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, max, screen = math.floor, math.max, screen
16 horizontal = { name = "centerworkh" }
19 local function arrange(p, layout)
20 local t = p.tag or screen[p.screen].selected_tag
24 if #cls == 0 then return end
26 local c, g = cls[1], {}
28 -- Main column, fixed width and height
29 local mwfact = t.master_width_factor
30 local mainhei = floor(wa.height * mwfact)
31 local mainwid = floor(wa.width * mwfact)
32 local slavewid = wa.width - mainwid
33 local slaveLwid = floor(slavewid / 2)
34 local slaveRwid = slavewid - slaveLwid
35 local slavehei = wa.height - mainhei
36 local slaveThei = floor(slavehei / 2)
37 local slaveBhei = slavehei - slaveThei
38 local nbrFirstSlaves = floor(#cls / 2)
39 local nbrSecondSlaves = floor((#cls - 1) / 2)
41 local slaveFirstDim, slaveSecondDim = 0, 0
43 if layout.name == "centerwork" then -- vertical
44 if nbrFirstSlaves > 0 then slaveFirstDim = floor(wa.height / nbrFirstSlaves) end
45 if nbrSecondSlaves > 0 then slaveSecondDim = floor(wa.height / nbrSecondSlaves) end
50 g.x = wa.x + slaveLwid
53 if nbrFirstSlaves > 0 then slaveFirstDim = floor(wa.width / nbrFirstSlaves) end
54 if nbrSecondSlaves > 0 then slaveSecondDim = floor(wa.width / nbrSecondSlaves) end
60 g.y = wa.y + slaveThei
63 g.width = max(g.width, 1)
64 g.height = max(g.height, 1)
69 if #cls <= 1 then return end
71 local c, g = cls[i], {}
72 local idxChecker, dimToAssign
74 local rowIndex = floor(i/2)
76 if layout.name == "centerwork" then
77 if i % 2 == 0 then -- left slave
79 g.y = wa.y + (rowIndex - 1) * slaveFirstDim
82 idxChecker, dimToAssign = nbrFirstSlaves, slaveFirstDim
84 g.x = wa.x + slaveLwid + mainwid
85 g.y = wa.y + (rowIndex - 1) * slaveSecondDim
88 idxChecker, dimToAssign = nbrSecondSlaves, slaveSecondDim
91 -- if last slave in row, use remaining space for it
92 if rowIndex == idxChecker then
93 g.height = wa.y + wa.height - g.y
95 g.height = dimToAssign
98 if i % 2 == 0 then -- top slave
99 g.x = wa.x + (rowIndex - 1) * slaveFirstDim
103 idxChecker, dimToAssign = nbrFirstSlaves, slaveFirstDim
105 g.x = wa.x + (rowIndex - 1) * slaveSecondDim
106 g.y = wa.y + slaveThei + mainhei
109 idxChecker, dimToAssign = nbrSecondSlaves, slaveSecondDim
112 -- if last slave in row, use remaining space for it
113 if rowIndex == idxChecker then
114 g.width = wa.x + wa.width - g.x
116 g.width = dimToAssign
120 g.width = max(g.width, 1)
121 g.height = max(g.height, 1)
127 function centerwork.arrange(p)
128 return arrange(p, centerwork)
131 function centerwork.horizontal.arrange(p)
132 return arrange(p, centerwork.horizontal)