submapDefault

Add support for a default action to take when the entered key does not match any entry.
This commit is contained in:
Anders Engstrom 2009-01-18 15:29:33 +00:00
parent b3822c6faa
commit b39dfa1917

View File

@ -15,7 +15,8 @@
module XMonad.Actions.Submap ( module XMonad.Actions.Submap (
-- * Usage -- * Usage
-- $usage -- $usage
submap submap,
submapDefault
) where ) where
import XMonad hiding (keys) import XMonad hiding (keys)
@ -57,7 +58,11 @@ For detailed instructions on editing your key bindings, see
-- corresponding action, or does nothing if the key is not found in -- corresponding action, or does nothing if the key is not found in
-- the map. -- the map.
submap :: M.Map (KeyMask, KeySym) (X ()) -> X () submap :: M.Map (KeyMask, KeySym) (X ()) -> X ()
submap keys = do submap keys = submapDefault (return ()) keys
-- | Like 'submap', but executes a default action if the key did not match.
submapDefault :: X () -> M.Map (KeyMask, KeySym) (X ()) -> X ()
submapDefault def keys = do
XConf { theRoot = root, display = d } <- ask XConf { theRoot = root, display = d } <- ask
io $ grabKeyboard d root False grabModeAsync grabModeAsync currentTime io $ grabKeyboard d root False grabModeAsync grabModeAsync currentTime
@ -73,4 +78,4 @@ submap keys = do
io $ ungrabKeyboard d currentTime io $ ungrabKeyboard d currentTime
m' <- cleanMask m m' <- cleanMask m
whenJust (M.lookup (m', s) keys) id maybe def id (M.lookup (m', s) keys)