aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad/Layout/Square.hs
blob: 9e07caaf658d49127bca198b01076a688c42adf2 (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
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  XMonad.Layout.Square
-- Copyright   :  (c) David Roundy <droundy@darcs.net>
-- License     :  BSD3-style (see LICENSE)
--
-- Maintainer  :  David Roundy <droundy@darcs.net>
-- Stability   :  unstable
-- Portability :  unportable
--
-- A layout that splits the screen into a square area and the rest of the
-- screen.
-- This is probably only ever useful in combination with
-- "XMonad.Layout.Combo".
-- It sticks one window in a square region, and makes the rest
-- of the windows live with what's left (in a full-screen sense).
--
-----------------------------------------------------------------------------

module XMonad.Layout.Square (
                             -- * Usage
                             -- $usage
                             Square(..) ) where

import XMonad
import XMonad.StackSet ( integrate )

-- $usage
-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@ file:
--
-- >   import XMonad.Layout.Square
--
-- An example layout using square together with "XMonad.Layout.Combo"
-- to make the very last area square:
--
-- > , combo (combo (mirror $ twoPane 0.03 0.85),1)] (twoPane 0.03 0.5) )
-- >                [(twoPane 0.03 0.2,1),(combo [(twoPane 0.03 0.8,1),(square,1)]
-- >         [(tabbed,3),(tabbed,30),(tabbed,1),(tabbed,1)]

-- For detailed instructions on editing your key bindings, see
-- "XMonad.Doc.Extending#Editing_key_bindings".

data Square a = Square deriving ( Read, Show )

instance LayoutClass Square a where
    pureLayout Square r s = arrange (integrate s)
        where arrange ws@(_:_) = map (\w->(w,rest)) (init ws) ++ [(last ws,sq)]
              arrange [] = [] -- actually, this is an impossible case
              (rest, sq) = splitSquare r

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)