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

full dynamic tagging and wiki added
[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) or 0
22
23     local wa = p.workarea
24     local cls = p.clients
25
26     if #cls > 0 then
27         local cells = math.ceil(math.sqrt(#cls))
28         local strips = math.ceil(#cls / cells)
29
30         local cell = 0
31         local strip = 0
32         for k, c in ipairs(cls) do
33             local g = {}
34             -- Save actual grid index for use in the useless_gap
35             -- routine.
36             local this_x = 0
37             local this_y = 0
38             if ( orientation == "east" and #cls > 2 )
39             or ( orientation == "south" and #cls <= 2 ) then
40                 if #cls < (strips * cells) and strip == strips - 1 then
41                     g.width = wa.width / (cells - ((strips * cells) - #cls))
42                 else
43                     g.width = wa.width / cells
44                 end
45                 g.height = wa.height / strips
46
47                 this_x = cell
48                 this_y = strip
49
50                 g.x = wa.x + cell * g.width
51                 g.y = wa.y + strip * g.height
52
53             else
54                 if #cls < (strips * cells) and strip == strips - 1 then
55                     g.height = wa.height / (cells - ((strips * cells) - #cls))
56                 else
57                     g.height = wa.height / cells
58                 end
59                 g.width = wa.width / strips
60
61                 this_x = strip
62                 this_y = cell
63
64                 g.x = wa.x + strip * g.width
65                 g.y = wa.y + cell * g.height
66             end
67
68             -- Useless gap.
69             if useless_gap > 0
70             then
71                 -- Top and left clients are shrinked by two steps and
72                 -- get moved away from the border. Other clients just
73                 -- get shrinked in one direction.
74                 if this_x == 0
75                 then
76                     g.width = g.width - 2 * useless_gap
77                     g.x = g.x + useless_gap
78                 else
79                     g.width = g.width - useless_gap
80                 end
81
82                 if this_y == 0
83                 then
84                     g.height = g.height - 2 * useless_gap
85                     g.y = g.y + useless_gap
86                 else
87                     g.height = g.height - useless_gap 
88                 end
89             end
90             -- End of useless gap.
91
92             c:geometry(g)
93
94             cell = cell + 1
95             if cell == cells then
96                 cell = 0
97                 strip = strip + 1
98             end
99         end
100     end
101 end
102
103 --- Horizontal fair layout.
104 -- @param screen The screen to arrange.
105 uselessfair.horizontal = {}
106 uselessfair.horizontal.name = "uselessfairh"
107 function uselessfair.horizontal.arrange(p)
108     return fair(p, "east")
109 end
110
111 -- Vertical fair layout.
112 -- @param screen The screen to arrange.
113 uselessfair.name = "uselessfair"
114 function uselessfair.arrange(p)
115     return fair(p, "south")
116 end
117
118 return uselessfair