From 91995df5592f0d718f53d59f8ef2cc111dd7485b Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Sun, 8 Aug 2021 15:46:09 +0100 Subject: [PATCH] X.A.Submap, X.U.Ungrab: Sync after ungrab (fixes issues with runProcessWithInput) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When `runProcessWithInput` is invoked immediately after `ungrabPointer`/`ungrabKeyboard`, we don't actually ungrab at all because `runProcessWithInput` blocks and the ungrab requests wait in Xlib's queue for a requests that needs a queue flush. Common uses of `unGrab` (before `spawn`) aren't followed by a blocking action, so the ungrab requests are flushed by xmonad's main loop, and this is merely a timing issue—fork/exec takes a while and xmonad probably manages to get back to its main loop in time. Uses of `runProcessWithInput` in ordinary non-submap key bindings happen to work because key bindings are passive grabs—the grab is released by the user's fingers releasing the key itself, even if xmonad's ungrab requests are stuck in a blocked queue. Submap key bindings, however, take an active grab and therefore need to ungrab explicitly. Easy fix—explicit `sync`. Fixes: https://github.com/xmonad/xmonad/issues/313 --- CHANGES.md | 5 +++++ XMonad/Actions/Submap.hs | 1 + XMonad/Util/Ungrab.hs | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index c5e2e4a5..87cbf400 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -681,6 +681,11 @@ - Added `swapWithCurrent` and `swapOrder` to the list of exported names. + - `XMonad.Actions.Submap`, `XMonad.Util.Ungrab`: + + - Fixed issue with keyboard/pointer staying grabbed when a blocking action + like `runProcessWithInput` was invoked. + ## 0.16 ### Breaking Changes diff --git a/XMonad/Actions/Submap.hs b/XMonad/Actions/Submap.hs index e360b0ff..52372cd2 100644 --- a/XMonad/Actions/Submap.hs +++ b/XMonad/Actions/Submap.hs @@ -92,5 +92,6 @@ submapDefaultWithKey defAction keys = do io $ ungrabPointer d currentTime io $ ungrabKeyboard d currentTime + io $ sync d False fromMaybe (defAction (m', s)) (M.lookup (m', s) keys) diff --git a/XMonad/Util/Ungrab.hs b/XMonad/Util/Ungrab.hs index 5ad4db56..e11f6630 100644 --- a/XMonad/Util/Ungrab.hs +++ b/XMonad/Util/Ungrab.hs @@ -18,6 +18,7 @@ module XMonad.Util.Ungrab unGrab ) where +import Graphics.X11.Xlib (sync) import Graphics.X11.Xlib.Extras (currentTime) import Graphics.X11.Xlib.Misc (ungrabKeyboard, ungrabPointer) import XMonad.Core @@ -40,4 +41,4 @@ import XMonad.Core -- | Release xmonad's keyboard grab, so other grabbers can do their thing. unGrab :: X () -unGrab = withDisplay $ \d -> io (ungrabKeyboard d currentTime >> ungrabPointer d currentTime) +unGrab = withDisplay $ \d -> io (ungrabKeyboard d currentTime >> ungrabPointer d currentTime >> sync d False)