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

#112: custom echo cmd added
[etc/awesome.git] / layout / cascadetile.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 local tonumber  = tonumber
14
15 local cascadetile =
16 {
17     name          = "cascadetile",
18     nmaster       = 0,
19     ncol          = 0,
20     mwfact        = 0,
21     offset_x      = 5,
22     offset_y      = 32,
23     extra_padding = 0
24 }
25
26 function cascadetile.arrange(p)
27
28     -- Layout with one fixed column meant for a master window. Its
29     -- width is calculated according to mwfact. Other clients are
30     -- cascaded or "tabbed" in a slave column on the right.
31
32     -- It's a bit hard to demonstrate the behaviour with ASCII-images...
33     --
34     --         (1)                 (2)                 (3)                 (4)
35     --   +----------+---+    +----------+---+    +----------+---+    +----------+---+
36     --   |          |   |    |          | 3 |    |          | 4 |    |         +---+|
37     --   |          |   | -> |          |   | -> |         +---++ -> |        +---+|+
38     --   |  1       | 2 |    |  1      +---++    |  1      | 3 ||    |  1    +---+|+|
39     --   |          |   |    |         | 2 ||    |        +---++|    |      +---+|+ |
40     --   |          |   |    |         |   ||    |        | 2 | |    |      | 2 |+  |
41     --   +----------+---+    +---------+---++    +--------+---+-+    +------+---+---+
42
43     -- A useless gap (like the dwm patch) can be defined with
44     -- beautiful.useless_gap_width.
45     local useless_gap = tonumber(beautiful.useless_gap_width) or 0
46     if useless_gap < 0 then useless_gap = 0 end
47
48     -- A global border can be defined with
49     -- beautiful.global_border_width
50     local global_border = tonumber(beautiful.global_border_width) or 0
51     if global_border < 0 then global_border = 0 end
52
53     -- Themes border width requires an offset
54     local bw = tonumber(beautiful.border_width) or 0
55
56     -- Screen.
57     local wa = p.workarea
58     local cls = p.clients
59
60     -- Borders are factored in.
61     wa.height = wa.height - ((global_border * 2) + (bw * 2))
62     wa.width = wa.width - ((global_border * 2) + (bw * 2))
63
64     -- Width of main column?
65     local t = tag.selected(p.screen)
66     local mwfact
67     if cascadetile.mwfact > 0
68     then
69         mwfact = cascadetile.mwfact
70     else
71         mwfact = tag.getmwfact(t)
72     end
73
74     -- Make slave windows overlap main window? Do this if ncol is 1.
75     local overlap_main
76     if cascadetile.ncol > 0
77     then
78         overlap_main = cascadetile.ncol
79     else
80         overlap_main = tag.getncol(t)
81     end
82
83     -- Minimum space for slave windows? See cascade.lua.
84     local num_c
85     if cascadetile.nmaster > 0
86     then
87         num_c = cascadetile.nmaster
88     else
89         num_c = tag.getnmaster(t)
90     end
91
92     local how_many = #cls - 1
93     if how_many < num_c
94     then
95         how_many = num_c
96     end
97     local current_offset_x = cascadetile.offset_x * (how_many - 1)
98     local current_offset_y = cascadetile.offset_y * (how_many - 1)
99
100     if #cls > 0
101     then
102         -- Main column, fixed width and height.
103         local c = cls[#cls]
104         local g = {}
105         local mainwid = wa.width * mwfact
106         local slavewid = wa.width - mainwid
107
108         if overlap_main == 1
109         then
110             g.width = wa.width
111
112             -- The size of the main window may be reduced a little bit.
113             -- This allows you to see if there are any windows below the
114             -- main window.
115             -- This only makes sense, though, if the main window is
116             -- overlapping everything else.
117             g.width = g.width - cascadetile.extra_padding
118         else
119             g.width = mainwid
120         end
121
122         g.height = wa.height
123         g.x = wa.x + global_border
124         g.y = wa.y + global_border
125         if useless_gap > 0
126         then
127             -- Reduce width once and move window to the right. Reduce
128             -- height twice, however.
129             g.width = g.width - useless_gap
130             g.height = g.height - 2 * useless_gap
131             g.x = g.x + useless_gap
132             g.y = g.y + useless_gap
133
134             -- When there's no window to the right, add an additional
135             -- gap.
136             if overlap_main == 1
137             then
138                 g.width = g.width - useless_gap
139             end
140         end
141         c:geometry(g)
142
143         -- Remaining clients stacked in slave column, new ones on top.
144         if #cls > 1
145         then
146             for i = (#cls - 1),1,-1
147             do
148                 c = cls[i]
149                 g = {}
150                 g.width = slavewid - current_offset_x
151                 g.height = wa.height - current_offset_y
152                 g.x = wa.x + mainwid + (how_many - i) * cascadetile.offset_x
153                 g.y = wa.y + (i - 1) * cascadetile.offset_y + global_border
154                 if useless_gap > 0
155                 then
156                     g.width = g.width - 2 * useless_gap
157                     g.height = g.height - 2 * useless_gap
158                     g.x = g.x + useless_gap
159                     g.y = g.y + useless_gap
160                 end
161                 c:geometry(g)
162             end
163         end
164     end
165 end
166
167 return cascadetile