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

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