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

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