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
6 * (c) 2013, Luke Bonham
7 * (c) 2010-2012, Peter Hofmann
11 local tag = require("awful.tag")
12 local beautiful = require("beautiful")
13 local math = { ceil = math.ceil,
16 local tonumber = tonumber
18 local termfair = { name = "termfair" }
20 function termfair.arrange(p)
21 -- Layout with fixed number of vertical columns (read from nmaster).
22 -- New windows align from left to right. When a row is full, a now
23 -- one above it is created. Like this:
26 -- +---+---+---+ +---+---+---+ +---+---+---+
27 -- | | | | | | | | | | | |
28 -- | 1 | | | -> | 2 | 1 | | -> | 3 | 2 | 1 | ->
29 -- | | | | | | | | | | | |
30 -- +---+---+---+ +---+---+---+ +---+---+---+
33 -- +---+---+---+ +---+---+---+ +---+---+---+
34 -- | 4 | | | | 5 | 4 | | | 6 | 5 | 4 |
35 -- +---+---+---+ -> +---+---+---+ -> +---+---+---+
36 -- | 3 | 2 | 1 | | 3 | 2 | 1 | | 3 | 2 | 1 |
37 -- +---+---+---+ +---+---+---+ +---+---+---+
39 -- A useless gap (like the dwm patch) can be defined with
40 -- beautiful.useless_gap_width.
41 local useless_gap = tonumber(beautiful.useless_gap_width) or 0
42 if useless_gap < 0 then useless_gap = 0 end
44 -- A global border can be defined with
45 -- beautiful.global_border_width
46 local global_border = tonumber(beautiful.global_border_width) or 0
47 if global_border < 0 then global_border = 0 end
53 -- Borders are factored in.
54 wa.height = wa.height - (global_border * 2)
55 wa.width = wa.width - (global_border * 2)
57 -- How many vertical columns?
58 local t = tag.selected(p.screen)
59 local num_x = termfair.nmaster or tag.getnmaster(t)
61 -- Do at least "desired_y" rows.
62 local desired_y = termfair.ncol or tag.getncol(t)
66 local num_y = math.max(math.ceil(#cls / num_x), desired_y)
67 local cur_num_x = num_x
70 local remaining_clients = #cls
71 local width = math.floor((wa.width - (num_x + 1)*useless_gap) / num_x)
72 local height = math.floor((wa.height - (num_y + 1)*useless_gap) / num_y)
74 -- We start the first row. Left-align by limiting the number of
76 if remaining_clients < num_x
78 cur_num_x = remaining_clients
81 -- Iterate in reversed order.
84 -- Get x and y position.
86 local this_x = cur_num_x - at_x - 1
87 local this_y = num_y - at_y - 1
91 if this_x == (num_x - 1)
93 g.width = wa.width - (num_x - 1)*width - (num_x + 1)*useless_gap - 2*c.border_width
95 g.width = width - 2*c.border_width
97 if this_y == (num_y - 1)
99 g.height = wa.height - (num_y - 1)*height - (num_y + 1)*useless_gap - 2*c.border_width
101 g.height = height - 2*c.border_width
104 g.x = wa.x + this_x*width + global_border
105 g.y = wa.y + this_y*height + global_border
109 -- All clients tile evenly.
110 g.x = g.x + (this_x + 1)*useless_gap
111 g.y = g.y + (this_y + 1)*useless_gap
115 remaining_clients = remaining_clients - 1
117 -- Next grid position.
121 -- Row full, create a new one above it.
125 -- We start a new row. Left-align.
126 if remaining_clients < num_x
128 cur_num_x = remaining_clients