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) 2016, Henrik Antonsson
6 * (c) 2015, Joerg Jaspert
8 * (c) 2013, Luke Bonham
9 * (c) 2010-2012, Peter Hofmann
13 local tonumber = tonumber
14 local math = { floor = math.floor }
15 local scr = require("awful.screen")
19 horizontal = { name = "centerworkh" }
22 local function do_centerwork(p, orientation)
26 local ta = scr.focused().selected_tag
28 if not ta then return end
30 if #cls <= 0 then return end
33 local useless_gap = p.useless_gap or 0
38 -- Main column, fixed width and height.
39 local mwfact = ta.master_width_factor
40 local mainhei = math.floor(wa.height * mwfact)
41 local mainwid = math.floor(wa.width * mwfact)
42 local slavewid = wa.width - mainwid
43 local slaveLwid = math.floor(slavewid / 2)
44 local slaveRwid = slavewid - slaveLwid
45 local slavehei = wa.height - mainhei
46 local slaveThei = math.floor(slavehei / 2)
47 local slaveBhei = slavehei - slaveThei
48 local nbrFirstSlaves = math.floor(#cls / 2)
49 local nbrSecondSlaves = math.floor((#cls - 1) / 2)
51 local slaveFirstDim, slaveSecondDim = 0, 0
53 if orientation == "vertical" then
54 if nbrFirstSlaves > 0 then slaveFirstDim = math.floor(wa.height / nbrFirstSlaves) end
55 if nbrSecondSlaves > 0 then slaveSecondDim = math.floor(wa.height / nbrSecondSlaves) end
57 g.height = wa.height - 2*useless_gap - 2*c.border_width
58 g.width = mainwid - 2*c.border_width
60 g.x = wa.x + slaveLwid
61 g.y = wa.y + useless_gap
63 if nbrFirstSlaves > 0 then slaveFirstDim = math.floor(wa.width / nbrFirstSlaves) end
64 if nbrSecondSlaves > 0 then slaveSecondDim = math.floor(wa.width / nbrSecondSlaves) end
66 g.height = mainhei - 2*c.border_width
67 g.width = wa.width - 2*useless_gap - 2*c.border_width
69 g.x = wa.x + useless_gap
70 g.y = wa.y + slaveThei
73 if g.width < 1 then g.width = 1 end
74 if g.height < 1 then g.height = 1 end
79 if #cls <= 1 then return end
84 local rowIndex = math.floor(i/2)
86 if orientation == "vertical" then
89 g.x = wa.x + useless_gap
90 g.y = wa.y + useless_gap + (rowIndex-1)*slaveFirstDim
92 g.width = slaveLwid - 2*useless_gap - 2*c.border_width
94 -- if last slave in left row use remaining space for that slave
95 if rowIndex == nbrFirstSlaves then
96 g.height = wa.y + wa.height - g.y - useless_gap - 2*c.border_width
98 g.height = slaveFirstDim - useless_gap - 2*c.border_width
102 g.x = wa.x + slaveLwid + mainwid + useless_gap
103 g.y = wa.y + useless_gap + (rowIndex-1)*slaveSecondDim
105 g.width = slaveRwid - 2*useless_gap - 2*c.border_width
107 -- if last slave in right row use remaining space for that slave
108 if rowIndex == nbrSecondSlaves then
109 g.height = wa.y + wa.height - g.y - useless_gap - 2*c.border_width
111 g.height = slaveSecondDim - useless_gap - 2*c.border_width
117 g.x = wa.x + useless_gap + (rowIndex-1)*slaveFirstDim
118 g.y = wa.y + useless_gap
120 g.height = slaveThei - 2*useless_gap - 2*c.border_width
122 -- if last slave in top row use remaining space for that slave
123 if rowIndex == nbrFirstSlaves then
124 g.width = wa.x + wa.width - g.x - useless_gap - 2*c.border_width
126 g.width = slaveFirstDim - useless_gap - 2*c.border_width
130 g.x = wa.x + useless_gap + (rowIndex-1)*slaveFirstDim
131 g.y = wa.y + slaveThei + mainhei + useless_gap
133 g.height = slaveBhei - 2*useless_gap - 2*c.border_width
135 -- if last slave in bottom row use remaining space for that slave
136 if rowIndex == nbrSecondSlaves then
137 g.width = wa.x + wa.width - g.x - useless_gap - 2*c.border_width
139 g.width = slaveSecondDim - useless_gap - 2*c.border_width
145 if g.width < 1 then g.width = 1 end
146 if g.height < 1 then g.height = 1 end
153 function centerwork.horizontal.arrange(p)
154 return do_centerwork(p, "horizontal")
157 function centerwork.arrange(p)
158 return do_centerwork(p, "vertical")