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

Fix muted problem. To know if the sound is mute we have to check if mute == "yes...
[etc/awesome.git] / layout / centerworkd.lua
1
2 --[[
3
4      Licensed under GNU General Public License v2
5       * (c) 2016,      Henrik Antonsson
6       * (c) 2014,      projektile
7       * (c) 2013,      Luke Bonham
8       * (c) 2010-2012, Peter Hofmann
9
10      Based on centerwork.lua
11 --]]
12
13 local awful     = require("awful")
14 local beautiful = require("beautiful")
15 local tonumber  = tonumber
16 local math      = { floor = math.floor }
17
18 local centerworkd =
19 {
20     name         = "centerworkd",
21 }
22
23 function centerworkd.arrange(p)
24     -- A useless gap (like the dwm patch) can be defined with
25     -- beautiful.useless_gap_width .
26     local useless_gap = tonumber(beautiful.useless_gap_width) or 0
27
28     -- A global border can be defined with
29     -- beautiful.global_border_width
30     local global_border = tonumber(beautiful.global_border_width) or 0
31     if global_border < 0 then global_border = 0 end
32
33     -- Screen.
34     local wa = p.workarea
35     local cls = p.clients
36
37     -- Borders are factored in.
38     wa.height = wa.height - (global_border * 2)
39     wa.width = wa.width - (global_border * 2)
40     wa.x = wa.x + global_border
41     wa.y = wa.y + global_border
42
43     -- Width of main column?
44     local t = awful.tag.selected(p.screen)
45     local mwfact = awful.tag.getmwfact(t)
46
47     if #cls > 0
48     then
49         -- Main column, fixed width and height.
50         local c = cls[1]
51         local g = {}
52         local mainwid = math.floor(wa.width * mwfact)
53         local slavewid = wa.width - mainwid
54         local slaveLwid = math.floor(slavewid / 2)
55         local slaveRwid = slavewid - slaveLwid
56         local nbrLeftSlaves = math.floor(#cls / 2)
57         local nbrRightSlaves = math.floor((#cls - 1) / 2)
58
59         local slaveLeftHeight = 0
60         if nbrLeftSlaves > 0 then slaveLeftHeight = math.floor(wa.height / nbrLeftSlaves) end
61         if nbrRightSlaves > 0 then slaveRightHeight = math.floor(wa.height / nbrRightSlaves) end
62
63         g.height = wa.height - 2*useless_gap - 2*c.border_width
64         g.width = mainwid - 2*c.border_width
65         g.x = wa.x + slaveLwid
66         g.y = wa.y + useless_gap
67
68         if g.width < 1 then g.width = 1 end
69         if g.height < 1 then g.height = 1 end
70         c:geometry(g)
71
72         -- Auxiliary windows.
73         if #cls > 1
74         then
75             for i = 2,#cls
76             do
77                 c = cls[i]
78                 g = {}
79
80                 local rowIndex = math.floor(i/2)
81
82                 -- If i is even it should be placed on the left side
83                 if i % 2 == 0
84                 then
85                     -- left slave
86                     g.x = wa.x + useless_gap
87                     g.y = wa.y + useless_gap + (rowIndex-1)*slaveLeftHeight
88
89                     g.width = slaveLwid - 2*useless_gap - 2*c.border_width
90
91                     -- if last slave in left row use remaining space for that slave
92                     if rowIndex == nbrLeftSlaves
93                     then
94                         g.height = wa.y + wa.height - g.y - useless_gap - 2*c.border_width
95                     else
96                         g.height = slaveLeftHeight - useless_gap - 2*c.border_width
97                     end
98                 else
99                     -- right slave
100                     g.x = wa.x + slaveLwid + mainwid + useless_gap
101                     g.y = wa.y + useless_gap + (rowIndex-1)*slaveRightHeight
102
103                     g.width = slaveRwid - 2*useless_gap - 2*c.border_width
104
105                     -- if last slave in right row use remaining space for that slave
106                     if rowIndex == nbrRightSlaves
107                     then
108                         g.height = wa.y + wa.height - g.y - useless_gap - 2*c.border_width
109                     else
110                         g.height = slaveRightHeight - useless_gap - 2*c.border_width
111                     end
112
113                 end
114
115                 if g.width < 1 then g.width = 1 end
116                 if g.height < 1 then g.height = 1 end
117                 c:geometry(g)
118             end
119         end
120     end
121 end
122
123 return centerworkd