aboutsummaryrefslogtreecommitdiffstats
path: root/RotView.hs
blob: 1fc421e5372fc3eb545d9e47a9872ab405389f99 (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
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 Control.Monad.State ( gets )
import Data.List ( sortBy )
import Data.Maybe ( listToMaybe )

import XMonad
import StackSet hiding (filter)
import qualified Operations as O

rotView :: Bool -> X ()
rotView b = do
    ws <- gets windowset
    let m = tag . workspace . current $ ws
        sortWs = sortBy (\x y -> compare (tag x) (tag y))
        pivoted = uncurry (flip (++)) . span ((< m) . tag) . sortWs . hidden $ ws
        nextws = listToMaybe . filter (not.isEmpty) . (if b then id else reverse) $ pivoted
    whenJust nextws (O.view . tag)

isEmpty :: Workspace i a -> Bool
isEmpty ws = case stack ws of
                Empty     -> True
                _         -> False