aboutsummaryrefslogtreecommitdiffstats
path: root/Tabbed.hs
blob: 5710bf8691317b06a2f209b611526380d6387d44 (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
module XMonadContrib.Tabbed ( tabbed ) where

-- This module defines a tabbed layout.

-- You can use this module with the following in your config file:

-- import XMonadContrib.Tabbed

-- defaultLayouts :: [Layout]
-- defaultLayouts = [ tabbed
--                  , ... ]

import Control.Monad ( forM )

import Graphics.X11.Xlib
import XMonad
import XMonadContrib.Decoration
import Operations ( focus )

tabbed :: Layout
tabbed =  Layout { doLayout = dolay, modifyLayout = const (return Nothing) }

dolay :: Rectangle -> [Window] -> X [(Window, Rectangle)]
dolay sc [w] = return [(w,sc)]
dolay sc@(Rectangle x _ wid _) ws =
    do let ts = gentabs x wid (length ws)
           tws = zip ts ws
       forM tws $ \(t,w) -> newDecoration t 1 0xFF0000 0x00FFFF (trace "draw") (focus w)
       return [ (w,shrink sc) | w <- ws ]

shrink :: Rectangle -> Rectangle
shrink (Rectangle x y w h) = Rectangle x (y+tabsize) w (h-tabsize)

gentabs :: Position -> Dimension -> Int -> [Rectangle]
gentabs _ _ 0 = []
gentabs x1 w num = Rectangle x1 0 (wid - 2) (tabsize - 2)
                   : gentabs (x1 + fromIntegral wid) (w - wid) (num - 1)
                              where wid = w `div` (fromIntegral num)

tabsize :: Integral a => a
tabsize = 30