diff options
Diffstat (limited to 'src/Internal/Submap.hs')
| -rw-r--r-- | src/Internal/Submap.hs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/Internal/Submap.hs b/src/Internal/Submap.hs index cdc2f95..40becdc 100644 --- a/src/Internal/Submap.hs +++ b/src/Internal/Submap.hs @@ -1,7 +1,13 @@ -module Internal.Submap (mapNextString, module X) where +module Internal.Submap ( + mapNextString, + submapButtonsWithKey, + nextButton, + module X) where import XMonad hiding (keys) import Control.Monad.Fix (fix) +import qualified Data.Map as Map +import Data.Map (Map) import XMonad.Actions.Submap as X @@ -26,3 +32,26 @@ mapNextString fn = do io $ ungrabKeyboard d currentTime fn m str + +nextButton :: X (ButtonMask, Button) +nextButton = do + XConf { theRoot = root, display = d } <- ask + io $ grabPointer d root False buttonPressMask grabModeAsync grabModeAsync 0 0 currentTime + + ret <- io $ allocaXEvent $ \xEv -> do + maskEvent d buttonPressMask xEv + ButtonEvent { ev_button = button, ev_state = m } <- getEvent xEv + return (m, button) + + io $ ungrabPointer d currentTime + + return ret + +submapButtonsWithKey :: + ((ButtonMask, Button) -> Window -> X ()) -> (Map (ButtonMask, Button) (Window -> X ())) -> Window -> X () +submapButtonsWithKey defaultAction actions window = do + arg <- nextButton + + case Map.lookup arg actions of + Nothing -> defaultAction arg window + Just fn -> fn window |