]> git.madduck.net Git - etc/awesome.git/blob - layout/uselessfair.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:

058dae6660007eb15ce3feba900bb3ebf648c02d
[etc/awesome.git] / layout / uselessfair.lua
1
2 --[[
3
4      Licensed under GNU General Public License v2
5       * (c) 2014,      projektile
6       * (c) 2013,      Luke Bonham
7       * (c) 2012,      Josh Komoroske
8       * (c) 2010-2012, Peter Hofmann
9
10 --]]
11
12 local beautiful = require("beautiful")
13 local ipairs    = ipairs
14 local math      = { ceil = math.ceil, sqrt = math.sqrt }
15 local tonumber  = tonumber
16
17 local uselessfair = {}
18
19 local function fair(p, orientation)
20     -- A useless gap (like the dwm patch) can be defined with
21     -- beautiful.useless_gap_width.
22     local useless_gap = tonumber(beautiful.useless_gap_width) or 0
23     if useless_gap < 0 then useless_gap = 0 end
24
25     -- A global border can be defined with
26     -- beautiful.global_border_width.
27     local global_border = tonumber(beautiful.global_border_width) or 0
28     if global_border < 0 then global_border = 0 end
29
30     -- Themes border width requires an offset.
31     local bw = tonumber(beautiful.border_width) or 0
32
33     -- Total window size extend
34     local ext = 2 * bw + useless_gap
35
36     -- get our orientation right.
37     local wa = p.workarea
38     local cls = p.clients
39
40     wa.height = wa.height - 2 * global_border - useless_gap
41     wa.width  = wa.width -  2 * global_border - useless_gap
42     wa.x = wa.x + useless_gap + global_border
43     wa.y = wa.y + useless_gap + global_border
44
45     if #cls > 0 then
46         local cells = math.ceil(math.sqrt(#cls))
47         local strips = math.ceil(#cls / cells)
48
49         local cell = 0
50         local strip = 0
51         for k, c in ipairs(cls) do
52             local g = {}
53
54             if ( orientation == "east" and #cls > 2 )
55             or ( orientation == "south" and #cls <= 2 ) then
56                 if #cls < (strips * cells) and strip == strips - 1 then
57                     g.width = wa.width / (cells - ((strips * cells) - #cls))
58                 else
59                     g.width = wa.width / cells
60                 end
61                 g.height = wa.height / strips
62
63                 g.x = wa.x + cell * g.width
64                 g.y = wa.y + strip * g.height
65
66             else
67                 if #cls < (strips * cells) and strip == strips - 1 then
68                     g.height = wa.height / (cells - ((strips * cells) - #cls))
69                 else
70                     g.height = wa.height / cells
71                 end
72                 g.width = wa.width / strips
73
74                 g.x = wa.x + strip * g.width
75                 g.y = wa.y + cell * g.height
76
77             end
78
79             g.width = g.width - ext
80             g.height = g.height - ext
81
82             c:geometry(g)
83
84             cell = cell + 1
85             if cell == cells then
86                 cell = 0
87                 strip = strip + 1
88             end
89         end
90     end
91 end
92
93 --- Horizontal fair layout.
94 -- @param screen The screen to arrange.
95 uselessfair.horizontal = {}
96 uselessfair.horizontal.name = "uselessfairh"
97 function uselessfair.horizontal.arrange(p)
98     return fair(p, "east")
99 end
100
101 -- Vertical fair layout.
102 -- @param screen The screen to arrange.
103 uselessfair.name = "uselessfair"
104 function uselessfair.arrange(p)
105     return fair(p, "south")
106 end
107
108 return uselessfair