diff options
author | lassulus <lass@aidsballs.de> | 2015-10-25 21:27:14 +0100 |
---|---|---|
committer | lassulus <lass@aidsballs.de> | 2015-10-25 21:27:14 +0100 |
commit | cc5220a4477e290f1833e609fed1e0f9f56e4a41 (patch) | |
tree | f7032b6126c6daac3e2d2e5ad9c5d628a7a3e34a /tv/2configs/xserver/xmonad/Util/Submap.hs | |
parent | ace11d79badafce313b17c968701739513e95982 (diff) | |
parent | cca25c7b66c44e0ec826d466bd48f2463df03fe9 (diff) |
Merge remote-tracking branch 'pnp/master'
Diffstat (limited to 'tv/2configs/xserver/xmonad/Util/Submap.hs')
-rw-r--r-- | tv/2configs/xserver/xmonad/Util/Submap.hs | 31 |
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) |