aboutsummaryrefslogtreecommitdiffstats
path: root/GreedyView.hs
blob: 275f44c85c52b7edcc7dc6c123952a86a92aac51 (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
-- greedyView is an alternative to standard workspace switching.  When a
-- workspace is already visible on another screen, greedyView swaps the
-- contents of that other screen with the current screen.

module XMonadContrib.GreedyView (greedyView) where

import StackSet as W
import XMonad
import Operations
import Data.List (find)

greedyView :: WorkspaceId -> X ()
greedyView = windows . greedyView'

greedyView' :: WorkspaceId -> WindowSet -> WindowSet
greedyView' w ws
 | any wTag (hidden ws)                             = W.view w ws
 | (Just s) <- find (wTag . workspace) (visible ws) = ws { current = setScreen s (screen $ current ws)
                                                         , visible = setScreen (current ws) (screen s)
                                                                   : filter (not . wTag . workspace) (visible ws)
                                                         }
 | otherwise                                        = ws
 where
    setScreen s i = s { screen = i }
    wTag = (w == ) . tag