{-# LANGUAGE LambdaCase #-}
module XMonad.Util.Grab
(
grabKP
, ungrabKP
, grabUngrab
, grab
, customRegrabEvHook
) where
import XMonad
import Control.Monad ( when )
import Data.Foldable ( traverse_ )
import Data.Semigroup ( All(..) )
grabKP :: KeyMask -> KeyCode -> X ()
grabKP :: KeyMask -> KeyCode -> X ()
grabKP KeyMask
mdfr KeyCode
kc = do
XConf { display :: XConf -> Display
display = Display
dpy, theRoot :: XConf -> Window
theRoot = Window
rootw } <- forall r (m :: * -> *). MonadReader r m => m r
ask
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (Display
-> KeyCode
-> KeyMask
-> Window
-> Bool
-> MappingRequest
-> MappingRequest
-> IO ()
grabKey Display
dpy KeyCode
kc KeyMask
mdfr Window
rootw Bool
True MappingRequest
grabModeAsync MappingRequest
grabModeAsync)
ungrabKP :: KeyMask -> KeyCode -> X ()
ungrabKP :: KeyMask -> KeyCode -> X ()
ungrabKP KeyMask
mdfr KeyCode
kc = do
XConf { display :: XConf -> Display
display = Display
dpy, theRoot :: XConf -> Window
theRoot = Window
rootw } <- forall r (m :: * -> *). MonadReader r m => m r
ask
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (Display -> KeyCode -> KeyMask -> Window -> IO ()
ungrabKey Display
dpy KeyCode
kc KeyMask
mdfr Window
rootw)
grabUngrab
:: [(KeyMask, KeySym)]
-> [(KeyMask, KeySym)]
-> X ()
grabUngrab :: [(KeyMask, Window)] -> [(KeyMask, Window)] -> X ()
grabUngrab [(KeyMask, Window)]
gr [(KeyMask, Window)]
ugr = do
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry KeyMask -> KeyCode -> X ()
ungrabKP) forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< [(KeyMask, Window)] -> X [(KeyMask, KeyCode)]
mkGrabs [(KeyMask, Window)]
ugr
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry KeyMask -> KeyCode -> X ()
grabKP) forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< [(KeyMask, Window)] -> X [(KeyMask, KeyCode)]
mkGrabs [(KeyMask, Window)]
gr
grab :: [(KeyMask, KeySym)] -> X ()
grab :: [(KeyMask, Window)] -> X ()
grab [(KeyMask, Window)]
ks = do
XConf { display :: XConf -> Display
display = Display
dpy, theRoot :: XConf -> Window
theRoot = Window
rootw } <- forall r (m :: * -> *). MonadReader r m => m r
ask
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (Display -> KeyCode -> KeyMask -> Window -> IO ()
ungrabKey Display
dpy KeyCode
anyKey KeyMask
anyModifier Window
rootw)
[(KeyMask, Window)] -> [(KeyMask, Window)] -> X ()
grabUngrab [(KeyMask, Window)]
ks []
customRegrabEvHook :: X () -> Event -> X All
customRegrabEvHook :: X () -> Event -> X All
customRegrabEvHook X ()
regr = \case
e :: Event
e@MappingNotifyEvent{} -> do
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (Event -> IO ()
refreshKeyboardMapping Event
e)
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Event -> MappingRequest
ev_request Event
e forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [MappingRequest
mappingKeyboard, MappingRequest
mappingModifier])
forall a b. (a -> b) -> a -> b
$ X ()
cacheNumlockMask
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> X ()
regr
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> All
All Bool
False)
Event
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> All
All Bool
True)