summaryrefslogtreecommitdiffstats
path: root/tv/2configs/xserver/xmonad/Util/Submap.hs
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2015-10-27 18:12:29 +0100
committermakefu <github@syntax-fehler.de>2015-10-27 18:12:29 +0100
commita85114c59c5102b839584f72454bca2c8abbb887 (patch)
tree18fc24394171f4afae3dee0e68e3781df75723ea /tv/2configs/xserver/xmonad/Util/Submap.hs
parentfe4f5b98b91f6bacb036d57b5322fb4e09c22f14 (diff)
parent20ad77468131b7c69c5b3a26ea149ae7fdc0173b (diff)
Merge branch 'master' of pnp:stockholm
Diffstat (limited to 'tv/2configs/xserver/xmonad/Util/Submap.hs')
-rw-r--r--tv/2configs/xserver/xmonad/Util/Submap.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/tv/2configs/xserver/xmonad/Util/Submap.hs b/tv/2configs/xserver/xmonad/Util/Submap.hs
new file mode 100644
index 000000000..b09b97cc2
--- /dev/null
+++ b/tv/2configs/xserver/xmonad/Util/Submap.hs
@@ -0,0 +1,31 @@
+-- This module is based on Jason Creighton's XMonad.Actions.Submap
+
+module Util.Submap
+ ( submapString
+ ) where
+
+import Data.Bits
+import XMonad hiding (keys)
+import qualified Data.Map as M
+import Control.Monad.Fix (fix)
+
+
+-- | Like 'XMonad.Actions.Submap.submapDefault', but provides the looked up string to the default action.
+submapString :: (String -> X ()) -> M.Map (KeyMask, KeySym) (X ()) -> X ()
+submapString def keys = do
+ XConf { theRoot = root, display = d } <- ask
+
+ (m, s, 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
+ if isModifierKey keysym
+ then nextkey
+ else do
+ (mbKeysym, str) <- lookupString (asKeyEvent p)
+ return (m, keysym, str)
+
+ -- Remove num lock mask and Xkb group state bits
+ m' <- cleanMask $ m .&. ((1 `shiftL` 12) - 1)
+
+ maybe (def str) id (M.lookup (m', s) keys)