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
7 * (c) 2009 Donald Ephraim Curtis
8 * (c) 2008 Julien Danjolu
12 local tag = require("awful.tag")
13 local beautiful = require("beautiful")
15 local math = { floor = math.floor,
19 local tonumber = tonumber
21 local uselesstile = {}
23 -- Transformation functions
24 local function flip(canvas, geometry)
27 x = 2 * canvas.x + canvas.width - geometry.x - geometry.width,
29 width = geometry.width,
30 height = geometry.height
34 local function swap(geometry)
35 return { x = geometry.y, y = geometry.x, width = geometry.height, height = geometry.width }
38 -- Find geometry for column/row tiling
39 local function cut_area(wa, total, index, is_horizontal)
40 local wa = is_horizontal and swap(wa) or wa
41 local height = wa.height / total
45 y = wa.y + (index - 1) * height,
50 if is_horizontal then area = swap(area) end
55 -- Client geometry correction depending on useless gap and window border
56 local function size_correction(c, geometry, useless_gap)
57 geometry.width = math.max(geometry.width - 2 * c.border_width - useless_gap, 1)
58 geometry.height = math.max(geometry.height - 2 * c.border_width - useless_gap, 1)
59 geometry.x = geometry.x + useless_gap / 2
60 geometry.y = geometry.y + useless_gap / 2
63 -- Tile group of clients in given area
64 -- @canvas need for proper transformation only
65 local function tile_column(canvas, area, list, useless_gap, transformation)
66 for i, c in ipairs(list) do
67 local g = cut_area(area, #list, i)
69 -- swap workarea dimensions
70 if transformation.flip then g = flip(canvas, g) end
71 if transformation.swap then g = swap(g) end
73 -- useless gap and border correction
74 size_correction(c, g, useless_gap)
81 local function tile(p, orientation)
84 local useless_gap = beautiful.useless_gap_width or 0
85 local global_border = beautiful.global_border_width or 0
90 local t = tag.selected(p.screen)
92 -- Nothing to tile here
93 if #cls == 0 then return end
96 local nmaster = math.min(tag.getnmaster(t), #cls)
97 local mwfact = tag.getmwfact(t)
101 elseif nmaster == #cls then
105 -- Workarea size correction depending on useless gap and global border
106 wa.height = wa.height - 2 * global_border - useless_gap
107 wa.width = wa.width - 2 * global_border - useless_gap
108 wa.x = wa.x + useless_gap / 2 + global_border
109 wa.y = wa.y + useless_gap / 2 + global_border
111 -- Find which transformation we need for given orientation
112 local transformation = {
113 swap = orientation == 'top' or orientation == 'bottom',
114 flip = orientation == 'left' or orientation == 'top'
117 -- Swap workarea dimensions if orientation vertical
118 if transformation.swap then wa = swap(wa) end
120 -- Split master and other windows
121 local cls_master, cls_other = {}, {}
123 for i, c in ipairs(cls) do
125 table.insert(cls_master, c)
127 table.insert(cls_other, c)
131 -- Tile master windows
132 local master_area = {
135 width = nmaster > 0 and wa.width * mwfact or 0,
139 tile_column(wa, master_area, cls_master, useless_gap, transformation)
141 -- Tile other windows
143 x = wa.x + master_area.width,
145 width = wa.width - master_area.width,
149 -- get column number for other windows
150 local ncol = math.min(tag.getncol(t), #cls_other)
152 -- split other windows to column groups
153 local last_small_column = ncol - #cls_other % ncol
154 local rows_min = math.floor(#cls_other / ncol)
156 local client_index = 1
158 local position = transformation.flip and ncol - i + 1 or i
159 local rows = i <= last_small_column and rows_min or rows_min + 1
163 table.insert(column, cls_other[client_index])
164 client_index = client_index + 1
168 local column_area = cut_area(other_area, ncol, position, true)
169 tile_column(wa, column_area, column, useless_gap, transformation)
173 -- Layout constructor
174 local function construct_layout(name, orientation)
177 -- @p screen number to tile
178 arrange = function(p) return tile(p, orientation) end
182 -- Build layouts with different tile direction
183 uselesstile.right = construct_layout("uselesstile", "right")
184 uselesstile.left = construct_layout("uselesstileleft", "left")
185 uselesstile.bottom = construct_layout("uselesstilebottom", "bottom")
186 uselesstile.top = construct_layout("uselesstiletop", "top")
189 uselesstile.arrange = uselesstile.right.arrange
190 uselesstile.name = uselesstile.right.name