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.
4 Licensed under GNU General Public License v2
5 * (c) 2013, Luke Bonham
6 * (c) 2010, Nicolas Estibals
7 * (c) 2010-2012, Peter Hofmann
11 local tag = require("awful.tag")
12 local beautiful = require("beautiful")
13 local math = { ceil = math.ceil,
16 local tonumber = tonumber
18 local centerfair = { name = "centerfair" }
20 function centerfair.arrange(p)
21 -- Layout with fixed number of vertical columns (read from nmaster).
22 -- Cols are centerded until there is nmaster columns, then windows
23 -- are stacked in the slave columns, with at most ncol clients per
24 -- column if possible.
26 -- with nmaster=3 and ncol=1 you'll have
28 -- +---+---+---+ +-+---+---+-+ +---+---+---+
29 -- | | | | | | | | | | | | |
30 -- | | 1 | | -> | | 1 | 2 | | -> | 1 | 2 | 3 | ->
31 -- | | | | | | | | | | | | |
32 -- +---+---+---+ +-+---+---+-+ +---+---+---+
35 -- +---+---+---+ +---+---+---+
36 -- | | | 3 | | | 2 | 4 |
37 -- + 1 + 2 +---+ -> + 1 +---+---+
38 -- | | | 4 | | | 3 | 5 |
39 -- +---+---+---+ +---+---+---+
41 -- A useless gap (like the dwm patch) can be defined with
42 -- beautiful.useless_gap_width .
43 local useless_gap = tonumber(beautiful.useless_gap_width) or 0
49 -- How many vertical columns? Read from nmaster on the tag.
50 local t = tag.selected(p.screen)
51 local num_x = centerfair.nmaster or tag.getnmaster(t)
52 local ncol = centerfair.ncol or tag.getncol(t)
54 local width = math.floor((wa.width-(num_x+1)*useless_gap) / num_x)
56 local offset_y = wa.y + useless_gap
59 -- Less clients than the number of columns, let's center it!
60 local offset_x = wa.x + useless_gap + (wa.width - #cls*width - (#cls+1)*useless_gap) / 2
63 g.height = wa.height - 2*useless_gap - 2
66 g.x = offset_x + (i - 1) * (width + useless_gap + 2)
70 -- More clients than the number of columns, let's arrange it!
72 if useless_gap > 0 then
76 -- Master client deserves a special treatement
78 g.width = wa.width - (num_x-1)*width -num_x*useless_gap - 2
79 g.height = wa.height - 2*useless_gap - 2
80 g.x = offset_x + useless_gap
84 -- Treat the other clients
86 -- Compute distribution of clients among columns
89 local remaining_clients = #cls-1
90 local ncol_min = math.ceil(remaining_clients/(num_x-1))
93 for i = (num_x-1), 1, -1 do
94 if (remaining_clients-i+1) < ncol
96 num_y[i] = remaining_clients-i + 1
100 remaining_clients = remaining_clients - num_y[i]
103 local rem = remaining_clients % (num_x-1)
106 for i = 1, num_x-1 do
110 for i = 1, num_x-1 do
111 num_y[i] = ncol_min - 1
114 num_y[num_x-1-i] = num_y[num_x-1-i] + 1
120 -- Compute geometry of the other clients
122 g.x = g.x + g.width+useless_gap + 2
125 if useless_gap > 0 then
126 g.width = g.width - useless_gap/2 - 2
129 for i = 1, (num_x-1) do
131 g.height = math.floor((wa.height-useless_gap)/num_y[i])
133 for j = 0, (num_y[i]-2) do
134 cls[nclient]:geometry(g)
135 nclient = nclient + 1
136 g.y = g.y + g.height+useless_gap + 2
137 to_remove = to_remove + 2
139 g.height = wa.height - num_y[i]*useless_gap - (num_y[i]-1)*g.height - useless_gap - to_remove
140 cls[nclient]:geometry(g)
141 nclient = nclient + 1
142 g.x = g.x+g.width+useless_gap + 2