aboutsummaryrefslogtreecommitdiffstats
path: root/GreedyView.hs
blob: 6cfa61243bf200098adac68c6338dc0706e5ec42 (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
52
53
54
55
56
57
58
59
60
61
62
63
{-# OPTIONS -fglasgow-exts #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  XMonadContrib.GreedyView
-- Copyright   :  (c) Spencer Janssen <sjanssen@cse.unl.edu>
-- License     :  BSD3-style (see LICENSE)
--
-- Maintainer  :  Spencer Janssen <sjanssen@cse.unl.edu>
-- Stability   :  unstable
-- Portability :  unportable
--
-- 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 (
                                 -- * Usage
                                 -- $usage
                                 greedyView
                                ) where

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

-- $usage
-- To use GreedyView as your default workspace switcher
--
-- Add this import:
--
-- >     import XMonadContrib.GreedyView
--
-- And replace the function call used to switch workspaces,
--
-- this:
--
-- > [((m .|. modMask, k), f i)
-- >     | (i, k) <- zip [0 .. fromIntegral workspaces - 1] [xK_1 ..]
-- >     , (f, m) <- [(view, 0), (shift, shiftMask)]]
--
-- becomes this :
--
-- > [((m .|. modMask, k), f i)
-- >     | (i, k) <- zip [0 .. fromIntegral workspaces - 1] [xK_1 ..]
-- >     , (f, m) <- [(greedyView, 0), (shift, shiftMask)]]
--

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 = (current ws) { workspace = workspace s }
                                                         , visible = s { workspace = workspace (current ws) }
                                                                   : filter (not . wTag . workspace) (visible ws)
                                                         }
 | otherwise                                        = ws
 where
    wTag = (w == ) . tag