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

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