aboutsummaryrefslogblamecommitdiffstats
path: root/RotView.hs
blob: 6a8fc7f16023dc36a29c62419c92ce2a8d3d26ff (plain) (tree)
1
2
3
4
5
6
7
8
9
10


                                                           

          
                               



                                                         

                                   
                                         
 
             
                               
                                
 





                                                                                 
                                                                                              
                                  
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, isJust )

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 (isJust . stack) . (if b then id else reverse) $ pivoted
    whenJust nextws (O.view . tag)