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

layout.centerwork: improved code
[etc/awesome.git] / layout / centerwork.lua
1 --[[
2
3      Licensed under GNU General Public License v2
4       * (c) 2016,      Henrik Antonsson
5       * (c) 2015,      Joerg Jaspert
6       * (c) 2014,      projektile
7       * (c) 2013,      Luca CPZ
8       * (c) 2010-2012, Peter Hofmann
9
10 --]]
11
12 local floor, max, screen = math.floor, math.max, screen
13
14 local centerwork = {
15     name       = "centerwork",
16     horizontal = { name = "centerworkh" }
17 }
18
19 local function arrange(p, layout)
20     local t   = p.tag or screen[p.screen].selected_tag
21     local wa  = p.workarea
22     local cls = p.clients
23
24     if #cls == 0 then return end
25
26     local c, g = cls[1], {}
27
28     -- Main column, fixed width and height
29     local mwfact          = t.master_width_factor
30     local mainhei         = floor(wa.height * mwfact)
31     local mainwid         = floor(wa.width * mwfact)
32     local slavewid        = wa.width - mainwid
33     local slaveLwid       = floor(slavewid / 2)
34     local slaveRwid       = slavewid - slaveLwid
35     local slavehei        = wa.height - mainhei
36     local slaveThei       = floor(slavehei / 2)
37     local slaveBhei       = slavehei - slaveThei
38     local nbrFirstSlaves  = floor(#cls / 2)
39     local nbrSecondSlaves = floor((#cls - 1) / 2)
40
41     local slaveFirstDim, slaveSecondDim = 0, 0
42
43     if layout.name == "centerwork" then -- vertical
44         if nbrFirstSlaves  > 0 then slaveFirstDim  = floor(wa.height / nbrFirstSlaves) end
45         if nbrSecondSlaves > 0 then slaveSecondDim = floor(wa.height / nbrSecondSlaves) end
46
47         g.height = wa.height
48         g.width  = mainwid
49
50         g.x = wa.x + slaveLwid
51         g.y = wa.y
52     else -- horizontal
53         if nbrFirstSlaves  > 0 then slaveFirstDim  = floor(wa.width / nbrFirstSlaves) end
54         if nbrSecondSlaves > 0 then slaveSecondDim = floor(wa.width / nbrSecondSlaves) end
55
56         g.height  = mainhei
57         g.width = wa.width
58
59         g.x = wa.x
60         g.y = wa.y + slaveThei
61     end
62
63     g.width  = max(g.width, 1)
64     g.height = max(g.height, 1)
65
66     p.geometries[c] = g
67
68     -- Auxiliary clients
69     if #cls <= 1 then return end
70     for i = 2, #cls do
71         local c, g = cls[i], {}
72         local idxChecker, dimToAssign
73
74         local rowIndex = floor(i/2)
75
76         if layout.name == "centerwork" then
77             if i % 2 == 0 then -- left slave
78                 g.x     = wa.x
79                 g.y     = wa.y + (rowIndex - 1) * slaveFirstDim
80                 g.width = slaveLwid
81
82                 idxChecker, dimToAssign = nbrFirstSlaves, slaveFirstDim
83             else -- right slave
84                 g.x     = wa.x + slaveLwid + mainwid
85                 g.y     = wa.y + (rowIndex - 1) * slaveSecondDim
86                 g.width = slaveRwid
87
88                 idxChecker, dimToAssign = nbrSecondSlaves, slaveSecondDim
89             end
90
91             -- if last slave in row, use remaining space for it
92             if rowIndex == idxChecker then
93                 g.height = wa.y + wa.height - g.y
94             else
95                 g.height = dimToAssign
96             end
97         else
98             if i % 2 == 0 then -- top slave
99                 g.x      = wa.x + (rowIndex - 1) * slaveFirstDim
100                 g.y      = wa.y
101                 g.height = slaveThei
102
103                 idxChecker, dimToAssign = nbrFirstSlaves, slaveFirstDim
104             else -- bottom slave
105                 g.x      = wa.x + (rowIndex - 1) * slaveSecondDim
106                 g.y      = wa.y + slaveThei + mainhei
107                 g.height = slaveBhei
108
109                 idxChecker, dimToAssign = nbrSecondSlaves, slaveSecondDim
110             end
111
112             -- if last slave in row, use remaining space for it
113             if rowIndex == idxChecker then
114                 g.width = wa.x + wa.width - g.x
115             else
116                 g.width = dimToAssign
117             end
118         end
119
120         g.width  = max(g.width, 1)
121         g.height = max(g.height, 1)
122
123         p.geometries[c] = g
124     end
125 end
126
127 function centerwork.arrange(p)
128     return arrange(p, centerwork)
129 end
130
131 function centerwork.horizontal.arrange(p)
132     return arrange(p, centerwork.horizontal)
133 end
134
135 return centerwork