]> 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:

save arezzo files
[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     -- get our orientation right.
34     local wa = p.workarea
35     local cls = p.clients
36
37     wa.height = wa.height - ((global_border * 2) + (bw * 2))
38     wa.width = wa.width - ((global_border * 2) + (bw * 2))
39
40     if #cls > 0 then
41         local cells = math.ceil(math.sqrt(#cls))
42         local strips = math.ceil(#cls / cells)
43
44         local cell = 0
45         local strip = 0
46         for k, c in ipairs(cls) do
47             local g = {}
48             -- Save actual grid index for use in the useless_gap
49             -- routine.
50             local this_x = 0
51             local this_y = 0
52             if ( orientation == "east" and #cls > 2 )
53             or ( orientation == "south" and #cls <= 2 ) then
54                 if #cls < (strips * cells) and strip == strips - 1 then
55                     g.width = wa.width / (cells - ((strips * cells) - #cls))
56                 else
57                     g.width = wa.width / cells
58                 end
59                 g.height = wa.height / strips
60
61                 this_x = cell
62                 this_y = strip
63
64                 g.x = wa.x + cell * g.width + global_border
65                 g.y = wa.y + strip * g.height + global_border
66
67             else
68                 if #cls < (strips * cells) and strip == strips - 1 then
69                     g.height = wa.height / (cells - ((strips * cells) - #cls))
70                 else
71                     g.height = wa.height / cells
72                 end
73                 g.width = wa.width / strips
74
75                 this_x = strip
76                 this_y = cell
77
78                 g.x = wa.x + strip * g.width + global_border
79                 g.y = wa.y + cell * g.height + global_border
80
81             end
82
83             -- Useless gap.
84             if useless_gap > 0
85             then
86                 -- All clients tile evenly.
87                 g.width = g.width - useless_gap
88                 g.x = g.x + (useless_gap / 2)
89                 g.height = g.height - useless_gap
90                 g.y = g.y + (useless_gap / 2)
91
92             end
93             -- End of useless gap.
94
95             c:geometry(g)
96
97             cell = cell + 1
98             if cell == cells then
99                 cell = 0
100                 strip = strip + 1
101             end
102         end
103     end
104 end
105
106 --- Horizontal fair layout.
107 -- @param screen The screen to arrange.
108 uselessfair.horizontal = {}
109 uselessfair.horizontal.name = "uselessfairh"
110 function uselessfair.horizontal.arrange(p)
111     return fair(p, "east")
112 end
113
114 -- Vertical fair layout.
115 -- @param screen The screen to arrange.
116 uselessfair.name = "uselessfair"
117 function uselessfair.arrange(p)
118     return fair(p, "south")
119 end
120
121 return uselessfair