]> git.madduck.net Git - etc/awesome.git/blob - layout/cascadetile.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

mpd: default art added
[etc/awesome.git] / layout / cascadetile.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2013,      Luke Bonham                
6       * (c) 2010-2012, Peter Hofmann              
7                                                   
8 --]]
9
10 local tag       = require("awful.tag")
11 local beautiful = require("beautiful")
12 local tonumber  = tonumber
13
14 local cascadetile =
15 {
16     name          = "cascadetile",
17     nmaster       = 0,
18     ncol          = 0,
19     mwfact        = 0,
20     offset_x      = 5,
21     offset_y      = 32,
22     extra_padding = 0
23 }
24
25 function cascadetile.arrange(p)
26
27     -- Layout with one fixed column meant for a master window. Its
28     -- width is calculated according to mwfact. Other clients are
29     -- cascaded or "tabbed" in a slave column on the right.
30
31     -- It's a bit hard to demonstrate the behaviour with ASCII-images...
32     --
33     --       (1)              (2)              (3)              (4)
34     --   +-----+---+      +-----+---+      +-----+---+      +-----+---+
35     --   |     |   |      |     |   |      |     |   |      |     | 4 |
36     --   |     |   |      |     | 2 |      |     | 3 |      |     |   |
37     --   |  1  |   |  ->  |  1  |   |  ->  |  1  |   |  ->  |  1  +---+
38     --   |     |   |      |     +---+      |     +---+      |     | 3 |
39     --   |     |   |      |     |   |      |     | 2 |      |     |---|
40     --   |     |   |      |     |   |      |     |---|      |     | 2 |
41     --   |     |   |      |     |   |      |     |   |      |     |---|
42     --   +-----+---+      +-----+---+      +-----+---+      +-----+---+
43
44     -- A useless gap (like the dwm patch) can be defined with
45     -- beautiful.useless_gap_width.
46     local useless_gap = tonumber(beautiful.useless_gap_width) or 0
47
48     -- Screen.
49     local wa = p.workarea
50     local cls = p.clients
51
52     -- Width of main column?
53     local t = tag.selected(p.screen)
54     local mwfact
55     if cascadetile.mwfact > 0
56     then
57         mwfact = cascadetile.mwfact
58     else
59         mwfact = tag.getmwfact(t)
60     end
61
62     -- Make slave windows overlap main window? Do this if ncol is 1.
63     local overlap_main
64     if cascadetile.ncol > 0
65     then
66         overlap_main = cascadetile.ncol
67     else
68         overlap_main = tag.getncol(t)
69     end
70
71     -- Minimum space for slave windows? See cascade.lua.
72     local num_c
73     if cascadetile.nmaster > 0
74     then
75         num_c = cascadetile.nmaster
76     else
77         num_c = tag.getnmaster(t)
78     end
79
80     local how_many = #cls - 1
81     if how_many < num_c
82     then
83         how_many = num_c
84     end
85     local current_offset_x = cascadetile.offset_x * (how_many - 1)
86     local current_offset_y = cascadetile.offset_y * (how_many - 1)
87
88     if #cls > 0
89     then
90         -- Main column, fixed width and height.
91         local c = cls[#cls]
92         local g = {}
93         local mainwid = wa.width * mwfact
94         local slavewid = wa.width - mainwid
95
96         if overlap_main == 1
97         then
98             g.width = wa.width
99
100             -- The size of the main window may be reduced a little bit.
101             -- This allows you to see if there are any windows below the
102             -- main window.
103             -- This only makes sense, though, if the main window is
104             -- overlapping everything else.
105             g.width = g.width - cascadetile.extra_padding
106         else
107             g.width = mainwid
108         end
109
110         g.height = wa.height
111         g.x = wa.x
112         g.y = wa.y
113         if useless_gap > 0
114         then
115             -- Reduce width once and move window to the right. Reduce
116             -- height twice, however.
117             g.width = g.width - useless_gap
118             g.height = g.height - 2 * useless_gap
119             g.x = g.x + useless_gap
120             g.y = g.y + useless_gap
121
122             -- When there's no window to the right, add an additional
123             -- gap.
124             if overlap_main == 1
125             then
126                 g.width = g.width - useless_gap
127             end
128         end
129         c:geometry(g)
130
131         -- Remaining clients stacked in slave column, new ones on top.
132         if #cls > 1
133         then
134             for i = (#cls - 1),1,-1
135             do
136                 c = cls[i]
137                 g = {}
138                 g.width = slavewid - current_offset_x
139                 g.height = wa.height - current_offset_y
140                 g.x = wa.x + mainwid + (how_many - i) * cascadetile.offset_x
141                 g.y = wa.y + (i - 1) * cascadetile.offset_y
142                 if useless_gap > 0
143                 then
144                     g.width = g.width - 2 * useless_gap
145                     g.height = g.height - 2 * useless_gap
146                     g.x = g.x + useless_gap
147                     g.y = g.y + useless_gap
148                 end
149                 c:geometry(g)
150             end
151         end
152     end
153 end
154
155 return cascadetile