Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X.H.EwmhDesktops: add a way to selectively ignore _NET_ACTIVE_WINDOW #110

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@
* `XMonad.Util.EZConfig`
- Added support for XF86Bluetooth.

* `XMonad.Hooks.EwmhDesktops`

Added `ignoreNetActiveWindow`, to selectively ignore window activation
requests from focus-stealing apps.

## 0.16

Expand Down
31 changes: 29 additions & 2 deletions XMonad/Hooks/EwmhDesktops.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module XMonad.Hooks.EwmhDesktops (
ewmhDesktopsLogHookCustom,
ewmhDesktopsEventHook,
ewmhDesktopsEventHookCustom,
ignoreNetActiveWindow,
ignoreNetActiveWindowEventHook,
ewmhFullscreen,
fullscreenEventHook,
fullscreenStartup
Expand All @@ -31,7 +33,6 @@ import Data.List
import Data.Maybe
import Data.Monoid
import qualified Data.Map.Strict as M
import System.IO.Unsafe

import XMonad
import Control.Monad
Expand Down Expand Up @@ -216,6 +217,33 @@ handle f (ClientMessageEvent {
return ()
handle _ _ = return ()

-- | Ignore window activation requests from some windows, e.g. a browser
-- stealing focus whenever a link is opened from another app.
--
-- Usage:
--
-- > main = xmonad $ ignoreNetActiveWindow q $ ewmh def
-- > where
-- > q = className =? "google-chrome"
ignoreNetActiveWindow :: Query Bool -> XConfig a -> XConfig a
ignoreNetActiveWindow q c =
c { handleEventHook = ignoreNetActiveWindowEventHook q (handleEventHook c) }

ignoreNetActiveWindowEventHook :: Query Bool -> (Event -> X All) -> Event -> X All
ignoreNetActiveWindowEventHook q hook
e@ClientMessageEvent{ ev_window = w, ev_message_type = mt, ev_data = d } = do
a_aw <- getAtom "_NET_ACTIVE_WINDOW"
-- https://specifications.freedesktop.org/wm-spec/wm-spec-1.3.html#sourceindication
let fromPager = [2] `isPrefixOf` d
if mt == a_aw && not fromPager
then do
ignore <- runQuery q w
if ignore
then return (All True)
else hook e
else hook e
ignoreNetActiveWindowEventHook _ hook e = hook e

-- | Add EWMH fullscreen functionality to the given config.
--
-- This must be applied after 'ewmh', like so:
Expand Down Expand Up @@ -323,7 +351,6 @@ addSupported :: [String] -> X ()
addSupported props = withDisplay $ \dpy -> do
r <- asks theRoot
a <- getAtom "_NET_SUPPORTED"
fs <- getAtom "_NET_WM_STATE_FULLSCREEN"
newSupportedList <- mapM (fmap fromIntegral . getAtom) props
io $ do
supportedList <- fmap (join . maybeToList) $ getWindowProperty32 dpy a r
Expand Down