From b7272ba8c84f254c3b7efcaf3d8e20686eeb0b1c Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Fri, 12 Nov 2021 13:08:24 -0700 Subject: Change swapMaster. Swap master now swaps the master window with the prior master window if swapMaster is called while the master window is focused. --- src/Internal/Windows.hs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/Internal/Windows.hs (limited to 'src/Internal/Windows.hs') diff --git a/src/Internal/Windows.hs b/src/Internal/Windows.hs new file mode 100644 index 0000000..0f109b7 --- /dev/null +++ b/src/Internal/Windows.hs @@ -0,0 +1,32 @@ +module Internal.Windows where + +import XMonad.StackSet (Stack(..), StackSet(..), Screen(..), Workspace(..), integrate) +import Data.Maybe (listToMaybe) +import qualified Data.Map as Map + +mapWindows :: (Ord a, Ord b) => (a -> b) -> StackSet i l a s sd -> StackSet i l b s sd +mapWindows fn (StackSet cur vis hid float) = + StackSet + (mapWindowsScreen cur) + (map mapWindowsScreen vis) + (map mapWindowsWorkspace hid) + (Map.mapKeys fn float) + where + mapWindowsScreen (Screen work a b) = Screen (mapWindowsWorkspace work) a b + mapWindowsWorkspace (Workspace t l stack) = + Workspace t l (fmap (mapStack fn) stack) + +-- | What genius decided to hide the instances for the Stack type!!??? +mapStack :: (a -> b) -> Stack a -> Stack b +mapStack fn (Stack focus up down) = Stack (fn focus) (map fn up) (map fn down) + +getMaster :: StackSet i l a s sd -> Maybe a +getMaster (StackSet (Screen (Workspace _ _ ss) _ _) _ _ _) = + head . integrate <$> ss + +swapWindows :: (Ord a) => a -> a -> StackSet i l a s d -> StackSet i l a s d +swapWindows wa wb = mapWindows $ \w -> + case w of + _ | w == wa -> wb + _ | w == wb -> wa + _ -> w -- cgit