diff options
| author | Josh Rahm <rahm@google.com> | 2021-11-12 13:08:24 -0700 |
|---|---|---|
| committer | Josh Rahm <joshuarahm@gmail.com> | 2022-10-09 12:19:45 -0600 |
| commit | b7272ba8c84f254c3b7efcaf3d8e20686eeb0b1c (patch) | |
| tree | 55047421e937bd0b289b893fce8572c9a0716ded /src/Internal/SwapMaster.hs | |
| parent | 04d0ab42a39df36acfc84846cc122f0bb9786446 (diff) | |
| download | rde-b7272ba8c84f254c3b7efcaf3d8e20686eeb0b1c.tar.gz rde-b7272ba8c84f254c3b7efcaf3d8e20686eeb0b1c.tar.bz2 rde-b7272ba8c84f254c3b7efcaf3d8e20686eeb0b1c.zip | |
Change swapMaster.
Swap master now swaps the master window with the prior master window if
swapMaster is called while the master window is focused.
Diffstat (limited to 'src/Internal/SwapMaster.hs')
| -rw-r--r-- | src/Internal/SwapMaster.hs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/Internal/SwapMaster.hs b/src/Internal/SwapMaster.hs new file mode 100644 index 0000000..c73cbd9 --- /dev/null +++ b/src/Internal/SwapMaster.hs @@ -0,0 +1,41 @@ +{- Swap window with the master, but save it. -} +module Internal.SwapMaster (swapMaster) where + +import qualified XMonad.StackSet as W + +import Internal.Windows (mapWindows, getMaster, swapWindows) +import Control.Monad.Trans.Maybe +import XMonad (Window, ExtensionClass(..), X(..), windows, windowset) +import Control.Monad (void) +import Control.Monad.Trans (lift) +import Data.Maybe (fromMaybe) +import Control.Monad.State (get) + +import qualified XMonad.Util.ExtensibleState as XS + +data LastWindow = LastWindow { + lastWindow :: (Maybe Window) + } deriving (Show, Read) + +instance ExtensionClass LastWindow where + initialValue = LastWindow Nothing + +hoist :: (Monad m) => Maybe a -> MaybeT m a +hoist = MaybeT . return + +swapMaster :: X () +swapMaster = void $ runMaybeT $ do + ss <- lift $ windowset <$> get + + focused <- hoist $ W.peek ss + master <- hoist $ getMaster ss + + if focused == master + then do + lw <- MaybeT $ lastWindow <$> XS.get + lift $ windows (swapWindows focused lw) + else lift $ windows (swapWindows focused master) + + lift $ do + XS.put (LastWindow $ Just master) + windows W.focusMaster |