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

Merge pull request #173 from guotsuan/master
[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     -- Screen.
54     local wa = p.workarea
55     local cls = p.clients
56
57     -- Borders are factored in.
58     wa.height = wa.height - (global_border * 2)
59     wa.width = wa.width - (global_border * 2)
60     wa.x = wa.x + global_border
61     wa.y = wa.y + global_border
62
63     -- Width of main column?
64     local t = tag.selected(p.screen)
65     local mwfact
66     if cascadetile.mwfact > 0
67     then
68         mwfact = cascadetile.mwfact
69     else
70         mwfact = tag.getmwfact(t)
71     end
72
73     -- Make slave windows overlap main window? Do this if ncol is 1.
74     local overlap_main
75     if cascadetile.ncol > 0
76     then
77         overlap_main = cascadetile.ncol
78     else
79         overlap_main = tag.getncol(t)
80     end
81
82     -- Minimum space for slave windows? See cascade.lua.
83     local num_c
84     if cascadetile.nmaster > 0
85     then
86         num_c = cascadetile.nmaster
87     else
88         num_c = tag.getnmaster(t)
89     end
90
91     local how_many = #cls - 1
92     if how_many < num_c
93     then
94         how_many = num_c
95     end
96     local current_offset_x = cascadetile.offset_x * (how_many - 1)
97     local current_offset_y = cascadetile.offset_y * (how_many - 1)
98
99     if #cls > 0
100     then
101         -- Main column, fixed width and height.
102         local c = cls[1]
103         local g = {}
104         -- Subtracting the useless_gap width from the work area width here
105         -- makes this mwfact calculation work the same as in uselesstile.
106         -- Rounding is necessary to prevent the rendered size of slavewid
107         -- from being 1 pixel off when the result is not an integer.
108         local mainwid = math.floor((wa.width - useless_gap) * mwfact)
109         local slavewid = wa.width - mainwid
110
111         if overlap_main == 1
112         then
113             g.width = wa.width - 2*c.border_width
114
115             -- The size of the main window may be reduced a little bit.
116             -- This allows you to see if there are any windows below the
117             -- main window.
118             -- This only makes sense, though, if the main window is
119             -- overlapping everything else.
120             g.width = g.width - cascadetile.extra_padding
121         else
122             g.width = mainwid - 2*c.border_width
123         end
124
125         g.height = wa.height - 2*c.border_width
126         g.x = wa.x
127         g.y = wa.y
128         if useless_gap > 0
129         then
130             -- Reduce width once and move window to the right. Reduce
131             -- height twice, however.
132             g.width = g.width - useless_gap
133             g.height = g.height - 2 * useless_gap
134             g.x = g.x + useless_gap
135             g.y = g.y + useless_gap
136
137             -- When there's no window to the right, add an additional
138             -- gap.
139             if overlap_main == 1
140             then
141                 g.width = g.width - useless_gap
142             end
143         end
144         if g.width < 1 then g.width = 1 end
145         if g.height < 1 then g.height = 1 end
146         c:geometry(g)
147
148         -- Remaining clients stacked in slave column, new ones on top.
149         if #cls > 1
150         then
151             for i = 2,#cls
152             do
153                 c = cls[i]
154                 g = {}
155                 g.width = slavewid - current_offset_x - 2*c.border_width
156                 g.height = wa.height - current_offset_y - 2*c.border_width
157                 g.x = wa.x + mainwid + (how_many - (i - 1)) * cascadetile.offset_x
158                 g.y = wa.y + (i - 2) * cascadetile.offset_y
159                 if useless_gap > 0
160                 then
161                     g.width = g.width - 2 * useless_gap
162                     g.height = g.height - 2 * useless_gap
163                     g.x = g.x + useless_gap
164                     g.y = g.y + useless_gap
165                 end
166                 if g.width < 1 then g.width = 1 end
167                 if g.height < 1 then g.height = 1 end
168                 c:geometry(g)
169             end
170         end
171     end
172 end
173
174 return cascadetile