Skip to content

Commit 837804c

Browse files
committed
X.H.EwmhDesktops: add a way to selectively ignore _NET_ACTIVE_WINDOW
1 parent 52f8c82 commit 837804c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

XMonad/Hooks/EwmhDesktops.hs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ module XMonad.Hooks.EwmhDesktops (
2121
ewmhDesktopsLogHookCustom,
2222
ewmhDesktopsEventHook,
2323
ewmhDesktopsEventHookCustom,
24+
ignoreNetActiveWindow,
25+
ignoreNetActiveWindowEventHook,
2426
ewmhFullscreen,
2527
fullscreenEventHook,
2628
fullscreenStartup
@@ -216,6 +218,31 @@ handle f (ClientMessageEvent {
216218
return ()
217219
handle _ _ = return ()
218220

221+
-- | Ignore window activation requests from some windows, e.g. a browser
222+
-- stealing focus whenever a link is opened from another app.
223+
--
224+
-- Usage:
225+
--
226+
-- > main = xmonad $ ignoreNetActiveWindow q $ ewmh def
227+
-- > where
228+
-- > q = className =? "google-chrome"
229+
ignoreNetActiveWindow :: Query Bool -> XConfig a -> XConfig a
230+
ignoreNetActiveWindow q c =
231+
c { handleEventHook = ignoreNetActiveWindowEventHook q (handleEventHook c) }
232+
233+
ignoreNetActiveWindowEventHook :: Query Bool -> (Event -> X All) -> Event -> X All
234+
ignoreNetActiveWindowEventHook q hook
235+
e@ClientMessageEvent{ ev_window = w, ev_message_type = mt } = do
236+
a_aw <- getAtom "_NET_ACTIVE_WINDOW"
237+
if mt == a_aw
238+
then do
239+
ignore <- runQuery q w
240+
if ignore
241+
then return (All True)
242+
else hook e
243+
else hook e
244+
ignoreNetActiveWindowEventHook _ hook e = hook e
245+
219246
-- | Add EWMH fullscreen functionality to the given config.
220247
--
221248
-- This must be applied after 'ewmh', like so:

0 commit comments

Comments
 (0)