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

bat.lua: add notification for full charge
[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,      Luke Bonham
8       * (c) 2010-2012, Peter Hofmann
9
10 --]]
11
12 local floor  = math.floor
13 local screen = screen
14
15 local centerwork = {
16     name         = "centerwork",
17     horizontal   = { name = "centerworkh" }
18 }
19
20 local function do_centerwork(p, orientation)
21     local t = p.tag or screen[p.screen].selected_tag
22     local wa = p.workarea
23     local cls = p.clients
24
25     if #cls == 0 then return end
26
27     local c = cls[1]
28     local g = {}
29
30     -- Main column, fixed width and height.
31     local mwfact          = t.master_width_factor
32     local mainhei         = floor(wa.height * mwfact)
33     local mainwid         = floor(wa.width * mwfact)
34     local slavewid        = wa.width - mainwid
35     local slaveLwid       = floor(slavewid / 2)
36     local slaveRwid       = slavewid - slaveLwid
37     local slavehei        = wa.height - mainhei
38     local slaveThei       = floor(slavehei / 2)
39     local slaveBhei       = slavehei - slaveThei
40     local nbrFirstSlaves  = floor(#cls / 2)
41     local nbrSecondSlaves = floor((#cls - 1) / 2)
42
43     local slaveFirstDim, slaveSecondDim = 0, 0
44
45     if orientation == "vertical" then
46         if nbrFirstSlaves  > 0 then slaveFirstDim  = floor(wa.height / nbrFirstSlaves) end
47         if nbrSecondSlaves > 0 then slaveSecondDim = floor(wa.height / nbrSecondSlaves) end
48
49         g.height = wa.height
50         g.width  = mainwid
51
52         g.x = wa.x + slaveLwid
53         g.y = wa.y
54     else
55         if nbrFirstSlaves  > 0 then slaveFirstDim  = floor(wa.width / nbrFirstSlaves) end
56         if nbrSecondSlaves > 0 then slaveSecondDim = floor(wa.width / nbrSecondSlaves) end
57
58         g.height  = mainhei
59         g.width = wa.width
60
61         g.x = wa.x
62         g.y = wa.y + slaveThei
63     end
64
65     if g.width  < 1 then g.width  = 1 end
66     if g.height < 1 then g.height = 1 end
67
68     p.geometries[c] = g
69
70     -- Auxiliary windows.
71     if #cls <= 1 then return end
72     for i = 2,#cls do
73         local c = cls[i]
74         local g = {}
75
76         local rowIndex = floor(i/2)
77
78         if orientation == "vertical" then
79             if i % 2 == 0 then
80                 -- left slave
81                 g.x = wa.x
82                 g.y = wa.y + (rowIndex-1)*slaveFirstDim
83
84                 g.width = slaveLwid
85
86                 -- if last slave in left row use remaining space for that slave
87                 if rowIndex == nbrFirstSlaves then
88                     g.height = wa.y + wa.height - g.y
89                 else
90                     g.height = slaveFirstDim
91                 end
92             else
93                 -- right slave
94                 g.x = wa.x + slaveLwid + mainwid
95                 g.y = wa.y + (rowIndex-1)*slaveSecondDim
96
97                 g.width = slaveRwid
98
99                 -- if last slave in right row use remaining space for that slave
100                 if rowIndex == nbrSecondSlaves then
101                     g.height = wa.y + wa.height - g.y
102                 else
103                     g.height = slaveSecondDim
104                 end
105             end
106         else
107             if i % 2 == 0 then
108                 -- top slave
109                 g.x = wa.x + (rowIndex-1)*slaveFirstDim
110                 g.y = wa.y
111
112                 g.height = slaveThei
113
114                 -- if last slave in top row use remaining space for that slave
115                 if rowIndex == nbrFirstSlaves then
116                     g.width = wa.x + wa.width - g.x
117                 else
118                     g.width = slaveFirstDim
119                 end
120             else
121                 -- bottom slave
122                 g.x = wa.x + (rowIndex-1)*slaveSecondDim
123                 g.y = wa.y + slaveThei + mainhei
124
125                 g.height = slaveBhei
126
127                 -- if last slave in bottom row use remaining space for that slave
128                 if rowIndex == nbrSecondSlaves then
129                     g.width = wa.x + wa.width - g.x
130                 else
131                     g.width = slaveSecondDim
132                 end
133
134             end
135         end
136
137         if g.width  < 1 then g.width  = 1 end
138         if g.height < 1 then g.height = 1 end
139
140         p.geometries[c] = g
141     end
142 end
143
144
145 function centerwork.horizontal.arrange(p)
146     return do_centerwork(p, "horizontal")
147 end
148
149 function centerwork.arrange(p)
150     return do_centerwork(p, "vertical")
151 end
152
153 return centerwork