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.
3 Licensed under GNU General Public License v2
4 * (c) 2016, Henrik Antonsson
5 * (c) 2015, Joerg Jaspert
8 * (c) 2010-2012, Peter Hofmann
12 local floor = math.floor
17 horizontal = { name = "centerworkh" }
20 local function do_centerwork(p, orientation)
21 local t = p.tag or screen[p.screen].selected_tag
25 if #cls == 0 then return end
30 -- Main column, fixed width and height.
31 local mwfact = t.master_width_factor
32 local mainhei = floor(wa.height * mwfact)
33 local mainwid = floor(wa.width * mwfact)
34 local slavewid = wa.width - mainwid
35 local slaveLwid = floor(slavewid / 2)
36 local slaveRwid = slavewid - slaveLwid
37 local slavehei = wa.height - mainhei
38 local slaveThei = floor(slavehei / 2)
39 local slaveBhei = slavehei - slaveThei
40 local nbrFirstSlaves = floor(#cls / 2)
41 local nbrSecondSlaves = floor((#cls - 1) / 2)
43 local slaveFirstDim, slaveSecondDim = 0, 0
45 if orientation == "vertical" then
46 if nbrFirstSlaves > 0 then slaveFirstDim = floor(wa.height / nbrFirstSlaves) end
47 if nbrSecondSlaves > 0 then slaveSecondDim = floor(wa.height / nbrSecondSlaves) end
52 g.x = wa.x + slaveLwid
55 if nbrFirstSlaves > 0 then slaveFirstDim = floor(wa.width / nbrFirstSlaves) end
56 if nbrSecondSlaves > 0 then slaveSecondDim = floor(wa.width / nbrSecondSlaves) end
62 g.y = wa.y + slaveThei
65 if g.width < 1 then g.width = 1 end
66 if g.height < 1 then g.height = 1 end
71 if #cls <= 1 then return end
76 local rowIndex = floor(i/2)
78 if orientation == "vertical" then
82 g.y = wa.y + (rowIndex-1)*slaveFirstDim
86 -- if last slave in left row use remaining space for that slave
87 if rowIndex == nbrFirstSlaves then
88 g.height = wa.y + wa.height - g.y
90 g.height = slaveFirstDim
94 g.x = wa.x + slaveLwid + mainwid
95 g.y = wa.y + (rowIndex-1)*slaveSecondDim
99 -- if last slave in right row use remaining space for that slave
100 if rowIndex == nbrSecondSlaves then
101 g.height = wa.y + wa.height - g.y
103 g.height = slaveSecondDim
109 g.x = wa.x + (rowIndex-1)*slaveFirstDim
114 -- if last slave in top row use remaining space for that slave
115 if rowIndex == nbrFirstSlaves then
116 g.width = wa.x + wa.width - g.x
118 g.width = slaveFirstDim
122 g.x = wa.x + (rowIndex-1)*slaveSecondDim
123 g.y = wa.y + slaveThei + mainhei
127 -- if last slave in bottom row use remaining space for that slave
128 if rowIndex == nbrSecondSlaves then
129 g.width = wa.x + wa.width - g.x
131 g.width = slaveSecondDim
137 if g.width < 1 then g.width = 1 end
138 if g.height < 1 then g.height = 1 end
145 function centerwork.horizontal.arrange(p)
146 return do_centerwork(p, "horizontal")
149 function centerwork.arrange(p)
150 return do_centerwork(p, "vertical")