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

contrib section started\!
[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             if wa2.y == static_wa.y then
68                top = true
69             end
70
71             if wa2.x == static_wa.x then
72                left = true
73             end
74
75             if top then
76                 wa2.height = wa2.height - 2 * useless_gap
77                 wa2.y = wa2.y + useless_gap
78             else
79                 wa2.height = wa2.height - useless_gap
80             end
81
82             if left then
83                 wa2.width = wa2.width - 2 * useless_gap
84                 wa2.x = wa2.x + useless_gap
85             else
86                 wa2.width = wa2.width - useless_gap
87             end
88         end
89         -- End of useless gap.
90
91         c:geometry(wa2)
92     end
93 end
94
95 --- Dwindle layout
96 uselesspiral.dwindle = {}
97 uselesspiral.dwindle.name = "uselessdwindle"
98 function uselesspiral.dwindle.arrange(p)
99     return spiral(p, false)
100 end
101
102 --- Spiral layout
103 uselesspiral.name = "uselesspiral"
104 function uselesspiral.arrange(p)
105     return spiral(p, true)
106 end
107
108 return uselesspiral