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

6aa6666bd85e777efb4a56885fb6f2516e48ddd6
[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
75                 gap_factor = (useless_gap / 100) * 2
76
77                 if this_x == 0
78                 then
79                     g.width = g.width - (2 + gap_factor) * useless_gap
80                     g.x = g.x + useless_gap
81                 else
82                     g.width = g.width - (1 + gap_factor) * useless_gap
83                 end
84
85                 if this_y == 0
86                 then
87                     g.height = g.height - (2 + gap_factor) * useless_gap
88                     g.y = g.y + useless_gap
89                 else
90                     g.height = g.height - (1 + gap_factor) * useless_gap
91                 end
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