aboutsummaryrefslogtreecommitdiff
path: root/src/Internal/Windows.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Internal/Windows.hs')
-rw-r--r--src/Internal/Windows.hs32
1 files changed, 32 insertions, 0 deletions
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