aboutsummaryrefslogtreecommitdiffstats
path: root/ThreeColumns.hs
blob: 6d74cb9db30cb9bacd9aef7980aceeabf2ed8dcf (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
64
65
66
67
68
69
70
-----------------------------------------------------------------------------
-- |
-- Module      :  XMonadContrib.ThreeColumns
-- Copyright   :  (c) Kai Grossjohann <kai@emptydomain.de>
-- License     :  BSD3-style (see LICENSE)
-- 
-- Maintainer  :  ?
-- Stability   :  unstable
-- Portability :  unportable
--
-- A layout similar to tall but with three columns.
--
-----------------------------------------------------------------------------

module XMonadContrib.ThreeColumns (
                              -- * Usage
                              -- $usage
                              threeCol
                             ) where

import XMonad
import qualified StackSet as W
import Operations ( Resize(..), IncMasterN(..), splitVertically, tall )

import Data.Ratio

--import Control.Monad.State
import Control.Monad.Reader

import Graphics.X11.Xlib

-- $usage
--
-- You can use this module with the following in your Config.hs file:
--
-- > import XMonadContrib.ThreeColumns
--
--  and add, to the list of layouts:
--
-- > threeCol

threeCol :: Int -> Rational -> Rational -> Layout a
threeCol nmaster delta frac =
    Layout { doLayout     = \r -> return . (\x->(x,Nothing)) .
                                  ap zip (tile3 frac r nmaster . length) . W.integrate
           , modifyLayout = \m -> return $ msum [fmap resize     (fromMessage m)
                                                ,fmap incmastern (fromMessage m)] }

    where resize Shrink = tall nmaster delta (max 0 $ frac-delta)
          resize Expand = tall nmaster delta (min 1 $ frac+delta)
          incmastern (IncMasterN d) = tall (max 0 (nmaster+d)) delta frac

-- | tile3.  Compute window positions using 3 panes
tile3 :: Rational -> Rectangle -> Int -> Int -> [Rectangle]
tile3 f r nmaster n = if n <= nmaster || nmaster == 0
    then splitVertically n r
    else splitVertically nmaster r1 ++ splitVertically nmid r2 ++ splitVertically nright r3
  where (r1, r2, r3) = split3HorizontallyBy f r
        nslave = (n - nmaster)
        nmid = floor (nslave % 2)
        nright = (n - nmaster - nmid)

split3HorizontallyBy :: Rational -> Rectangle -> (Rectangle, Rectangle, Rectangle)
split3HorizontallyBy f (Rectangle sx sy sw sh) =
    ( Rectangle sx sy leftw sh
    , Rectangle (sx + fromIntegral leftw) sy midw sh
    , Rectangle (sx + fromIntegral leftw + fromIntegral midw) sy rightw sh )
  where leftw = floor $ fromIntegral sw * (2/3) * f
        midw = floor ( (sw - leftw) % 2 )
        rightw = sw - leftw - midw