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 tag = require("awful.tag")
14 local tonumber = tonumber
15 local math = { floor = math.floor }
19 horizontal = { name = "centerworkh" }
22 local function do_centerwork(p, orientation)
27 if #cls <= 0 then return end
30 local useless_gap = p.useless_gap or 0
35 -- Main column, fixed width and height.
36 local mwfact = tag.object.get_master_width_factor(t)
37 local mainhei = math.floor(wa.height * mwfact)
38 local mainwid = math.floor(wa.width * mwfact)
39 local slavewid = wa.width - mainwid
40 local slaveLwid = math.floor(slavewid / 2)
41 local slaveRwid = slavewid - slaveLwid
42 local slavehei = wa.height - mainhei
43 local slaveThei = math.floor(slavehei / 2)
44 local slaveBhei = slavehei - slaveThei
45 local nbrFirstSlaves = math.floor(#cls / 2)
46 local nbrSecondSlaves = math.floor((#cls - 1) / 2)
48 local slaveFirstDim, slaveSecondDim = 0, 0
50 if orientation == "vertical" then
51 if nbrFirstSlaves > 0 then slaveFirstDim = math.floor(wa.height / nbrFirstSlaves) end
52 if nbrSecondSlaves > 0 then slaveSecondDim = math.floor(wa.height / nbrSecondSlaves) end
54 g.height = wa.height - 2*useless_gap - 2*c.border_width
55 g.width = mainwid - 2*c.border_width
57 g.x = wa.x + slaveLwid
58 g.y = wa.y + useless_gap
60 if nbrFirstSlaves > 0 then slaveFirstDim = math.floor(wa.width / nbrFirstSlaves) end
61 if nbrSecondSlaves > 0 then slaveSecondDim = math.floor(wa.width / nbrSecondSlaves) end
63 g.height = mainhei - 2*c.border_width
64 g.width = wa.width - 2*useless_gap - 2*c.border_width
66 g.x = wa.x + useless_gap
67 g.y = wa.y + slaveThei
70 if g.width < 1 then g.width = 1 end
71 if g.height < 1 then g.height = 1 end
76 if #cls <= 1 then return end
81 local rowIndex = math.floor(i/2)
83 if orientation == "vertical" then
86 g.x = wa.x + useless_gap
87 g.y = wa.y + useless_gap + (rowIndex-1)*slaveFirstDim
89 g.width = slaveLwid - 2*useless_gap - 2*c.border_width
91 -- if last slave in left row use remaining space for that slave
92 if rowIndex == nbrFirstSlaves then
93 g.height = wa.y + wa.height - g.y - useless_gap - 2*c.border_width
95 g.height = slaveFirstDim - useless_gap - 2*c.border_width
99 g.x = wa.x + slaveLwid + mainwid + useless_gap
100 g.y = wa.y + useless_gap + (rowIndex-1)*slaveSecondDim
102 g.width = slaveRwid - 2*useless_gap - 2*c.border_width
104 -- if last slave in right row use remaining space for that slave
105 if rowIndex == nbrSecondSlaves then
106 g.height = wa.y + wa.height - g.y - useless_gap - 2*c.border_width
108 g.height = slaveSecondDim - useless_gap - 2*c.border_width
114 g.x = wa.x + useless_gap + (rowIndex-1)*slaveFirstDim
115 g.y = wa.y + useless_gap
117 g.height = slaveThei - 2*useless_gap - 2*c.border_width
119 -- if last slave in top row use remaining space for that slave
120 if rowIndex == nbrFirstSlaves then
121 g.width = wa.x + wa.width - g.x - useless_gap - 2*c.border_width
123 g.width = slaveFirstDim - useless_gap - 2*c.border_width
127 g.x = wa.x + useless_gap + (rowIndex-1)*slaveFirstDim
128 g.y = wa.y + slaveThei + mainhei + useless_gap
130 g.height = slaveBhei - 2*useless_gap - 2*c.border_width
132 -- if last slave in bottom row use remaining space for that slave
133 if rowIndex == nbrSecondSlaves then
134 g.width = wa.x + wa.width - g.x - useless_gap - 2*c.border_width
136 g.width = slaveSecondDim - useless_gap - 2*c.border_width
142 if g.width < 1 then g.width = 1 end
143 if g.height < 1 then g.height = 1 end
150 function centerwork.horizontal.arrange(p)
151 return do_centerwork(p, "horizontal")
154 function centerwork.arrange(p)
155 return do_centerwork(p, "vertical")