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) 2018, Eugene Pakhomov
5 * (c) 2016, Henrik Antonsson
6 * (c) 2015, Joerg Jaspert
9 * (c) 2010-2012, Peter Hofmann
13 local capi, floor, max, screen = capi, math.floor, math.max, screen
17 horizontal = { name = "centerworkh" }
20 local function arrange(p, layout)
21 local t = p.tag or screen[p.screen].selected_tag
25 if #cls == 0 then return end
27 local c, g = cls[1], {}
29 -- Main column, fixed width and height
30 local mwfact = t.master_width_factor
31 local mainhei = floor(wa.height * mwfact)
32 local mainwid = floor(wa.width * mwfact)
33 local slavewid = wa.width - mainwid
34 local slaveLwid = floor(slavewid / 2)
35 local slaveRwid = slavewid - slaveLwid
36 local slavehei = wa.height - mainhei
37 local slaveThei = floor(slavehei / 2)
38 local slaveBhei = slavehei - slaveThei
39 local nbrFirstSlaves = floor(#cls / 2)
40 local nbrSecondSlaves = floor((#cls - 1) / 2)
42 local slaveFirstDim, slaveSecondDim = 0, 0
44 if layout.name == "centerwork" then -- vertical
45 if nbrFirstSlaves > 0 then slaveFirstDim = floor(wa.height / nbrFirstSlaves) end
46 if nbrSecondSlaves > 0 then slaveSecondDim = floor(wa.height / nbrSecondSlaves) end
51 g.x = wa.x + slaveLwid
54 if nbrFirstSlaves > 0 then slaveFirstDim = floor(wa.width / nbrFirstSlaves) end
55 if nbrSecondSlaves > 0 then slaveSecondDim = floor(wa.width / nbrSecondSlaves) end
61 g.y = wa.y + slaveThei
64 g.width = max(g.width, 1)
65 g.height = max(g.height, 1)
70 if #cls <= 1 then return end
72 local c, g = cls[i], {}
73 local idxChecker, dimToAssign
75 local rowIndex = floor(i/2)
77 if layout.name == "centerwork" then
78 if i % 2 == 0 then -- left slave
80 g.y = wa.y + (rowIndex - 1) * slaveFirstDim
83 idxChecker, dimToAssign = nbrFirstSlaves, slaveFirstDim
85 g.x = wa.x + slaveLwid + mainwid
86 g.y = wa.y + (rowIndex - 1) * slaveSecondDim
89 idxChecker, dimToAssign = nbrSecondSlaves, slaveSecondDim
92 -- if last slave in row, use remaining space for it
93 if rowIndex == idxChecker then
94 g.height = wa.y + wa.height - g.y
96 g.height = dimToAssign
99 if i % 2 == 0 then -- top slave
100 g.x = wa.x + (rowIndex - 1) * slaveFirstDim
104 idxChecker, dimToAssign = nbrFirstSlaves, slaveFirstDim
106 g.x = wa.x + (rowIndex - 1) * slaveSecondDim
107 g.y = wa.y + slaveThei + mainhei
110 idxChecker, dimToAssign = nbrSecondSlaves, slaveSecondDim
113 -- if last slave in row, use remaining space for it
114 if rowIndex == idxChecker then
115 g.width = wa.x + wa.width - g.x
117 g.width = dimToAssign
121 g.width = max(g.width, 1)
122 g.height = max(g.height, 1)
128 local function mouse_resize_handler(c, corner, x, y, orientation)
129 local wa = c.screen.workarea
130 local mwfact = c.screen.selected_tag.master_width_factor
131 local g = c:geometry()
133 local cursor = "cross"
137 if orientation == 'vertical' then
138 if g.height + 15 >= wa.height then
139 offset = g.height * .5
140 cursor = "sb_h_double_arrow"
141 elseif not (g.y + g.height + 15 > wa.y + wa.height) then
144 corner_coords = { x = wa.x + wa.width * (1 - mwfact) / 2, y = g.y + offset }
146 if g.width + 15 >= wa.width then
147 offset = g.width * .5
148 cursor = "sb_v_double_arrow"
149 elseif not (g.x + g.width + 15 > wa.x + wa.width) then
152 corner_coords = { y = wa.y + wa.height * (1 - mwfact) / 2, x = g.x + offset }
155 capi.mouse.coords(corner_coords)
157 local prev_coords = {}
159 capi.mousegrabber.run(function(_mouse)
160 if not c.valid then return false end
161 for _, v in ipairs(_mouse.buttons) do
163 prev_coords = { x = _mouse.x, y = _mouse.y }
165 if orientation == 'vertical' then
166 new_mwfact = 1 - (_mouse.x - wa.x) / wa.width * 2
168 new_mwfact = 1 - (_mouse.y - wa.y) / wa.height * 2
170 c.screen.selected_tag.master_width_factor = math.min(math.max(new_mwfact, 0.01), 0.99)
174 return prev_coords.x == _mouse.x and prev_coords.y == _mouse.y
178 function centerwork.arrange(p)
179 return arrange(p, centerwork)
182 function centerwork.horizontal.arrange(p)
183 return arrange(p, centerwork.horizontal)
186 function centerwork.mouse_resize_handler(c, corner, x, y)
187 return mouse_resize_handler(c, corner, x, y, 'vertical')
190 function centerwork.horizontal.mouse_resize_handler(c, corner, x, y)
191 return mouse_resize_handler(c, corner, x, y, 'horizontal')