Skip to content

Instantly share code, notes, and snippets.

@LSLeary
Last active November 14, 2019 16:05
Show Gist options
  • Save LSLeary/36abffeb4150b6e9addc68af16a3d97e to your computer and use it in GitHub Desktop.
Save LSLeary/36abffeb4150b6e9addc68af16a3d97e to your computer and use it in GitHub Desktop.
import XMonad
import qualified XMonad.StackSet as W
import Graphics.X11.Xlib.Window (raiseWindow)
import XMonad.Hooks.EwmhDesktops (ewmh)
import Data.Monoid (All(..))
import qualified Data.Map.Strict as M
-- | Separate out propertyNotifyHook from the logHook.
propertyNotifyHook :: X () -> Event -> X All
propertyNotifyHook action event = case event of
PropertyEvent { ev_event_type = t, ev_atom = a }
| (t == propertyNotify) && (a == wM_NAME)
-> All False <$ (action >> broadcastMessage event)
_ -> return (All True)
-- | Raise the focus if it's floating.
raiseHook :: X ()
raiseHook = withFocused $ \win ->
whenX (isFloat win) . withDisplay $ \dpy ->
io (raiseWindow dpy win)
-- | Holds iff the window is a float.
isFloat :: Window -> X Bool
isFloat = \w -> gets (M.member w . W.floating . windowset)
-- Should be the /outermost/ config modifier.
relayoutOnlyHook a conf = conf
{ logHook = logHook conf <+> a
, handleEventHook = handleEventHook conf <+> propertyNotifyHook (logHook conf)
}
-- Example usage.
main :: IO ()
main = xmonad . relayoutOnlyHook raiseHook . ewmh . ... $ def
{ ... = ...
, ... = ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment