{-# 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 } <- X XConf
forall r (m :: * -> *). MonadReader r m => m r
ask
IO () -> X ()
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 } <- X XConf
forall r (m :: * -> *). MonadReader r m => m r
ask
IO () -> X ()
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
((KeyMask, KeyCode) -> X ()) -> [(KeyMask, KeyCode)] -> X ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ ((KeyMask -> KeyCode -> X ()) -> (KeyMask, KeyCode) -> X ()
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry KeyMask -> KeyCode -> X ()
ungrabKP) ([(KeyMask, KeyCode)] -> X ()) -> X [(KeyMask, KeyCode)] -> X ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< [(KeyMask, Window)] -> X [(KeyMask, KeyCode)]
mkGrabs [(KeyMask, Window)]
ugr
((KeyMask, KeyCode) -> X ()) -> [(KeyMask, KeyCode)] -> X ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ ((KeyMask -> KeyCode -> X ()) -> (KeyMask, KeyCode) -> X ()
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry KeyMask -> KeyCode -> X ()
grabKP) ([(KeyMask, KeyCode)] -> X ()) -> X [(KeyMask, KeyCode)] -> X ()
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 } <- X XConf
forall r (m :: * -> *). MonadReader r m => m r
ask
IO () -> X ()
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
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (Event -> IO ()
refreshKeyboardMapping Event
e)
Bool -> X () -> X ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Event -> MappingRequest
ev_request Event
e MappingRequest -> [MappingRequest] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [MappingRequest
mappingKeyboard, MappingRequest
mappingModifier])
(X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ X ()
cacheNumlockMask
X () -> X () -> X ()
forall a b. X a -> X b -> X b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> X ()
regr
All -> X All
forall a. a -> X a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> All
All Bool
False)
Event
_ -> All -> X All
forall a. a -> X a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> All
All Bool
True)