Skip to content

Commit

Permalink
X.U.Grab: Drop mkGrabs, setNumlockMask in favor of the new core exports
Browse files Browse the repository at this point in the history
Now that we require xmonad 0.18.0, we can do this.

Related: xmonad/xmonad#405
Related: 0934fe5 ("X.U.Grab: Hide mkGrabs from XMonad")
  • Loading branch information
liskin committed May 13, 2024
1 parent 02f124c commit 8e34c2f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 50 deletions.
52 changes: 4 additions & 48 deletions XMonad/Util/Grab.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@ module XMonad.Util.Grab
) where

-- core
import XMonad hiding (mkGrabs)
import XMonad

import Control.Monad ( when )
import Data.Bits ( setBit )
import Data.Foldable ( traverse_ )
-- base
import qualified Data.Map.Strict as M
import Data.Semigroup ( All(..) )
import Data.Traversable ( for )

-- }}}

Expand Down Expand Up @@ -70,9 +67,8 @@ grabUngrab
-> [(KeyMask, KeySym)] -- ^ Keys to ungrab
-> X ()
grabUngrab gr ugr = do
f <- mkGrabs
traverse_ (uncurry ungrabKP) (f ugr)
traverse_ (uncurry grabKP) (f gr)
traverse_ (uncurry ungrabKP) =<< mkGrabs ugr
traverse_ (uncurry grabKP) =<< mkGrabs gr

-- | A convenience function to grab keys. This also ungrabs all
-- previously grabbed keys.
Expand All @@ -88,49 +84,9 @@ customRegrabEvHook regr = \case
e@MappingNotifyEvent{} -> do
io (refreshKeyboardMapping e)
when (ev_request e `elem` [mappingKeyboard, mappingModifier])
$ setNumlockMask
$ cacheNumlockMask
>> regr
pure (All False)
_ -> pure (All True)

-- }}}

-- --< Private Utils >-- {{{

-- | Private action shamelessly copied and restyled from XMonad.Main source.
setNumlockMask :: X ()
setNumlockMask = withDisplay $ \dpy -> do
ms <- io (getModifierMapping dpy)
xs <- sequence
[ do
ks <- io (keycodeToKeysym dpy kc 0)
pure $ if ks == xK_Num_Lock
then setBit 0 (fromIntegral m)
else 0 :: KeyMask
| (m, kcs) <- ms
, kc <- kcs
, kc /= 0
]
modify $ \s -> s { numberlockMask = foldr (.|.) 0 xs }

-- | Private function shamelessly copied and refactored from XMonad.Main source.
mkGrabs :: X ([(KeyMask, KeySym)] -> [(KeyMask, KeyCode)])
mkGrabs = withDisplay $ \dpy -> do
let (minCode, maxCode) = displayKeycodes dpy
allCodes = [fromIntegral minCode .. fromIntegral maxCode]
syms <- io . for allCodes $ \code -> keycodeToKeysym dpy code 0
let keysymMap = M.fromListWith (++) (zip syms $ pure <$> allCodes)
keysymToKeycodes sym = M.findWithDefault [] sym keysymMap
extraMods <- extraModifiers
pure $ \ks -> do
(mask, sym) <- ks
keycode <- keysymToKeycodes sym
extraMod <- extraMods
pure (mask .|. extraMod, keycode)

-- }}}


-- NOTE: there is some duplication between this module and core. The
-- latter probably will never change, but this needs to be kept in sync
-- with any potential bugs that might arise.
4 changes: 2 additions & 2 deletions xmonad-contrib.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ library
ghc-options: -Wall -Wno-unused-do-bind

if flag(pedantic)
ghc-options: -Werror -Wwarn=deprecations -Wwarn=dodgy-imports
ghc-options: -Werror -Wwarn=deprecations

-- Keep this in sync with the oldest version in 'tested-with'
if impl(ghc > 8.6.5)
Expand Down Expand Up @@ -496,7 +496,7 @@ test-suite tests
default-language: Haskell2010

if flag(pedantic)
ghc-options: -Werror -Wwarn=deprecations -Wwarn=dodgy-imports
ghc-options: -Werror -Wwarn=deprecations

-- Keep this in sync with the oldest version in 'tested-with'
if impl(ghc > 8.6.5)
Expand Down

0 comments on commit 8e34c2f

Please sign in to comment.