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

Merge branch 'master' of https://github.com/MaximeCheramy/lain into MaximeCheramy...
[etc/awesome.git] / layout / cascade.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2014,      projektile                 
6       * (c) 2013,      Luke Bonham                
7       * (c) 2010-2012, Peter Hofmann              
8                                                   
9 --]]
10
11 local tag       = require("awful.tag")
12 local beautiful = require("beautiful")
13
14 local cascade =
15 {
16     name     = "cascade",
17     nmaster  = 0,
18     offset_x = 32,
19     offset_y = 8
20 }
21
22 function cascade.arrange(p)
23
24     -- Cascade windows.
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     -- Screen.
32     local wa = p.workarea
33     local cls = p.clients
34
35     wa.height = wa.height - (global_border * 2)
36     wa.width = wa.width - (global_border * 2)
37     wa.x = wa.x + global_border
38     wa.y = wa.y + global_border
39
40     -- Opening a new window will usually force all existing windows to
41     -- get resized. This wastes a lot of CPU time. So let's set a lower
42     -- bound to "how_many": This wastes a little screen space but you'll
43     -- get a much better user experience.
44     local t = tag.selected(p.screen)
45     local num_c
46     if cascade.nmaster > 0
47     then
48         num_c = cascade.nmaster
49     else
50         num_c = tag.getnmaster(t)
51     end
52
53     local how_many = #cls
54     if how_many < num_c
55     then
56         how_many = num_c
57     end
58
59     local current_offset_x = cascade.offset_x * (how_many - 1)
60     local current_offset_y = cascade.offset_y * (how_many - 1)
61
62     -- Iterate.
63     for i = 1,#cls,1
64     do
65         local c = cls[i]
66         local g = {}
67
68         g.x = wa.x + (how_many - i) * cascade.offset_x
69         g.y = wa.y + (i - 1) * cascade.offset_y
70         g.width = wa.width - current_offset_x - 2*c.border_width
71         g.height = wa.height - current_offset_y - 2*c.border_width
72         if g.width < 1 then g.width = 1 end
73         if g.height < 1 then g.height = 1 end
74
75         c:geometry(g)
76     end
77 end
78
79 return cascade