[xmonad] focus handling

Adam Vogt vogt.adam at gmail.com
Tue Feb 2 00:36:29 EST 2010


* On Monday, February 01 2010, Alessandro Massignan wrote:

>Hi all,
>
>i've a workspace for pidgin/skype and i wonder if their roster window should
>avoid focus switching (focusUp and focusDown) letting me to focus only the
>other windows (chats, options, ...).
>Is there a way to prevent a window being focused (eg. by classname, role,
>...)?
>
>thanks to all,
>ff0000

This can be accomplished with XMonad.Layout.BoringWindows [1]. While the
module doesn't export functionality to directly set target windows as
boring, you can work around that in your config with something like:

] import XMonad
] import qualified XMonad.StackSet as W
] import XMonad.Layout.BoringWindows
] 
] -- | Variant of 'markBoring', if 'XMonad.Layout.BoringWindows.IsBoring'
] --   was exported we could write much shorter:
] -- > markBoring' = sendMessage . IsBoring
] markBoring' :: Window -> X ()
] markBoring' w = do
]     st at XState { windowset = ws } <- get
]     env <- ask
]     (_,st') <- io $ runX env
]                          st{ windowset = W.insertUp w ws }
]                          markBoring
] 
]     -- this should encourage consideration of some alternative to the built-in
]     -- records: all this does is set the current layout in st to the one gotten
]     -- from st'
]     put $ st{ windowset =
]             ws{ W.current =
]               (W.current ws){ W.workspace =
]                (W.workspace $ W.current ws){ W.layout =
]                         W.layout $ W.workspace
]                         $ W.current $ windowset st'
]               }}}}
] 
] doBoring :: ManageHook
] doBoring = do
]     w <- ask
]     liftX $ markBoring' w
]     idHook

Then use doBoring as other ManageHooks. This also requires that you
modify your layout and add some keybindings as described in the
BoringWindows documentation.

However, if you reset your layout (mod-shift-space), then you would have
to run that manageHook over all the windows present in your workspace to
get your correct behavior back. Ex. you could use the following rerunMH
function to run a managehook (the one you defined using doBoring) on all
the windows in your current workspace:

] rerunMH :: ManageHook -> X ()
] rerunMH mhook = withWindowSet $ mapM_ (runQuery mhook) .  W.index

This might make sense to run after resetting layouts (mod-shift-space)
as this fragment that fits in some keybindings does (for a specific
managehook):

]   ,((modm .|. shiftMask,xK_space),
]           do { setLayout . Layout . layoutHook =<< ask
]              ; rerunMH (className =? "foo" --> doBoring)
]              }
]       )

Hope this helps,
--
Adam

[1] http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Layout-BoringWindows.html


More information about the xmonad mailing list