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

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