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

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