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

readme updated
[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)
21     if useless_gap == nil
22     then
23         useless_gap = 0
24     end
25
26     local wa = p.workarea
27     local cls = p.clients
28     local n = #cls
29
30     local static_wa = wa
31
32     for k, c in ipairs(cls) do
33         if k < n then
34             if k % 2 == 0 then
35                 wa.height = wa.height / 2
36             else
37                 wa.width = wa.width / 2
38             end
39         end
40
41         if k % 4 == 0 and spiral then
42             wa.x = wa.x - wa.width
43         elseif k % 2 == 0 or
44             (k % 4 == 3 and k < n and spiral) then
45             wa.x = wa.x + wa.width
46         end
47
48         if k % 4 == 1 and k ~= 1 and spiral then
49             wa.y = wa.y - wa.height
50         elseif k % 2 == 1 and k ~= 1 or
51             (k % 4 == 0 and k < n and spiral) then
52             wa.y = wa.y + wa.height
53         end
54
55             local wa2 = {}
56             wa2.x = wa.x
57             wa2.y = wa.y
58             wa2.height = wa.height
59             wa2.width = wa.width
60
61         -- Useless gap.
62         if useless_gap > 0
63         then
64             -- Top and left clients are shrinked by two steps and
65             -- get moved away from the border. Other clients just
66             -- get shrinked in one direction.
67
68             top = false
69             left = false
70
71             if wa2.y == static_wa.y then
72                  top = true
73             end
74
75             if wa2.x == static_wa.x then
76                  left = true
77             end
78
79             if top then
80                   wa2.height = wa2.height - 2 * useless_gap
81                   wa2.y = wa2.y + useless_gap
82             else
83                   wa2.height = wa2.height - useless_gap
84             end
85
86             if left then
87                   wa2.width = wa2.width - 2 * useless_gap
88                   wa2.x = wa2.x + useless_gap
89             else
90                   wa2.width = wa2.width - useless_gap
91             end
92         end
93         -- End of useless gap.
94
95         c:geometry(wa2)
96     end
97 end
98
99 --- Dwindle layout
100 uselesspiral.dwindle = {}
101 uselesspiral.dwindle.name = "uselessdwindle"
102 function uselesspiral.dwindle.arrange(p)
103     return spiral(p, false)
104 end
105
106 --- Spiral layout
107 uselesspiral.name = "uselesspiral"
108 function uselesspiral.arrange(p)
109     return spiral(p, true)
110 end
111
112 return uselesspiral