From 9127725fd496be2db5ab1826d8585a8cf43f7d5a Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Fri, 8 Apr 2022 11:42:15 -0600 Subject: Add more bindings to the "g" command. --- src/Internal/Submap.hs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/Internal/Submap.hs') diff --git a/src/Internal/Submap.hs b/src/Internal/Submap.hs index 32dda2a..0e54c43 100644 --- a/src/Internal/Submap.hs +++ b/src/Internal/Submap.hs @@ -1,5 +1,6 @@ module Internal.Submap ( mapNextString, + mapNextStringWithKeysym, submapButtonsWithKey, nextButton, nextMotion, @@ -13,15 +14,20 @@ import Data.Map (Map) import XMonad.Actions.Submap as X -{- Like submap fram XMonad.Actions.Submap, but sends the string from - - XLookupString to the function rather than the KeySym. +{- + - Like submap fram XMonad.Actions.Submap, but sends the string from + - XLookupString to the function along side the keysym. + - + - This function allows mappings where the mapped string might be important, + - but also allows submappings for keys that may not have a character associated + - with them (for example, the function keys). -} -mapNextString :: (KeyMask -> String -> X a) -> X a -mapNextString fn = do +mapNextStringWithKeysym :: (KeyMask -> KeySym -> String -> X a) -> X a +mapNextStringWithKeysym fn = do XConf { theRoot = root, display = d } <- ask io $ grabKeyboard d root False grabModeAsync grabModeAsync currentTime - (m, str) <- io $ allocaXEvent $ \p -> fix $ \nextkey -> do + (m, str, keysym) <- io $ allocaXEvent $ \p -> fix $ \nextkey -> do maskEvent d keyPressMask p KeyEvent { ev_keycode = code, ev_state = m } <- getEvent p keysym <- keycodeToKeysym d code 0 @@ -29,12 +35,17 @@ mapNextString fn = do if isModifierKey keysym then nextkey - else return (m, str) + else return (m, str, keysym) io $ ungrabKeyboard d currentTime - fn m str + fn m keysym str +{- Like submap, but on the character typed rather than the kysym. -} +mapNextString :: (KeyMask -> String -> X a) -> X a +mapNextString fn = mapNextStringWithKeysym (\m _ s -> fn m s) + +{- Grabs the mouse and returns the next button press. -} nextButton :: X (ButtonMask, Button) nextButton = do XConf { theRoot = root, display = d } <- ask @@ -49,6 +60,7 @@ nextButton = do return ret +{- Grabs the mouse and reports the next mouse motion. -} nextMotion :: X (Int, Int) nextMotion = do XConf { theRoot = root, display = d } <- ask @@ -63,6 +75,7 @@ nextMotion = do return ret +{- Grabs the mouse and reports the next mouse motion or button press. -} nextMotionOrButton :: X (Either (Int, Int) (ButtonMask, Button)) nextMotionOrButton = do XConf { theRoot = root, display = d } <- ask -- cgit