Fixed window gaps in the "fair" tiling mode.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Josh Komoroske 2012-11-05 18:57:59 -05:00 committed by Uli Schlachter
parent 265060f1f7
commit 8e35e1a6a9
1 changed files with 51 additions and 31 deletions

View File

@ -1,6 +1,6 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
-- @author Julien Danjou &lt;julien@danjou.info&gt; -- @author Josh Komoroske
-- @copyright 2008 Julien Danjou -- @copyright 2012 Josh Komoroske
-- @release @AWESOME_VERSION@ -- @release @AWESOME_VERSION@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
@ -16,46 +16,66 @@ local function do_fair(p, orientation)
local wa = p.workarea local wa = p.workarea
local cls = p.clients local cls = p.clients
-- Swap workarea dimensions, if our orientation is "east"
if orientation == 'east' then
wa.width, wa.height = wa.height, wa.width
wa.x, wa.y = wa.y, wa.x
end
if #cls > 0 then if #cls > 0 then
local cells = math.ceil(math.sqrt(#cls)) local rows, cols = 0, 0
local strips = math.ceil(#cls / cells) if #cls == 2 then
rows, cols = 1, 2
else
rows = math.ceil(math.sqrt(#cls))
cols = math.ceil(#cls / rows)
end
local cell = 0
local strip = 0
for k, c in ipairs(cls) do for k, c in ipairs(cls) do
k = k - 1
local g = {} local g = {}
if ( orientation == "east" and #cls > 2 )
or ( orientation == "south" and #cls <= 2 ) then
if #cls < (strips * cells) and strip == strips - 1 then
g.width = wa.width / (cells - ((strips * cells) - #cls))
else
g.width = wa.width / cells
end
g.height = wa.height / strips
g.x = wa.x + cell * g.width local row, col = 0, 0
g.y = wa.y + strip * g.height row = k % rows
col = math.floor(k / rows)
local lrows, lcols = 0, 0
if k >= rows * cols - rows then
lrows = #cls - (rows * cols - rows)
lcols = cols
else else
if #cls < (strips * cells) and strip == strips - 1 then lrows = rows
g.height = wa.height / (cells - ((strips * cells) - #cls)) lcols = cols
else end
g.height = wa.height / cells
end if row == lrows - 1 then
g.width = wa.width / strips g.height = wa.height - math.ceil(wa.height / lrows) * row
g.y = wa.height - g.height
g.x = wa.x + strip * g.width else
g.y = wa.y + cell * g.height g.height = math.ceil(wa.height / lrows)
g.y = g.height * row
end
if col == lcols - 1 then
g.width = wa.width - math.ceil(wa.width / lcols) * col
g.x = wa.width - g.width
else
g.width = math.ceil(wa.width / lcols)
g.x = g.width * col
end end
g.width = g.width - c.border_width * 2
g.height = g.height - c.border_width * 2 g.height = g.height - c.border_width * 2
c:geometry(g) g.width = g.width - c.border_width * 2
g.y = g.y + wa.y
g.x = g.x + wa.x
cell = cell + 1 -- Swap window dimensions, if our orientation is "east"
if cell == cells then if orientation == 'east' then
cell = 0 g.width, g.height = g.height, g.width
strip = strip + 1 g.x, g.y = g.y, g.x
end end
c:geometry(g)
end end
end end
end end