aboutsummaryrefslogtreecommitdiffstats
path: root/RotView.hs
blob: 46ce0bf1e2c8ec788c1f42252c64aaa629c28431 (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
module XMonadContrib.RotView ( rotView ) where

-- Provides bindings to cycle through non-empty workspaces.

-- To use:
-- import XMonadContrib.RotView

--    , ((modMask .|. shiftMask, xK_Right), rotView True)
--    , ((modMask .|. shiftMask, xK_Left), rotView False)

import qualified Data.Map as M
import Control.Monad.State

import Operations ( view )
import XMonad ( X, WorkspaceId, workspace, whenJust )
import StackSet ( StackSet )
import Data.Maybe ( listToMaybe )
import qualified StackSet as W ( stacks, current, visibleWorkspaces, index )

rotView :: Bool -> X ()
rotView b = do ws <- gets windowset
               let m = W.current ws
                   vis = W.visibleWorkspaces ws
                   allws = if b then allWorkspaces ws else reverse $ allWorkspaces ws
                   pivoted = uncurry (flip (++)) . span (/=m) $ allws
                   interesting i = not (i `elem` vis) && not (isEmpty i ws)
                   nextws = listToMaybe . filter interesting $ pivoted
               whenJust nextws view

-- | A list of all the workspaces.
allWorkspaces :: StackSet WorkspaceId j a -> [WorkspaceId]
allWorkspaces = M.keys . W.stacks

isEmpty :: WorkspaceId -> StackSet WorkspaceId j a -> Bool
isEmpty i = maybe True null . W.index i