Skip to content

Commit

Permalink
X.H.UrgencyHook: Add askUrgent and doAskUrgent
Browse files Browse the repository at this point in the history
These are useful when one blocks some _NET_ACTIVE_WINDOW requests but
still wants to somehow show that a window requested focus.

TODO: changelog
TODO: xmonad/X11#71
TODO: maybe bump X11 dependency instead?
  • Loading branch information
liskin committed Jan 30, 2021
1 parent 8f5b332 commit 04bc42c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
additional combinators.

TODO: refactor and update and make it not a breaking change
TODO: mention doAskUrgent

* `XMonad.Prompt.Directory`

Expand Down
37 changes: 37 additions & 0 deletions XMonad/Hooks/UrgencyHook.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{-# LANGUAGE FlexibleContexts, MultiParamTypeClasses, TypeSynonymInstances, PatternGuards, DeriveDataTypeable,
FlexibleInstances #-}
{-# LANGUAGE CPP #-}

#define X11_has_setClientMessageEvent MIN_VERSION_X11(1, 10, 0)

-----------------------------------------------------------------------------
-- |
Expand Down Expand Up @@ -63,6 +66,9 @@ module XMonad.Hooks.UrgencyHook (
FocusHook(..),
filterUrgencyHook,
minutes, seconds,
#if X11_has_setClientMessageEvent
askUrgent, doAskUrgent,
#endif
-- * Stuff for developers:
readUrgents, withUrgents,
StdoutUrgencyHook(..),
Expand All @@ -80,6 +86,7 @@ import qualified XMonad.Util.ExtensibleState as XS
import XMonad.Util.NamedWindows (getName)
import XMonad.Util.Timer (TimerId, startTimer, handleTimer)
import XMonad.Util.WindowProperties (getProp32)
import XMonad.Util.XUtils (fi)

import Control.Monad (when)
import Data.Bits (testBit)
Expand Down Expand Up @@ -541,3 +548,33 @@ filterUrgencyHook skips w = do
Just tag -> when (tag `elem` skips)
$ adjustUrgents (delete w)
_ -> return ()

#if X11_has_setClientMessageEvent

-- | Mark the given window urgent.
--
-- (The implementation is a bit hacky: send a _NET_WM_STATE ClientMessage to
-- ourselves. This is so that we respect the 'SuppressWhen' of the configured
-- urgency hooks.)
--
-- TODO: https://github.com/quchen/articles/blob/master/haskell-cpp-compatibility.md
askUrgent :: Window -> X ()
askUrgent w = withDisplay $ \dpy -> do
rw <- asks theRoot
a_wmstate <- getAtom "_NET_WM_STATE"
a_da <- getAtom "_NET_WM_STATE_DEMANDS_ATTENTION"
let state_add = 1
let source_pager = 2
io $ allocaXEvent $ \e -> do
setEventType e clientMessage
setClientMessageEvent' e w a_wmstate 32 [state_add, fi a_da, 0, source_pager]
sendEvent dpy rw False (substructureRedirectMask .|. substructureNotifyMask) e

-- | Helper for 'ManageHook' that marks the window as urgent (unless
-- suppressed, see 'SuppressWhen'). Useful in
-- 'XMonad.Hooks.EwmhDesktops.activateHook' and also in combination with
-- "XMonad.Hooks.InsertPosition", "XMonad.Hooks.Focus".
doAskUrgent :: ManageHook
doAskUrgent = ask >>= \w -> liftX (askUrgent w) >> return mempty

#endif
4 changes: 2 additions & 2 deletions xmonad-contrib.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ library
random,
mtl >= 1 && < 3,
unix,
X11>=1.6.1 && < 1.10,
X11>=1.6.1 && < 1.11,
xmonad >= 0.15 && < 0.16,
utf8-string

Expand Down Expand Up @@ -399,7 +399,7 @@ test-suite tests
hs-source-dirs: tests, .
build-depends: base
, QuickCheck >= 2
, X11>=1.6.1 && < 1.10
, X11>=1.6.1 && < 1.11
, containers
, directory
, hspec >= 2.4.0 && < 3
Expand Down

0 comments on commit 04bc42c

Please sign in to comment.