aboutsummaryrefslogtreecommitdiffstats
path: root/Submap.hs
diff options
context:
space:
mode:
authorJason Creighton <jcreigh@gmail.com>2007-06-06 08:19:41 +0200
committerJason Creighton <jcreigh@gmail.com>2007-06-06 08:19:41 +0200
commitc136d4baf7f2f417efc6316db9967257807cbc5b (patch)
treee6bd9f246bd5e3fee7d78b67276cec9c9cb6388b /Submap.hs
parent8758a33a16e5cf6887d27636cb8222a7b24eb235 (diff)
downloadXMonadContrib-c136d4baf7f2f417efc6316db9967257807cbc5b.tar.gz
XMonadContrib-c136d4baf7f2f417efc6316db9967257807cbc5b.tar.xz
XMonadContrib-c136d4baf7f2f417efc6316db9967257807cbc5b.zip
Submap: For creating keyboard submappings
darcs-hash:20070606061941-b9aa7-dd1476862b4d6755e2d4971c4e475604fdc248fc.gz
Diffstat (limited to 'Submap.hs')
-rw-r--r--Submap.hs44
1 files changed, 44 insertions, 0 deletions
diff --git a/Submap.hs b/Submap.hs
new file mode 100644
index 0000000..987ff46
--- /dev/null
+++ b/Submap.hs
@@ -0,0 +1,44 @@
+{-
+Allows you to create a sub-mapping of keys. Example:
+
+ , ((modMask, xK_a), submap . M.fromList $
+ [ ((0, xK_n), spawn "mpc next")
+ , ((0, xK_p), spawn "mpc prev")
+ , ((0, xK_z), spawn "mpc random")
+ , ((0, xK_space), spawn "mpc toggle")
+ ])
+
+So, for example, to run 'spawn "mpc next"', you would hit mod-a (to trigger the
+submapping) and then 'n' to run that action. (0 means "no modifier"). You are,
+of course, free to use any combination of modifiers in the submapping. However,
+anyModifier will not work, because that is a special value passed to XGrabKey()
+and not an actual modifier.
+-}
+
+module XMonadContrib.Submap where
+
+import Control.Monad.Reader
+
+import XMonad
+import Operations (cleanMask)
+import Graphics.X11.Xlib
+import Graphics.X11.Xlib.Extras
+import qualified Data.Map as M
+
+submap :: M.Map (KeyMask, KeySym) (X ()) -> X ()
+submap keys = do
+ XConf { theRoot = root, display = d } <- ask
+
+ io $ grabKeyboard d root False grabModeAsync grabModeAsync currentTime
+
+ keyspec <- 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 return (cleanMask m, keysym)
+
+ io $ ungrabKeyboard d currentTime
+
+ whenJust (M.lookup keyspec keys) id