aboutsummaryrefslogtreecommitdiffstats
path: root/SimpleStacking.hs
blob: 3229a8bc5443b184e01dc2bcbcf662fe812fb7d8 (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
{-# OPTIONS -fglasgow-exts #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  XMonadContrib.SimpleStacking
-- Copyright   :  (c) David Roundy <droundy@darcs.net>
-- License     :  BSD-style (see LICENSE)
-- 
-- Maintainer  :  David Roundy <droundy@darcs.net>
-- Stability   :  unstable
-- Portability :  unportable
--
-- A module to be used to obtain a simple "memory" of stacking order.
--
-- WARNING: This module is incompatible with Xinerama!
--
-----------------------------------------------------------------------------

module XMonadContrib.SimpleStacking (
                                     -- * Usage
                                     -- $usage 
                                     simpleStacking
                                    ) where

import Control.Monad.State ( modify )
import qualified Data.Map as M
import Data.Maybe ( catMaybes )

import Data.List ( nub, lookup )
import StackSet ( focus, tag, workspace, current, integrate )
import Graphics.X11.Xlib ( Window )

import XMonad

-- $usage
-- You can use this module for 
-- See, for instance, "XMonadContrib.Tabbed"

simpleStacking :: Layout Window -> Layout Window
simpleStacking = simpleStacking' []

simpleStacking' :: [Window] -> Layout Window -> Layout Window
simpleStacking' st l = l { doLayout = dl
                         , modifyLayout = \m -> fmap (simpleStacking' st) `fmap` modifyLayout l m }
    where dl r s = do modify $ \ state ->
                          state { layouts = M.adjust
                                            (\(_,ss)->(simpleStacking'
                                                       (focus s:filter (`elem` integrate s) st) l,ss))
                                            (tag.workspace.current.windowset $ state)
                                            (layouts state) }
                      lo <- doLayout l r s
                      let m = map (\ (w,rr) -> (w,(w,rr))) lo
                      return $ catMaybes $ map ((flip lookup) m) $ nub (focus s : st ++ map fst lo)