From 2855ed3d70240856f5fa060f5551adde2ea65a93 Mon Sep 17 00:00:00 2001 From: brandon s allbery kf8nh Date: Sat, 16 Jan 2016 00:37:19 -0500 Subject: [PATCH 1/2] add X.U.Ungrab --- XMonad/Util/Ungrab.hs | 43 +++++++++++++++++++++++++++++++++++++++++++ xmonad-contrib.cabal | 1 + 2 files changed, 44 insertions(+) create mode 100644 XMonad/Util/Ungrab.hs diff --git a/XMonad/Util/Ungrab.hs b/XMonad/Util/Ungrab.hs new file mode 100644 index 00000000..5ad4db56 --- /dev/null +++ b/XMonad/Util/Ungrab.hs @@ -0,0 +1,43 @@ +----------------------------------------------------------------------------- +-- | +-- Module : XMonad.Util.Ungrab +-- Copyright : (c) 2016 Brandon S Allbery +-- License : BSD-style (see xmonad/LICENSE) +-- +-- Maintainer : allbery.b@gmail.com +-- Stability : unstable +-- Portability : unportable +-- +-- Allow releasing xmonad's keyboard grab +-- +----------------------------------------------------------------------------- + +module XMonad.Util.Ungrab + ( -- * Usage: + -- $usage + unGrab + ) where + +import Graphics.X11.Xlib.Extras (currentTime) +import Graphics.X11.Xlib.Misc (ungrabKeyboard, ungrabPointer) +import XMonad.Core + +-- $usage +-- 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 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. + +-- | Release xmonad's keyboard grab, so other grabbers can do their thing. +unGrab :: X () +unGrab = withDisplay $ \d -> io (ungrabKeyboard d currentTime >> ungrabPointer d currentTime) diff --git a/xmonad-contrib.cabal b/xmonad-contrib.cabal index e0b41338..12721cee 100644 --- a/xmonad-contrib.cabal +++ b/xmonad-contrib.cabal @@ -326,6 +326,7 @@ library XMonad.Util.Themes XMonad.Util.Timer XMonad.Util.Types + XMonad.Util.Ungrab XMonad.Util.WindowProperties XMonad.Util.WindowState XMonad.Util.WorkspaceCompare From 37965692684d54ccd424664e9c90760e0aaff770 Mon Sep 17 00:00:00 2001 From: brandon s allbery kf8nh Date: Sat, 13 Feb 2016 21:29:06 -0500 Subject: [PATCH 2/2] whoops, CHANGES.md --- CHANGES.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 2673f6eb..d8b5414e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,14 @@ * New constructor `CenteredAt Rational Rational` added for `XMonad.Prompt.XPPosition`. +### New Modules + + * `XMonad.Util.Ungrab` + + Release xmonad's keyboard and pointer grabs immediately, so + screen grabbers and lock utilities, etc. will work. Replaces + the short sleep hackaround. + ## 0.12 (December 14, 2015) ### Breaking Changes