aboutsummaryrefslogtreecommitdiff
path: root/src/Rahm/Desktop/Keys.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Rahm/Desktop/Keys.hs')
-rw-r--r--src/Rahm/Desktop/Keys.hs78
1 files changed, 62 insertions, 16 deletions
diff --git a/src/Rahm/Desktop/Keys.hs b/src/Rahm/Desktop/Keys.hs
index b6f8737..5fcea5a 100644
--- a/src/Rahm/Desktop/Keys.hs
+++ b/src/Rahm/Desktop/Keys.hs
@@ -3,6 +3,7 @@ module Rahm.Desktop.Keys (applyKeys, commandHandler) where
import Control.Applicative
import Control.Monad
( filterM,
+ forM,
forM_,
unless,
when,
@@ -47,6 +48,7 @@ import Graphics.X11.XScreenSaver (XScreenSaverState (ScreenSaverCycle))
import Rahm.Desktop.BorderColors (BorderColor (BorderColor), withBorderColor, withBorderColorM)
import Rahm.Desktop.Common
( Location (..),
+ Xish (liftFromX),
click,
duplWindow,
focusLocation,
@@ -70,7 +72,7 @@ import Rahm.Desktop.History
)
import Rahm.Desktop.Keys.Dsl2
import Rahm.Desktop.Keys.Grab (KeySymOrKeyCode (..))
-import Rahm.Desktop.Keys.KeyFeed (execKeyFeed, liftXToFeed, pushKey, runKeyFeed, runKeyFeedX)
+import Rahm.Desktop.Keys.KeyFeed
import Rahm.Desktop.Keys.Local
import Rahm.Desktop.Keys.Wml
import Rahm.Desktop.Layout (nLayouts)
@@ -119,6 +121,7 @@ import Rahm.Desktop.Submap
submap,
submapButtonsWithKey,
)
+import Rahm.Desktop.Swap
import Rahm.Desktop.SwapMaster (swapMaster)
import Rahm.Desktop.TabletMode
import Rahm.Desktop.Theater
@@ -361,21 +364,64 @@ bindings = do
bind xK_w $ do
justMod $
doc "Swap windows with other windows" $
- pushPendingBuffer "w " $ do
- runMaybeT_ $ do
- l1 <- mapMaybe (\(Location _ w) -> w) <$> runKeyFeed readNextLocationSet
- withBorderColorM selectedWindowsColor l1 $ do
- lift $ addStringToPendingBuffer " "
- l2 <- mapMaybe (\(Location _ w) -> w) <$> runKeyFeed readNextLocationSet
- let (l1', l2') =
- if length l1 > length l2
- then (l1, l2)
- else (l2, l1)
- l1'' = filter (not . (`elem` l2')) l1'
-
- lift $ do
- setAlternateWindows (l1'' ++ l2')
- windows $ W.swapWindows $ zip l1'' l2' ++ zip l2' l1''
+ pushPendingBuffer "w " $
+ execKeyFeed $ do
+ let doPeek :: KeyFeed a -> KeyFeed a -> KeyFeed a
+ doPeek ifDouble notDouble =
+ peekKey
+ ( \case
+ (m, xK_w, _) | m == mod4Mask -> skipKey >> ifDouble
+ _ -> notDouble
+ )
+ in doPeek
+ ( liftFromX $ do
+ currentM <- W.peek <$> gets windowset
+ forM_ currentM $ \current -> do
+ buddy <- getSwapBuddy current
+ case buddy of
+ Just b -> do
+ logs Debug "Swapping %s with buddy %s" (show current) (show b)
+ swapWindows [current] [b]
+ Nothing ->
+ logs Debug "No swap buddy for %s" (show current)
+ )
+ $ do
+ l1 <- mapMaybe (\(Location _ w) -> w) <$> readNextLocationSet
+ liftFromX $ addStringToPendingBuffer " "
+ l2 <- mapMaybe (\(Location _ w) -> w) <$> readNextLocationSet
+ let (l1', l2') =
+ if length l1 > length l2
+ then (l1, l2)
+ else (l2, l1)
+ l1'' = filter (not . (`elem` l2')) l1'
+ in liftFromX $ do
+ setAlternateWindows (l1'' ++ l2')
+ swapWindows l1'' l2'
+
+ -- let doExec :: KeyFeed a -> KeyFeed a -> KeyFeed a
+ -- doExec ifDouble notDouble =
+ -- peekKey
+ -- ( \case
+ -- (m, xK_w, _) | m == mod4Mask -> skipKey >> ifDouble
+ -- _ -> notDouble
+ -- )
+ -- in runKeyFeed $
+ -- doExec (pure ()) $
+ -- runMaybeT_ $
+ -- do
+ -- l1 <- mapMaybe (\(Location _ w) -> w) <$> readNextLocationSet
+ -- withBorderColorM selectedWindowsColor l1 $ do
+ -- lift $ addStringToPendingBuffer " "
+ -- l2 <- mapMaybe (\(Location _ w) -> w) <$> readNextLocationSet
+ -- let (l1', l2') =
+ -- if length l1 > length l2
+ -- then (l1, l2)
+ -- else (l2, l1)
+ -- l1'' = filter (not . (`elem` l2')) l1'
+
+ -- lift $ do
+ -- setAlternateWindows (l1'' ++ l2')
+ -- windows $ W.swapWindows $ zip l1'' l2' ++ zip l2' l1''
shiftMod
$ doc
"Swap two workspaces (or rename the current one). \