aboutsummaryrefslogtreecommitdiff
path: root/src/Internal/Submap.hs
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2022-03-21 10:15:03 -0600
committerJosh Rahm <rahm@google.com>2022-03-21 10:15:03 -0600
commitcfb489be45b8222c4984b344ee4e1f2e760dd3b7 (patch)
tree1a1d8c4f6d804ab6560157603785d3aee00ae213 /src/Internal/Submap.hs
parente2b8c1c7e934009e26ad640d75c689211f51cc1b (diff)
parenta87cbc7357566b26c7dca7538d4b03da5f8b999a (diff)
downloadrde-cfb489be45b8222c4984b344ee4e1f2e760dd3b7.tar.gz
rde-cfb489be45b8222c4984b344ee4e1f2e760dd3b7.tar.bz2
rde-cfb489be45b8222c4984b344ee4e1f2e760dd3b7.zip
Merge branch 'v017' of git.josher.dev:rde into v017
Diffstat (limited to 'src/Internal/Submap.hs')
-rw-r--r--src/Internal/Submap.hs46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/Internal/Submap.hs b/src/Internal/Submap.hs
index cdc2f95..e5968ff 100644
--- a/src/Internal/Submap.hs
+++ b/src/Internal/Submap.hs
@@ -1,7 +1,14 @@
-module Internal.Submap (mapNextString, module X) where
+module Internal.Submap (
+ mapNextString,
+ submapButtonsWithKey,
+ nextButton,
+ nextMotion,
+ 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 +33,40 @@ 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
+
+nextMotion :: X (Int, Int)
+nextMotion = do
+ XConf { theRoot = root, display = d } <- ask
+ io $ grabPointer d root False pointerMotionMask grabModeAsync grabModeAsync 0 0 currentTime
+
+ ret <- io $ allocaXEvent $ \xEv -> do
+ maskEvent d pointerMotionMask xEv
+ MotionEvent { ev_x = x, ev_y = y } <- getEvent xEv
+ return (fromIntegral x, fromIntegral y)
+
+ 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