Skip to content

Commit 8df5bd9

Browse files
committed
X.H.UrgencyHook: Add askUrgent and doAskUrgent
These are useful when one blocks some _NET_ACTIVE_WINDOW requests but still wants to somehow show that a window requested focus. Related: xmonad#110 Related: xmonad#128 Related: xmonad#192
1 parent e72e663 commit 8df5bd9

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,10 @@
634634
- Added a variant of `filterUrgencyHook` that takes a generic `Query Bool`
635635
to select which windows should never be marked urgent.
636636

637+
- Added `askUrgent` and a `doAskUrgent` manage hook helper for marking
638+
windows as urgent from inside of xmonad. This can be used as a less
639+
intrusive action for windows requesting focus.
640+
637641
* `XMonad.Hooks.ServerMode`
638642

639643
- To make it easier to use, the `xmonadctl` client is now included in

XMonad/Hooks/UrgencyHook.hs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ module XMonad.Hooks.UrgencyHook (
6060
FocusHook(..),
6161
filterUrgencyHook, filterUrgencyHook',
6262
minutes, seconds,
63+
askUrgent, doAskUrgent,
6364
-- * Stuff for developers:
6465
readUrgents, withUrgents, clearUrgents',
6566
StdoutUrgencyHook(..),
@@ -70,7 +71,7 @@ module XMonad.Hooks.UrgencyHook (
7071
) where
7172

7273
import XMonad
73-
import XMonad.Prelude (delete, fromMaybe, listToMaybe, maybeToList, when, (\\))
74+
import XMonad.Prelude (fi, delete, fromMaybe, listToMaybe, maybeToList, when, (\\))
7475
import qualified XMonad.StackSet as W
7576

7677
import XMonad.Hooks.ManageHelpers (windowTag)
@@ -542,3 +543,28 @@ filterUrgencyHook skips = filterUrgencyHook' $ maybe False (`elem` skips) <$> wi
542543
-- should never be marked urgent.
543544
filterUrgencyHook' :: Query Bool -> Window -> X ()
544545
filterUrgencyHook' q w = whenX (runQuery q w) (clearUrgents' [w])
546+
547+
-- | Mark the given window urgent.
548+
--
549+
-- (The implementation is a bit hacky: send a _NET_WM_STATE ClientMessage to
550+
-- ourselves. This is so that we respect the 'SuppressWhen' of the configured
551+
-- urgency hooks. If this module if ever migrated to the ExtensibleConf
552+
-- infrastrcture, we'll then invoke markUrgent directly.)
553+
askUrgent :: Window -> X ()
554+
askUrgent w = withDisplay $ \dpy -> do
555+
rw <- asks theRoot
556+
a_wmstate <- getAtom "_NET_WM_STATE"
557+
a_da <- getAtom "_NET_WM_STATE_DEMANDS_ATTENTION"
558+
let state_add = 1
559+
let source_pager = 2
560+
io $ allocaXEvent $ \e -> do
561+
setEventType e clientMessage
562+
setClientMessageEvent' e w a_wmstate 32 [state_add, fi a_da, 0, source_pager]
563+
sendEvent dpy rw False (substructureRedirectMask .|. substructureNotifyMask) e
564+
565+
-- | Helper for 'ManageHook' that marks the window as urgent (unless
566+
-- suppressed, see 'SuppressWhen'). Useful in
567+
-- 'XMonad.Hooks.EwmhDesktops.activateLogHook' and also in combination with
568+
-- "XMonad.Hooks.InsertPosition", "XMonad.Hooks.Focus".
569+
doAskUrgent :: ManageHook
570+
doAskUrgent = ask >>= \w -> liftX (askUrgent w) >> return mempty

0 commit comments

Comments
 (0)