Wednesday, November 11, 2009

Dialog Windows in XMonad

The current implementation for dialog detection only treats transient windows of the parent window as dialogs, and ignores EWMH compliant applications that set the window type to _NET_WM_WINDOW_TYPE_DIALOG

The following code detects EMWH dialog windows:
import XMonad
import Graphics.X11.Xlib.Extras

-- | Float all dialog windows
manageDialogs :: ManageHook
manageDialogs = checkDialog --> doFloat

-- | Check if window is DIALOG window
checkDialog :: Query Bool
checkDialog = ask >>= \w -> liftX $ do
                a <- getAtom "_NET_WM_WINDOW_TYPE"
                dialog <- getAtom "_NET_WM_WINDOW_TYPE_DIALOG"
                mbr <- getProp a w
                case mbr of
                  Just [r] -> return $ elem (fromIntegral r) [dialog]
                  _ -> return False

-- | Helper to read a property
getProp :: Atom -> Window -> X (Maybe [CLong])
getProp a w = withDisplay $ \dpy -> io $ getWindowProperty32 dpy a w
It's then just a matter of adding the manageDialogs hook to your manageHooks, here is my manageHooks:
myManageHook :: ManageHook
myManageHook = composeAll
               [ manageDocks
               , manageDialogs
               , manageHook defaultConfig
               ]