Add submapDefaultWithKey.

This is useful for when we want to decide what to do in the default
action based on the key that failed to match in the submap.
This commit is contained in:
Matus Goljer 2016-10-16 16:40:13 +02:00
parent 444986d993
commit e5ca066057

View File

@ -16,7 +16,8 @@ module XMonad.Actions.Submap (
-- * Usage -- * Usage
-- $usage -- $usage
submap, submap,
submapDefault submapDefault,
submapDefaultWithKey
) where ) where
import Data.Bits import Data.Bits
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
@ -63,7 +64,14 @@ submap = submapDefault (return ())
-- | Like 'submap', but executes a default action if the key did not match. -- | Like 'submap', but executes a default action if the key did not match.
submapDefault :: X () -> M.Map (KeyMask, KeySym) (X ()) -> X () submapDefault :: X () -> M.Map (KeyMask, KeySym) (X ()) -> X ()
submapDefault defAction keys = do submapDefault = submapDefaultWithKey . const
-- | Like 'submapDefault', but sends the unmatched key to the default
-- action as argument.
submapDefaultWithKey :: ((KeyMask, KeySym) -> X ())
-> M.Map (KeyMask, KeySym) (X ())
-> X ()
submapDefaultWithKey defAction 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
@ -80,4 +88,4 @@ submapDefault defAction keys = do
io $ ungrabKeyboard d currentTime io $ ungrabKeyboard d currentTime
fromMaybe defAction (M.lookup (m', s) keys) fromMaybe (defAction (m', s)) (M.lookup (m', s) keys)