Skip to content

Commit

Permalink
Merge pull request #479 from iogrt/ungrab
Browse files Browse the repository at this point in the history
Move `unGrab` to `XMonad.Operations`
  • Loading branch information
slotThe committed Dec 9, 2023
2 parents 706f548 + 0156e29 commit 855ff2f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 23 additions & 1 deletion src/XMonad/Operations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 855ff2f

Please sign in to comment.