module XMonad.Actions.Submap (
submap,
submapDefault,
submapDefaultWithKey
) where
import Data.Bits
import XMonad.Prelude (fix, fromMaybe)
import XMonad hiding (keys)
import qualified Data.Map as M
submap :: M.Map (KeyMask, KeySym) (X ()) -> X ()
submap :: Map (KeyMask, KeySym) (X ()) -> X ()
submap = X () -> Map (KeyMask, KeySym) (X ()) -> X ()
submapDefault (() -> X ()
forall (m :: * -> *) a. Monad m => a -> m a
return ())
submapDefault :: X () -> M.Map (KeyMask, KeySym) (X ()) -> X ()
submapDefault :: X () -> Map (KeyMask, KeySym) (X ()) -> X ()
submapDefault = ((KeyMask, KeySym) -> X ()) -> Map (KeyMask, KeySym) (X ()) -> X ()
submapDefaultWithKey (((KeyMask, KeySym) -> X ())
-> Map (KeyMask, KeySym) (X ()) -> X ())
-> (X () -> (KeyMask, KeySym) -> X ())
-> X ()
-> Map (KeyMask, KeySym) (X ())
-> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. X () -> (KeyMask, KeySym) -> X ()
forall a b. a -> b -> a
const
submapDefaultWithKey :: ((KeyMask, KeySym) -> X ())
-> M.Map (KeyMask, KeySym) (X ())
-> X ()
submapDefaultWithKey :: ((KeyMask, KeySym) -> X ()) -> Map (KeyMask, KeySym) (X ()) -> X ()
submapDefaultWithKey (KeyMask, KeySym) -> X ()
defAction Map (KeyMask, KeySym) (X ())
keys = do
XConf { theRoot :: XConf -> KeySym
theRoot = KeySym
root, display :: XConf -> Display
display = Display
d } <- X XConf
forall r (m :: * -> *). MonadReader r m => m r
ask
IO GrabStatus -> X GrabStatus
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO GrabStatus -> X GrabStatus) -> IO GrabStatus -> X GrabStatus
forall a b. (a -> b) -> a -> b
$ Display
-> KeySym
-> Bool
-> GrabStatus
-> GrabStatus
-> KeySym
-> IO GrabStatus
grabKeyboard Display
d KeySym
root Bool
False GrabStatus
grabModeAsync GrabStatus
grabModeAsync KeySym
currentTime
IO GrabStatus -> X GrabStatus
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO GrabStatus -> X GrabStatus) -> IO GrabStatus -> X GrabStatus
forall a b. (a -> b) -> a -> b
$ Display
-> KeySym
-> Bool
-> KeySym
-> GrabStatus
-> GrabStatus
-> KeySym
-> KeySym
-> KeySym
-> IO GrabStatus
grabPointer Display
d KeySym
root Bool
False KeySym
buttonPressMask GrabStatus
grabModeAsync GrabStatus
grabModeAsync
KeySym
none KeySym
none KeySym
currentTime
(KeyMask
m, KeySym
s) <- IO (KeyMask, KeySym) -> X (KeyMask, KeySym)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO (KeyMask, KeySym) -> X (KeyMask, KeySym))
-> IO (KeyMask, KeySym) -> X (KeyMask, KeySym)
forall a b. (a -> b) -> a -> b
$ (XEventPtr -> IO (KeyMask, KeySym)) -> IO (KeyMask, KeySym)
forall a. (XEventPtr -> IO a) -> IO a
allocaXEvent ((XEventPtr -> IO (KeyMask, KeySym)) -> IO (KeyMask, KeySym))
-> (XEventPtr -> IO (KeyMask, KeySym)) -> IO (KeyMask, KeySym)
forall a b. (a -> b) -> a -> b
$ \XEventPtr
p -> (IO (KeyMask, KeySym) -> IO (KeyMask, KeySym))
-> IO (KeyMask, KeySym)
forall a. (a -> a) -> a
fix ((IO (KeyMask, KeySym) -> IO (KeyMask, KeySym))
-> IO (KeyMask, KeySym))
-> (IO (KeyMask, KeySym) -> IO (KeyMask, KeySym))
-> IO (KeyMask, KeySym)
forall a b. (a -> b) -> a -> b
$ \IO (KeyMask, KeySym)
nextkey -> do
Display -> KeySym -> XEventPtr -> IO ()
maskEvent Display
d (KeySym
keyPressMask KeySym -> KeySym -> KeySym
forall a. Bits a => a -> a -> a
.|. KeySym
buttonPressMask) XEventPtr
p
Event
ev <- XEventPtr -> IO Event
getEvent XEventPtr
p
case Event
ev of
KeyEvent { ev_keycode :: Event -> KeyCode
ev_keycode = KeyCode
code, ev_state :: Event -> KeyMask
ev_state = KeyMask
m } -> do
KeySym
keysym <- Display -> KeyCode -> GrabStatus -> IO KeySym
keycodeToKeysym Display
d KeyCode
code GrabStatus
0
if KeySym -> Bool
isModifierKey KeySym
keysym
then IO (KeyMask, KeySym)
nextkey
else (KeyMask, KeySym) -> IO (KeyMask, KeySym)
forall (m :: * -> *) a. Monad m => a -> m a
return (KeyMask
m, KeySym
keysym)
Event
_ -> (KeyMask, KeySym) -> IO (KeyMask, KeySym)
forall (m :: * -> *) a. Monad m => a -> m a
return (KeyMask
0, KeySym
0)
KeyMask
m' <- KeyMask -> X KeyMask
cleanMask (KeyMask -> X KeyMask) -> KeyMask -> X KeyMask
forall a b. (a -> b) -> a -> b
$ KeyMask
m KeyMask -> KeyMask -> KeyMask
forall a. Bits a => a -> a -> a
.&. ((KeyMask
1 KeyMask -> Int -> KeyMask
forall a. Bits a => a -> Int -> a
`shiftL` Int
12) KeyMask -> KeyMask -> KeyMask
forall a. Num a => a -> a -> a
- KeyMask
1)
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> KeySym -> IO ()
ungrabPointer Display
d KeySym
currentTime
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> KeySym -> IO ()
ungrabKeyboard Display
d KeySym
currentTime
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Bool -> IO ()
sync Display
d Bool
False
X () -> Maybe (X ()) -> X ()
forall a. a -> Maybe a -> a
fromMaybe ((KeyMask, KeySym) -> X ()
defAction (KeyMask
m', KeySym
s)) ((KeyMask, KeySym) -> Map (KeyMask, KeySym) (X ()) -> Maybe (X ())
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup (KeyMask
m', KeySym
s) Map (KeyMask, KeySym) (X ())
keys)