mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-18 19:10:21 -07:00
X.U.Grab: Drop mkGrabs, setNumlockMask in favor of the new core exports
Now that we require xmonad 0.18.0, we can do this. Related: https://github.com/xmonad/xmonad/pull/405 Related: 0934fe5cd758 ("X.U.Grab: Hide mkGrabs from XMonad")
This commit is contained in:
parent
02f124cf4b
commit
8e34c2f745
@ -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 )
|
||||
|
||||
-- }}}
|
||||
|
||||
@ -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.
|
||||
@ -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.
|
||||
|
@ -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)
|
||||
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user