]> git.madduck.net Git - etc/awesome.git/blob - layout/termfair.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

another attempt to fix weather widget behaviour
[etc/awesome.git] / layout / termfair.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2014,      projektile                 
6       * (c) 2013,      Luke Bonham                
7       * (c) 2010-2012, Peter Hofmann              
8                                                   
9 --]]
10
11 local tag       = require("awful.tag")
12 local beautiful = require("beautiful")
13 local math      = { ceil  = math.ceil,
14                     floor = math.floor,
15                     max   = math.max }
16 local tonumber  = tonumber
17
18 local termfair  = { name = "termfair" }
19
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:
24
25     --        (1)                (2)                (3)
26     --   +---+---+---+      +---+---+---+      +---+---+---+
27     --   |   |   |   |      |   |   |   |      |   |   |   |
28     --   | 1 |   |   |  ->  | 2 | 1 |   |  ->  | 3 | 2 | 1 |  ->
29     --   |   |   |   |      |   |   |   |      |   |   |   |
30     --   +---+---+---+      +---+---+---+      +---+---+---+
31
32     --        (4)                (5)                (6)
33     --   +---+---+---+      +---+---+---+      +---+---+---+
34     --   | 4 |   |   |      | 5 | 4 |   |      | 6 | 5 | 4 |
35     --   +---+---+---+  ->  +---+---+---+  ->  +---+---+---+
36     --   | 3 | 2 | 1 |      | 3 | 2 | 1 |      | 3 | 2 | 1 |
37     --   +---+---+---+      +---+---+---+      +---+---+---+
38
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
43
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
48
49     -- Screen.
50     local wa = p.workarea
51     local cls = p.clients
52
53     -- Borders are factored in.
54     wa.height = wa.height - (global_border * 2)
55     wa.width = wa.width - (global_border * 2)
56     wa.x = wa.x + global_border
57     wa.y = wa.y + global_border
58
59     -- How many vertical columns?
60     local t = tag.selected(p.screen)
61     local num_x = termfair.nmaster or tag.getnmaster(t)
62
63     -- Do at least "desired_y" rows.
64     local desired_y = termfair.ncol or tag.getncol(t)
65
66     if #cls > 0
67     then
68         local num_y = math.max(math.ceil(#cls / num_x), desired_y)
69         local cur_num_x = num_x
70         local at_x = 0
71         local at_y = 0
72         local remaining_clients = #cls
73         local width = math.floor((wa.width - (num_x + 1)*useless_gap) / num_x)
74         local height = math.floor((wa.height - (num_y + 1)*useless_gap) / num_y)
75
76         -- We start the first row. Left-align by limiting the number of
77         -- available slots.
78         if remaining_clients < num_x
79         then
80             cur_num_x = remaining_clients
81         end
82
83         -- Iterate in reversed order.
84         for i = #cls,1,-1
85         do
86             -- Get x and y position.
87             local c = cls[i]
88             local this_x = cur_num_x - at_x - 1
89             local this_y = num_y - at_y - 1
90
91             -- Calc geometry.
92             local g = {}
93             if this_x == (num_x - 1)
94             then
95                 g.width = wa.width - (num_x - 1)*width - (num_x + 1)*useless_gap - 2*c.border_width
96             else
97                 g.width = width - 2*c.border_width
98             end
99             if this_y == (num_y - 1)
100             then
101                 g.height = wa.height - (num_y - 1)*height - (num_y + 1)*useless_gap - 2*c.border_width
102             else
103                 g.height = height - 2*c.border_width
104             end
105
106             g.x = wa.x + this_x*width
107             g.y = wa.y + this_y*height
108
109             if useless_gap > 0
110             then
111                 -- All clients tile evenly.
112                 g.x = g.x + (this_x + 1)*useless_gap
113                 g.y = g.y + (this_y + 1)*useless_gap
114
115             end
116             if g.width < 1 then g.width = 1 end
117             if g.height < 1 then g.height = 1 end
118             c:geometry(g)
119             remaining_clients = remaining_clients - 1
120
121             -- Next grid position.
122             at_x = at_x + 1
123             if at_x == num_x
124             then
125                 -- Row full, create a new one above it.
126                 at_x = 0
127                 at_y = at_y + 1
128
129                 -- We start a new row. Left-align.
130                 if remaining_clients < num_x
131                 then
132                     cur_num_x = remaining_clients
133                 end
134             end
135         end
136     end
137 end
138
139 return termfair