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) 2013, Luke Bonham
6 * (c) 2010-2012, Peter Hofmann
10 local tag = require("awful.tag")
11 local beautiful = require("beautiful")
12 local math = { ceil = math.ceil,
15 local tonumber = tonumber
17 local termfair = { name = "termfair" }
19 function termfair.arrange(p)
20 -- Layout with fixed number of vertical columns (read from nmaster).
21 -- New windows align from left to right. When a row is full, a now
22 -- one above it is created. Like this:
25 -- +---+---+---+ +---+---+---+ +---+---+---+
26 -- | | | | | | | | | | | |
27 -- | 1 | | | -> | 2 | 1 | | -> | 3 | 2 | 1 | ->
28 -- | | | | | | | | | | | |
29 -- +---+---+---+ +---+---+---+ +---+---+---+
32 -- +---+---+---+ +---+---+---+ +---+---+---+
33 -- | 4 | | | | 5 | 4 | | | 6 | 5 | 4 |
34 -- +---+---+---+ -> +---+---+---+ -> +---+---+---+
35 -- | 3 | 2 | 1 | | 3 | 2 | 1 | | 3 | 2 | 1 |
36 -- +---+---+---+ +---+---+---+ +---+---+---+
38 -- A useless gap (like the dwm patch) can be defined with
39 -- beautiful.useless_gap_width.
40 local useless_gap = tonumber(beautiful.useless_gap_width) or 0
46 -- How many vertical columns?
47 local t = tag.selected(p.screen)
48 local num_x = termfair.nmaster or tag.getnmaster(t)
50 -- Do at least "desired_y" rows.
51 local desired_y = termfair.ncol or tag.getncol(t)
55 local num_y = math.max(math.ceil(#cls / num_x), desired_y)
56 local cur_num_x = num_x
59 local remaining_clients = #cls
60 local width = math.floor(wa.width / num_x)
61 local height = math.floor(wa.height / num_y)
63 -- We start the first row. Left-align by limiting the number of
65 if remaining_clients < num_x
67 cur_num_x = remaining_clients
70 -- Iterate in reversed order.
73 -- Get x and y position.
75 local this_x = cur_num_x - at_x - 1
76 local this_y = num_y - at_y - 1
80 if this_x == (num_x - 1)
82 g.width = wa.width - (num_x - 1) * width
86 if this_y == (num_y - 1)
88 g.height = wa.height - (num_y - 1) * height
92 g.x = wa.x + this_x * width
93 g.y = wa.y + this_y * height
96 -- Top and left clients are shrinked by two steps and
97 -- get moved away from the border. Other clients just
98 -- get shrinked in one direction.
101 g.width = g.width - 2 * useless_gap
102 g.x = g.x + useless_gap
104 g.width = g.width - useless_gap
109 g.height = g.height - 2 * useless_gap
110 g.y = g.y + useless_gap
112 g.height = g.height - useless_gap
116 remaining_clients = remaining_clients - 1
118 -- Next grid position.
122 -- Row full, create a new one above it.
126 -- We start a new row. Left-align.
127 if remaining_clients < num_x
129 cur_num_x = remaining_clients