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

refresh widget fix
[etc/awesome.git] / layout / uselessfair.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2013,      Luke Bonham                
6       * (c) 2012,      Josh Komoroske             
7       * (c) 2010-2012, Peter Hofmann              
8                                                   
9 --]]
10
11 local beautiful = require("beautiful")
12 local ipairs    = ipairs
13 local math      = { ceil = math.ceil, sqrt = math.sqrt }
14 local tonumber  = tonumber
15
16 local uselessfair = {}
17
18 local function fair(p, orientation)
19     -- A useless gap (like the dwm patch) can be defined with
20     -- beautiful.useless_gap_width.
21     local useless_gap = tonumber(beautiful.useless_gap_width)
22     if useless_gap == nil
23     then
24         useless_gap = 0
25     end
26
27     local wa = p.workarea
28     local cls = p.clients
29
30     if #cls > 0 then
31         local cells = math.ceil(math.sqrt(#cls))
32         local strips = math.ceil(#cls / cells)
33
34         local cell = 0
35         local strip = 0
36         for k, c in ipairs(cls) do
37             local g = {}
38             -- Save actual grid index for use in the useless_gap
39             -- routine.
40             local this_x = 0
41             local this_y = 0
42             if ( orientation == "east" and #cls > 2 )
43             or ( orientation == "south" and #cls <= 2 ) then
44                 if #cls < (strips * cells) and strip == strips - 1 then
45                     g.width = wa.width / (cells - ((strips * cells) - #cls))
46                 else
47                     g.width = wa.width / cells
48                 end
49                 g.height = wa.height / strips
50
51                 this_x = cell
52                 this_y = strip
53
54                 g.x = wa.x + cell * g.width
55                 g.y = wa.y + strip * g.height
56
57             else
58                 if #cls < (strips * cells) and strip == strips - 1 then
59                     g.height = wa.height / (cells - ((strips * cells) - #cls))
60                 else
61                     g.height = wa.height / cells
62                 end
63                 g.width = wa.width / strips
64
65                 this_x = strip
66                 this_y = cell
67
68                 g.x = wa.x + strip * g.width
69                 g.y = wa.y + cell * g.height
70             end
71
72             -- Useless gap.
73             if useless_gap > 0
74             then
75                 -- Top and left clients are shrinked by two steps and
76                 -- get moved away from the border. Other clients just
77                 -- get shrinked in one direction.
78                 if this_x == 0
79                 then
80                     g.width = g.width - 2 * useless_gap
81                     g.x = g.x + useless_gap
82                 else
83                     g.width = g.width - useless_gap
84                 end
85
86                 if this_y == 0
87                 then
88                     g.height = g.height - 2 * useless_gap
89                     g.y = g.y + useless_gap
90                 else
91                     g.height = g.height - useless_gap
92                 end
93             end
94             -- End of useless gap.
95
96             c:geometry(g)
97
98             cell = cell + 1
99             if cell == cells then
100                 cell = 0
101                 strip = strip + 1
102             end
103         end
104     end
105 end
106
107 --- Horizontal fair layout.
108 -- @param screen The screen to arrange.
109 uselessfair.horizontal = {}
110 uselessfair.horizontal.name = "uselessfairh"
111 function uselessfair.horizontal.arrange(p)
112     return fair(p, "east")
113 end
114
115 -- Vertical fair layout.
116 -- @param screen The screen to arrange.
117 uselessfair.name = "uselessfair"
118 function uselessfair.arrange(p)
119     return fair(p, "south")
120 end
121
122 return uselessfair