[xmonad] Haskell question: avoiding code duplication

Peter Jones mlists at pmade.com
Wed Feb 6 17:37:34 CET 2013


adam vogt <vogt.adam at gmail.com> writes:
> Maybe you'll like this version below better. You can use mempty
> instead of 'return . mempty $ True'. The latter is a bit confusing
> since the True doesn't end up in value, since there's a "instance
> Monoid b => Monoid (a -> b)" whose mempty ignores the argument `a'.

Thanks Adam, after look at the Monoid instance for X I can see what
you're talking about.  Here is my final version if anyone cares:

-- | Enables 'focusFollowsMouse' for tiled windows only.  For this to
-- work you need to turn off 'focusFollowsMouse' in your configuration
-- and then add this function to your 'handleEventHook'.
focusFollowsTiledOnly :: Event -> X All
focusFollowsTiledOnly e@(CrossingEvent {ev_window = w, ev_event_type = t})
  | isNormalEnter = whenX bothTiled (focus w) >> mempty
  where isNormalEnter   = t == enterNotify && ev_mode e == notifyNormal
        bothTiled       = notFloating w <&&> currentIsTiled
        currentIsTiled  = currentWindow >>= maybe (return True) notFloating
        currentWindow   = gets $ W.peek . windowset
        notFloating w'  = gets $ not . M.member w' . W.floating . windowset
focusFollowsTiledOnly _ = mempty

-- 
Peter Jones --- Love to Develop
303-219-0226 http://devalot.com




More information about the xmonad mailing list