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

issue #11 typos fixed
[etc/awesome.git] / layout / uselesspiral.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2013,      Luke Bonham                
6       * (c) 2009       Uli Schlachter             
7       * (c) 2008       Julien Danjolu             
8                                                   
9 --]]
10
11 local beautiful = require("beautiful")
12 local ipairs    = ipairs
13 local tonumber  = tonumber
14
15 local uselesspiral = {}
16
17 local function spiral(p, spiral)
18     -- A useless gap (like the dwm patch) can be defined with
19     -- beautiful.useless_gap_width.
20     local useless_gap = tonumber(beautiful.useless_gap_width) or 0
21
22     local wa = p.workarea
23     local cls = p.clients
24     local n = #cls
25
26     local static_wa = wa
27
28     for k, c in ipairs(cls) do
29         if k < n then
30             if k % 2 == 0 then
31                 wa.height = wa.height / 2
32             else
33                 wa.width = wa.width / 2
34             end
35         end
36
37         if k % 4 == 0 and spiral then
38             wa.x = wa.x - wa.width
39         elseif k % 2 == 0 or
40             (k % 4 == 3 and k < n and spiral) then
41             wa.x = wa.x + wa.width
42         end
43
44         if k % 4 == 1 and k ~= 1 and spiral then
45             wa.y = wa.y - wa.height
46         elseif k % 2 == 1 and k ~= 1 or
47             (k % 4 == 0 and k < n and spiral) then
48             wa.y = wa.y + wa.height
49         end
50
51             local wa2 = {}
52             wa2.x = wa.x
53             wa2.y = wa.y
54             wa2.height = wa.height
55             wa2.width = wa.width
56
57         -- Useless gap.
58         if useless_gap > 0
59         then
60             -- Top and left clients are shrinked by two steps and
61             -- get moved away from the border. Other clients just
62             -- get shrinked in one direction.
63
64             top = false
65             left = false
66
67             gap_factor = (useless_gap / 100) * 2
68
69             if wa2.y == static_wa.y then
70                top = true
71             end
72
73             if wa2.x == static_wa.x then
74                left = true
75             end
76
77             if top then
78                 wa2.height = wa2.height - (2 + gap_factor) * useless_gap
79                 wa2.y = wa2.y + useless_gap
80             else
81                 wa2.height = wa2.height - (1 + gap_factor) * useless_gap
82             end
83
84             if left then
85                 wa2.width = wa2.width - (2 + gap_factor) * useless_gap
86                 wa2.x = wa2.x + useless_gap
87             else
88                 wa2.width = wa2.width - (1 + gap_factor) * useless_gap
89             end
90         end
91         -- End of useless gap.
92
93         c:geometry(wa2)
94     end
95 end
96
97 --- Dwindle layout
98 uselesspiral.dwindle = {}
99 uselesspiral.dwindle.name = "uselessdwindle"
100 function uselesspiral.dwindle.arrange(p)
101     return spiral(p, false)
102 end
103
104 --- Spiral layout
105 uselesspiral.name = "uselesspiral"
106 function uselesspiral.arrange(p)
107     return spiral(p, true)
108 end
109
110 return uselesspiral