diff options
| author | tv <tv@krebsco.de> | 2015-10-29 01:49:27 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2015-10-29 01:49:27 +0100 |
| commit | 81329c86ac95ec5c151cbdac98144eb87a5c01d7 (patch) | |
| tree | 3ccb6edff8ad1fccf04e78285c9afb4232401265 /tv/5pkgs/xmonad-tv/Util/Submap.hs | |
| parent | 6db59aa0d6056fd2eb1c8fa6491b34b458a7d62a (diff) | |
tv: {2configs/xserver => 5pkgs}/xmonad-tv
Diffstat (limited to 'tv/5pkgs/xmonad-tv/Util/Submap.hs')
| -rw-r--r-- | tv/5pkgs/xmonad-tv/Util/Submap.hs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tv/5pkgs/xmonad-tv/Util/Submap.hs b/tv/5pkgs/xmonad-tv/Util/Submap.hs new file mode 100644 index 0000000..b09b97c --- /dev/null +++ b/tv/5pkgs/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) |
