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

maildir: turned into an abase example
[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 floor  = math.floor
12 local screen = screen
13
14 local cascade = {
15     name     = "cascade",
16     nmaster  = 0,
17     offset_x = 32,
18     offset_y = 8,
19     tile     = {
20         name          = "cascadetile",
21         nmaster       = 0,
22         ncol          = 0,
23         mwfact        = 0,
24         offset_x      = 5,
25         offset_y      = 32,
26         extra_padding = 0
27     }
28 }
29
30 local function do_cascade(p, tiling)
31     local t = p.tag or screen[p.screen].selected_tag
32     local wa = p.workarea
33     local cls = p.clients
34
35     if #cls == 0 then return end
36
37     if not tiling then
38         -- Cascade windows.
39
40         local num_c
41         if cascade.nmaster > 0 then
42             num_c = cascade.nmaster
43         else
44             num_c = t.master_count
45         end
46
47         -- Opening a new window will usually force all existing windows to
48         -- get resized. This wastes a lot of CPU time. So let's set a lower
49         -- bound to "how_many": This wastes a little screen space but you'll
50         -- get a much better user experience.
51         local how_many = (#cls >= num_c and #cls) or num_c
52
53         local current_offset_x = cascade.offset_x * (how_many - 1)
54         local current_offset_y = cascade.offset_y * (how_many - 1)
55
56         -- Iterate.
57         for i = 1,#cls,1 do
58             local c = cls[i]
59             local g = {}
60
61             g.x      = wa.x + (how_many - i) * cascade.offset_x
62             g.y      = wa.y + (i - 1) * cascade.offset_y
63             g.width  = wa.width - current_offset_x
64             g.height = wa.height - current_offset_y
65
66             if g.width  < 1 then g.width  = 1 end
67             if g.height < 1 then g.height = 1 end
68
69             p.geometries[c] = g
70         end
71     else
72         -- Layout with one fixed column meant for a master window. Its
73         -- width is calculated according to mwfact. Other clients are
74         -- cascaded or "tabbed" in a slave column on the right.
75
76         --         (1)                 (2)                 (3)                 (4)
77         --   +----------+---+    +----------+---+    +----------+---+    +----------+---+
78         --   |          |   |    |          | 3 |    |          | 4 |    |         +---+|
79         --   |          |   | -> |          |   | -> |         +---++ -> |        +---+|+
80         --   |  1       | 2 |    |  1      +---++    |  1      | 3 ||    |  1    +---+|+|
81         --   |          |   |    |         | 2 ||    |        +---++|    |      +---+|+ |
82         --   |          |   |    |         |   ||    |        | 2 | |    |      | 2 |+  |
83         --   +----------+---+    +---------+---++    +--------+---+-+    +------+---+---+
84
85         local mwfact
86         if cascade.tile.mwfact > 0 then
87             mwfact = cascade.tile.mwfact
88         else
89             mwfact = t.master_width_factor
90         end
91
92         -- Make slave windows overlap main window? Do this if ncol is 1.
93         local overlap_main
94         if cascade.tile.ncol > 0 then
95             overlap_main = cascade.tile.ncol
96         else
97             overlap_main = t.column_count
98         end
99
100         -- Minimum space for slave windows? See cascade.tile.lua.
101         local num_c
102         if cascade.tile.nmaster > 0 then
103             num_c = cascade.tile.nmaster
104         else
105             num_c = t.master_count
106         end
107
108         local how_many = (#cls - 1 >= num_c and (#cls - 1)) or num_c
109
110         local current_offset_x = cascade.tile.offset_x * (how_many - 1)
111         local current_offset_y = cascade.tile.offset_y * (how_many - 1)
112
113         if #cls <= 0 then return end
114
115         -- Main column, fixed width and height.
116         local c = cls[1]
117         local g = {}
118         -- Rounding is necessary to prevent the rendered size of slavewid
119         -- from being 1 pixel off when the result is not an integer.
120         local mainwid = floor(wa.width * mwfact)
121         local slavewid = wa.width - mainwid
122
123         if overlap_main == 1 then
124             g.width = wa.width
125
126             -- The size of the main window may be reduced a little bit.
127             -- This allows you to see if there are any windows below the
128             -- main window.
129             -- This only makes sense, though, if the main window is
130             -- overlapping everything else.
131             g.width = g.width - cascade.tile.extra_padding
132         else
133             g.width = mainwid
134         end
135
136         g.height = wa.height
137         g.x = wa.x
138         g.y = wa.y
139
140         if g.width < 1  then g.width  = 1 end
141         if g.height < 1 then g.height = 1 end
142
143         p.geometries[c] = g
144
145         -- Remaining clients stacked in slave column, new ones on top.
146         if #cls <= 1 then return end
147         for i = 2,#cls do
148             c = cls[i]
149             g = {}
150
151             g.width  = slavewid - current_offset_x
152             g.height = wa.height - current_offset_y
153
154             g.x = wa.x + mainwid + (how_many - (i - 1)) * cascade.tile.offset_x
155             g.y = wa.y + (i - 2) * cascade.tile.offset_y
156
157             if g.width < 1  then g.width  = 1 end
158             if g.height < 1 then g.height = 1 end
159
160             p.geometries[c] = g
161         end
162     end
163 end
164
165 function cascade.tile.arrange(p)
166     return do_cascade(p, true)
167 end
168
169 function cascade.arrange(p)
170     return do_cascade(p, false)
171 end
172
173 return cascade