summaryrefslogtreecommitdiffstats
path: root/tv/2configs/xserver/xmonad-tv/Util/Submap.hs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2015-10-24 22:09:55 +0200
committertv <tv@krebsco.de>2015-10-24 22:09:55 +0200
commitb1f7c03ecdde2593045ab80a2b94de1ff4d32178 (patch)
tree5aa489151a72fd7174da2eafa85c068be5e2ff6e /tv/2configs/xserver/xmonad-tv/Util/Submap.hs
parenta920d7e85a513d4aa56fc883d82cd8d26dc58f5b (diff)
tv: nano really is just vim
This is required or else we have to modify glorious packages like cvs.
Diffstat (limited to 'tv/2configs/xserver/xmonad-tv/Util/Submap.hs')
-rw-r--r--tv/2configs/xserver/xmonad-tv/Util/Submap.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/tv/2configs/xserver/xmonad-tv/Util/Submap.hs b/tv/2configs/xserver/xmonad-tv/Util/Submap.hs
new file mode 100644
index 0000000..b09b97c
--- /dev/null
+++ b/tv/2configs/xserver/xmonad-tv/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)