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.
4 Licensed under GNU General Public License v2
5 * (c) 2014, projektile, worron
6 * (c) 2013, Luke Bonham
7 * (c) 2012, Josh Komoroske
8 * (c) 2010-2012, Peter Hofmann
12 local beautiful = require("beautiful")
14 local math = { ceil = math.ceil, sqrt = math.sqrt, floor = math.floor, max = math.max }
15 local tonumber = tonumber
17 local uselessfair = {}
19 -- Transformation functions
20 local function swap(geometry)
21 return { x = geometry.y, y = geometry.x, width = geometry.height, height = geometry.width }
24 -- Client geometry correction depending on useless gap and window border
25 local function size_correction(c, geometry, useless_gap)
26 geometry.width = math.max(geometry.width - 2 * c.border_width - useless_gap, 1)
27 geometry.height = math.max(geometry.height - 2 * c.border_width - useless_gap, 1)
28 geometry.x = geometry.x + useless_gap / 2
29 geometry.y = geometry.y + useless_gap / 2
32 -- Main tiling function
33 local function fair(p, orientation)
36 local useless_gap = beautiful.useless_gap_width or 0
37 local global_border = beautiful.global_border_width or 0
43 -- Nothing to tile here
44 if #cls == 0 then return end
46 -- Workarea size correction depending on useless gap and global border
47 wa.height = wa.height - 2 * global_border - useless_gap
48 wa.width = wa.width - 2 * global_border - useless_gap
49 wa.x = wa.x + useless_gap / 2 + global_border
50 wa.y = wa.y + useless_gap / 2 + global_border
52 -- Geometry calculation
55 local rows = math.ceil(math.sqrt(#cls))
56 local cols = math.ceil(#cls / rows)
58 for i, c in ipairs(cls) do
61 -- find tile orientation for current client and swap geometry if need
62 local need_swap = (orientation == "east" and #cls <= 2) or (orientation == "south" and #cls > 2)
63 local area = need_swap and swap(wa) or wa
66 if #cls < (cols * rows) and row == cols - 1 then
67 g.width = area.width / (rows - ((cols * rows) - #cls))
69 g.width = area.width / rows
72 g.height = area.height / cols
73 g.x = area.x + col * g.width
74 g.y = area.y + row * g.height
76 -- turn back to real if geometry was swapped
77 if need_swap then g = swap(g) end
79 -- window size correction depending on useless gap and window border
80 size_correction(c, g, useless_gap)
85 -- update tile grid coordinates
87 row = math.floor(i / rows)
92 local function construct_layout(name, direction)
95 -- @p screen The screen number to tile
96 arrange = function(p) return fair(p, direction) end
100 -- Build layouts with different tile direction
101 uselessfair.vertical = construct_layout("uselessfair", "south")
102 uselessfair.horizontal = construct_layout("uselessfairh", "east")
105 uselessfair.arrange = uselessfair.vertical.arrange
106 uselessfair.name = uselessfair.vertical.name