aboutsummaryrefslogtreecommitdiffstats
path: root/Dishes.hs
blob: faacd31451badb0d47fbe67ed555aaf091ec8730 (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
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  XMonadContrib.Dishes
-- Copyright   :  (c) Jeremy Apthorp
-- License     :  BSD-style (see LICENSE)
--
-- Maintainer  :  Jeremy Apthorp <nornagon@gmail.com>
-- Stability   :  unstable
-- Portability :  portable
--
-- Dishes is a layout that stacks extra windows underneath the master
-- windows.
--
-----------------------------------------------------------------------------

module XMonadContrib.Dishes (
                              -- * Usage
															-- $usage
                              Dishes (..)
                            ) where

import Data.List
import XMonad
import Operations
import StackSet (integrate)
import Control.Monad (ap)
import Graphics.X11.Xlib

-- $usage
-- You can use this module with the following in your Config.hs file:
--
-- > import XMonadContrib.Dishes
--
-- and add the following line to your 'layouts'
--
-- > , Layout $ Dishes 2 (1%6)

-- %import XMonadContrib.Dishes
-- %layout , Layout $ Dishes 2 (1%6)

data Dishes a = Dishes Int Rational deriving (Show, Read)
instance LayoutClass Dishes a where
	doLayout (Dishes nmaster h) r =
		return . (\x->(x,Nothing)) .
		ap zip (dishes h r nmaster . length) . integrate
	pureMessage (Dishes nmaster h) m = fmap incmastern (fromMessage m)
		where incmastern (IncMasterN d) = Dishes (max 0 (nmaster+d)) h

dishes :: Rational -> Rectangle -> Int -> Int -> [Rectangle]
dishes h s nmaster n = if n <= nmaster
		then splitHorizontally n s
		else ws
	where
		(m,rest) = splitVerticallyBy (1 - (fromIntegral $ n - nmaster) * h) s
		ws = splitHorizontally nmaster m ++ splitVertically (n - nmaster) rest