layouts: spiral: Avoid gaps between windows

When an area is split in two, for example horizontally, one of the windows
should have height math.floor(previous height / 2) and the other
math.ceil(previous height / 2), to be certain that no gaps are left between the
windows.

For instance, if the first window has height h and the second window has height
math.floor(h / 2), the height of the third window should be math.ceil(h / 2)
instead of the same as for the second window.

So to compute the size of window n + 1 it’s necessary to remember the size of
window n - 1 as well as that of window n.

Signed-off-by: Fabienne Ducroquet <fabiduc@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Fabienne Ducroquet 2014-01-18 16:12:30 +01:00 committed by Uli Schlachter
parent 7adc21e2ca
commit 94a8c72596
1 changed files with 19 additions and 11 deletions

View File

@ -7,6 +7,7 @@
-- Grab environment we need -- Grab environment we need
local ipairs = ipairs local ipairs = ipairs
local math = math
-- awful.layout.suit.spiral -- awful.layout.suit.spiral
local spiral = {} local spiral = {}
@ -15,28 +16,35 @@ local function do_spiral(p, _spiral)
local wa = p.workarea local wa = p.workarea
local cls = p.clients local cls = p.clients
local n = #cls local n = #cls
local old_width, old_height = wa.width, 2 * wa.height
for k, c in ipairs(cls) do for k, c in ipairs(cls) do
if k < n then
if k % 2 == 0 then if k % 2 == 0 then
wa.height = wa.height / 2 wa.width, old_width = math.ceil(old_width / 2), wa.width
if k ~= n then
wa.height, old_height = math.floor(wa.height / 2), wa.height
end
else else
wa.width = wa.width / 2 wa.height, old_height = math.ceil(old_height / 2), wa.height
if k ~= n then
wa.width, old_width = math.floor(wa.width / 2), wa.width
end end
end end
if k % 4 == 0 and _spiral then if k % 4 == 0 and _spiral then
wa.x = wa.x - wa.width wa.x = wa.x - wa.width
elseif k % 2 == 0 or elseif k % 2 == 0 then
(k % 4 == 3 and k < n and _spiral) then wa.x = wa.x + old_width
wa.x = wa.x + wa.width elseif k % 4 == 3 and k < n and _spiral then
wa.x = wa.x + math.ceil(old_width / 2)
end end
if k % 4 == 1 and k ~= 1 and _spiral then if k % 4 == 1 and k ~= 1 and _spiral then
wa.y = wa.y - wa.height wa.y = wa.y - wa.height
elseif k % 2 == 1 and k ~= 1 or elseif k % 2 == 1 and k ~= 1 then
(k % 4 == 0 and k < n and _spiral) then wa.y = wa.y + old_height
wa.y = wa.y + wa.height elseif k % 4 == 0 and k < n and _spiral then
wa.y = wa.y + math.ceil(old_height / 2)
end end
local g = { local g = {