aboutsummaryrefslogtreecommitdiff
path: root/src/Internal/Submap.hs
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2021-11-23 12:32:00 -0700
committerJosh Rahm <rahm@google.com>2021-11-23 12:32:00 -0700
commite41358263a211bb651ebfdeedeef28c013494960 (patch)
treefa262f2344ef0567f4f9706dd20d006b336f2a12 /src/Internal/Submap.hs
parente1348d91338891be4dd3f7a8d335a5b0452db742 (diff)
downloadrde-e41358263a211bb651ebfdeedeef28c013494960.tar.gz
rde-e41358263a211bb651ebfdeedeef28c013494960.tar.bz2
rde-e41358263a211bb651ebfdeedeef28c013494960.zip
Added ability to submap based on the lookupString.
This changes how workspaces work. There are now as many workspaces as there are AlphaNumeric characters. I'm not really sure how I like it, but it's interesting. I'll keep it for a bit and see how I like it.
Diffstat (limited to 'src/Internal/Submap.hs')
-rw-r--r--src/Internal/Submap.hs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/Internal/Submap.hs b/src/Internal/Submap.hs
new file mode 100644
index 0000000..cdc2f95
--- /dev/null
+++ b/src/Internal/Submap.hs
@@ -0,0 +1,28 @@
+module Internal.Submap (mapNextString, module X) where
+
+import XMonad hiding (keys)
+import Control.Monad.Fix (fix)
+
+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.
+ -}
+mapNextString :: (KeyMask -> String -> X a) -> X a
+mapNextString fn = do
+ XConf { theRoot = root, display = d } <- ask
+ io $ grabKeyboard d root False grabModeAsync grabModeAsync currentTime
+
+ (m, str) <- io $ allocaXEvent $ \p -> fix $ \nextkey -> do
+ maskEvent d keyPressMask p
+ KeyEvent { ev_keycode = code, ev_state = m } <- getEvent p
+ keysym <- keycodeToKeysym d code 0
+ (_, str) <- lookupString (asKeyEvent p)
+
+ if isModifierKey keysym
+ then nextkey
+ else return $ (m, str)
+
+ io $ ungrabKeyboard d currentTime
+
+ fn m str