aboutsummaryrefslogtreecommitdiff
path: root/src/Rahm/Desktop/StackSet.hs
blob: 251bee3ae9320c5845f9f01f43cb7f57d44a5b35 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module Rahm.Desktop.StackSet (
  masterWindow,
  findWorkspace,
  ensureWorkspace,
  swapWorkspaces,
  greedyView,
  shiftWin,
  module W) where

import Prelude hiding (head, tail)
import Data.List.Safe (head, tail)
import Data.List (find)
import XMonad.StackSet as W hiding (greedyView, shiftWin)
import qualified XMonad.StackSet
import Data.Default
import Data.Maybe (fromMaybe)

masterWindow :: StackSet i l a s sd -> Maybe a
masterWindow = head . integrate' . stack . workspace . current

findWorkspace :: (Eq i) =>
  i -> StackSet i l a s sd -> Maybe (Workspace i l a)
findWorkspace wid = find ((==wid) . tag) . workspaces

ensureWorkspace :: (Eq i) =>
  i -> StackSet i l a s sd -> (StackSet i l a s sd, Workspace i l a)
ensureWorkspace t ss =
  case findWorkspace t ss of
    Nothing ->
      let ws = Workspace t (layout . workspace . current $ ss) Nothing in
        (ss { hidden = ws : hidden ss }, ws)
    Just ws -> (ss, ws)

swapWorkspaces ::
  (Eq i) =>
    i -> i -> StackSet i l a s sd -> StackSet i l a s sd
swapWorkspaces wid1 wid2 ss =
  let (ss', workspace1) = ensureWorkspace wid1 ss
      (ss'', workspace2) = ensureWorkspace wid2 ss'
      in
  mapWorkspace (\w ->
    case () of
      _ | tag w == wid1 -> workspace2
      _ | tag w == wid2 -> workspace1
      _ -> w) ss''
      
greedyView :: (Eq i) => i -> StackSet i l a s sd -> StackSet i l a s sd
greedyView wid ss = swapWorkspaces (tag . workspace . current $ ss) wid ss

shiftWin :: (Ord a, Eq s, Eq i) => i -> a -> StackSet i l a s sd -> StackSet i l a s sd
shiftWin wid a = XMonad.StackSet.shiftWin wid a . fst . ensureWorkspace wid