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
21 -- You can set the number of columns and rows,
22 -- -- otherwise they are read from awful.tag
23 nmaster = 0, -- columns
27 function termfair.arrange(p)
28 -- Layout with fixed number of vertical columns (read from nmaster).
29 -- New windows align from left to right. When a row is full, a now
30 -- one above it is created. Like this:
33 -- +---+---+---+ +---+---+---+ +---+---+---+
34 -- | | | | | | | | | | | |
35 -- | 1 | | | -> | 2 | 1 | | -> | 3 | 2 | 1 | ->
36 -- | | | | | | | | | | | |
37 -- +---+---+---+ +---+---+---+ +---+---+---+
40 -- +---+---+---+ +---+---+---+ +---+---+---+
41 -- | 4 | | | | 5 | 4 | | | 6 | 5 | 4 |
42 -- +---+---+---+ -> +---+---+---+ -> +---+---+---+
43 -- | 3 | 2 | 1 | | 3 | 2 | 1 | | 3 | 2 | 1 |
44 -- +---+---+---+ +---+---+---+ +---+---+---+
46 -- A useless gap (like the dwm patch) can be defined with
47 -- beautiful.useless_gap_width.
48 local useless_gap = tonumber(beautiful.useless_gap_width)
58 -- How many vertical columns?
59 local t = tag.selected(p.screen)
61 if termfair.nmaster ~= 0
63 num_x = termfair.nmaster
65 num_x = tag.getnmaster(t)
68 -- Do at least "desired_y" rows.
72 desired_y = termfair.ncol
74 desired_y = tag.getncol(t)
79 local num_y = math.max(math.ceil(#cls / num_x), desired_y)
80 local cur_num_x = num_x
83 local remaining_clients = #cls
84 local width = math.floor(wa.width / num_x)
85 local height = math.floor(wa.height / num_y)
87 -- We start the first row. Left-align by limiting the number of
89 if remaining_clients < num_x
91 cur_num_x = remaining_clients
94 -- Iterate in reversed order.
97 -- Get x and y position.
99 local this_x = cur_num_x - at_x - 1
100 local this_y = num_y - at_y - 1
104 if this_x == (num_x - 1)
106 g.width = wa.width - (num_x - 1) * width
110 if this_y == (num_y - 1)
112 g.height = wa.height - (num_y - 1) * height
116 g.x = wa.x + this_x * width
117 g.y = wa.y + this_y * height
120 -- Top and left clients are shrinked by two steps and
121 -- get moved away from the border. Other clients just
122 -- get shrinked in one direction.
125 g.width = g.width - 2 * useless_gap
126 g.x = g.x + useless_gap
128 g.width = g.width - useless_gap
133 g.height = g.height - 2 * useless_gap
134 g.y = g.y + useless_gap
136 g.height = g.height - useless_gap
140 remaining_clients = remaining_clients - 1
142 -- Next grid position.
146 -- Row full, create a new one above it.
150 -- We start a new row. Left-align.
151 if remaining_clients < num_x
153 cur_num_x = remaining_clients