aboutsummaryrefslogtreecommitdiffstats
path: root/Square.hs
blob: 0cd5a3c0bf6a9ba8bb90a00690c30f24bb53f6be (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
-- A layout that splits the screen into a square area and the rest of the
-- screen.


-- An example layout using square to make the very last area square:

--  , combo [(tabbed,3),(tabbed,30),(tabbed,1),(tabbed,1)]
--              (combo [(twoPane 0.03 0.2,1)
--                     ,(combo [(twoPane 0.03 0.8,1),(square,1)]
--                                 (mirror $ twoPane 0.03 0.85),1)] (twoPane 0.03 0.5) )

module XMonadContrib.Square ( square ) where

import XMonad
import Graphics.X11.Xlib
import StackSet ( integrate )

square :: Layout
square = Layout { doLayout = \r s -> arrange r (integrate s), modifyLayout = message }
 where
    arrange rect ws@(_:_) = do
        let (rest, sq) = splitSquare rect
        return (map (\w->(w,rest)) (init ws) ++ [(last ws,sq)])
    arrange _ [] = return []

    message _ = return Nothing

splitSquare :: Rectangle -> (Rectangle, Rectangle)
splitSquare (Rectangle x y w h)
    | w > h = (Rectangle x y (w - h) h, Rectangle (x+fromIntegral (w-h)) y h h)
    | otherwise = (Rectangle x y w (h-w), Rectangle x (y+fromIntegral (h-w)) w w)