aboutsummaryrefslogtreecommitdiff
path: root/src/Rahm/Desktop/SwapMaster.hs
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2023-12-04 12:53:17 -0700
committerJosh Rahm <rahm@google.com>2023-12-04 12:53:17 -0700
commit2ab0c27e9864fd072275664ff13270c5e42ed1b6 (patch)
treefebac27241d330546d9d0b1bed5b97e3fe2f0fc7 /src/Rahm/Desktop/SwapMaster.hs
parent7451146b8738db5bd31c968e9fc6703fcbff6078 (diff)
downloadrde-2ab0c27e9864fd072275664ff13270c5e42ed1b6.tar.gz
rde-2ab0c27e9864fd072275664ff13270c5e42ed1b6.tar.bz2
rde-2ab0c27e9864fd072275664ff13270c5e42ed1b6.zip
Fix bug in master swapping where the last window is not scoped to a tag.
Diffstat (limited to 'src/Rahm/Desktop/SwapMaster.hs')
-rw-r--r--src/Rahm/Desktop/SwapMaster.hs44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/Rahm/Desktop/SwapMaster.hs b/src/Rahm/Desktop/SwapMaster.hs
index c7e02bc..68072a9 100644
--- a/src/Rahm/Desktop/SwapMaster.hs
+++ b/src/Rahm/Desktop/SwapMaster.hs
@@ -5,11 +5,16 @@ import Control.Monad (void)
import Control.Monad.State (gets)
import Control.Monad.Trans (lift)
import Control.Monad.Trans.Maybe (MaybeT (..))
+import Data.Map (Map)
+import qualified Data.Map as Map
+import Rahm.Desktop.Common (runMaybeT_)
import qualified Rahm.Desktop.StackSet as W
- ( focusMaster,
+ ( currentTag,
+ focusMaster,
masterWindow,
peek,
swapWindows,
+ tag,
)
import XMonad
( ExtensionClass (..),
@@ -18,33 +23,42 @@ import XMonad
windows,
windowset,
)
-import qualified XMonad.Util.ExtensibleState as XS (get, put)
+import qualified XMonad.Util.ExtensibleState as XS (get, modify, put)
newtype LastWindow = LastWindow
- { lastWindow :: Maybe Window
+ { lastWindow :: Map String Window
}
deriving (Show, Read)
instance ExtensionClass LastWindow where
- initialValue = LastWindow Nothing
+ initialValue = LastWindow mempty
hoist :: (Monad m) => Maybe a -> MaybeT m a
hoist = MaybeT . return
swapMaster :: X ()
-swapMaster = void $
- runMaybeT $ do
+swapMaster =
+ runMaybeT_ $ do
ss <- gets windowset
+ let ct = W.currentTag ss
- focused <- hoist $ W.peek ss
- master <- hoist $ W.masterWindow ss
-
- if focused == master
- then do
- lw <- MaybeT $ lastWindow <$> XS.get
- lift $ windows (W.swapWindows [(focused, lw)])
- else lift $ windows (W.swapWindows [(focused, master)])
+ (focused, master) <-
+ hoist $ do
+ a <- W.peek ss
+ b <- W.masterWindow ss
+ return (a, b)
lift $ do
- XS.put (LastWindow $ Just master)
+ st <- lastWindow <$> XS.get
+ windows . W.swapWindows $
+ case focused == master of
+ True
+ | (Just lw) <- Map.lookup ct st ->
+ [(focused, lw)]
+ False -> [(master, focused)]
+ _ -> []
+
+ XS.modify $
+ \(LastWindow m) ->
+ LastWindow $ Map.insert (W.currentTag ss) master m
windows W.focusMaster