diff --git a/CHANGES.md b/CHANGES.md index 00114c4..54f4980 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,10 @@ * Recompilation now detects `flake.nix` and `default.nix` (can be a symlink) and switches to using `nix build` as appropriate. +* Added `unGrab` to `XMonad.Operations`; this releases XMonad's passive + keyboard grab, so other applications (like `scrot`) can do their + thing. + ### Bug Fixes * Duplicated floats (e.g. from X.A.CopyToAll) no longer escape to inactive diff --git a/src/XMonad/Operations.hs b/src/XMonad/Operations.hs index 9101cc0..3cdf258 100644 --- a/src/XMonad/Operations.hs +++ b/src/XMonad/Operations.hs @@ -33,7 +33,7 @@ module XMonad.Operations ( -- * Keyboard and Mouse cleanMask, extraModifiers, mouseDrag, mouseMoveWindow, mouseResizeWindow, - setButtonGrab, setFocusX, cacheNumlockMask, mkGrabs, + setButtonGrab, setFocusX, cacheNumlockMask, mkGrabs, unGrab, -- * Messages sendMessage, broadcastMessage, sendMessageWithNoRefresh, @@ -475,6 +475,28 @@ mkGrabs ks = withDisplay $ \dpy -> do , extraMod <- extraMods ] +-- | Release XMonad's keyboard grab, so other grabbers can do their thing. +-- +-- Start a keyboard action with this if it is going to run something +-- that needs to do a keyboard, pointer, or server grab. For example, +-- +-- > , ((modm .|. controlMask, xK_p), unGrab >> spawn "scrot") +-- +-- (Other examples are certain screen lockers and "gksu".) +-- This avoids needing to insert a pause/sleep before running the +-- command. +-- +-- XMonad retains the keyboard grab during key actions because if they +-- use a submap, they need the keyboard to be grabbed, and if they had +-- to assert their own grab then the asynchronous nature of X11 allows +-- race conditions between XMonad, other clients, and the X server that +-- would cause keys to sometimes be "leaked" to the focused window. +unGrab :: X () +unGrab = withDisplay $ \d -> io $ do + ungrabKeyboard d currentTime + ungrabPointer d currentTime + sync d False + ------------------------------------------------------------------------ -- Message handling