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

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