2020-11-30 18:45:04 +01:00
|
|
|
local awful = require("awful")
|
2020-10-19 17:25:05 +02:00
|
|
|
local math = math
|
|
|
|
|
|
|
|
local mylayout = {}
|
|
|
|
|
|
|
|
mylayout.name = "centered"
|
|
|
|
|
|
|
|
function mylayout.arrange(p)
|
|
|
|
local area = p.workarea
|
|
|
|
local t = p.tag or screen[p.screen].selected_tag
|
|
|
|
local mwfact = t.master_width_factor
|
|
|
|
local nmaster = math.min(t.master_count, #p.clients)
|
|
|
|
local nslaves = #p.clients - nmaster
|
|
|
|
|
|
|
|
local master_area_width = area.width * mwfact
|
2021-08-27 20:01:22 +02:00
|
|
|
local slave_area_width = area.width - master_area_width
|
|
|
|
local master_area_x = area.x + 0.5 * slave_area_width
|
2020-10-19 17:25:05 +02:00
|
|
|
|
2021-08-27 20:01:22 +02:00
|
|
|
local number_of_left_sided_slaves = math.floor(nslaves / 2)
|
2020-10-19 17:25:05 +02:00
|
|
|
local number_of_right_sided_slaves = nslaves - number_of_left_sided_slaves
|
|
|
|
local left_iterator = 0
|
|
|
|
local right_iterator = 0
|
|
|
|
|
|
|
|
-- Special case: no maters -> rrelapse into awesomes fair layout
|
|
|
|
if t.master_count == 0 then
|
|
|
|
awful.layout.suit.fair.arrange(p)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2021-08-27 20:01:22 +02:00
|
|
|
-- Special case: one slave -> relapse into awesomes masterstack tile layout
|
2020-10-19 17:25:05 +02:00
|
|
|
if nslaves == 1 then
|
|
|
|
awful.layout.suit.tile.right.arrange(p)
|
|
|
|
return
|
2021-08-27 20:01:22 +02:00
|
|
|
end
|
2020-10-19 17:25:05 +02:00
|
|
|
|
|
|
|
-- Special case: no slaves -> fullscreen master area
|
|
|
|
if nslaves < 1 then
|
2021-08-27 20:01:22 +02:00
|
|
|
master_area_width = area.width
|
2020-10-19 17:25:05 +02:00
|
|
|
master_area_x = area.x
|
|
|
|
end
|
|
|
|
|
2021-08-27 20:01:22 +02:00
|
|
|
-- iterate through masters
|
|
|
|
for idx = 1, nmaster do
|
|
|
|
local c = p.clients[idx]
|
|
|
|
local g
|
2020-10-19 17:25:05 +02:00
|
|
|
g = {
|
2021-08-27 20:01:22 +02:00
|
|
|
x = master_area_x,
|
|
|
|
y = area.y + (nmaster - idx) * (area.height / nmaster),
|
|
|
|
width = master_area_width,
|
|
|
|
height = area.height / nmaster,
|
2020-10-19 17:25:05 +02:00
|
|
|
}
|
2021-08-27 20:01:22 +02:00
|
|
|
p.geometries[c] = g
|
|
|
|
end
|
2020-10-19 17:25:05 +02:00
|
|
|
|
2021-08-27 20:01:22 +02:00
|
|
|
-- iterate through slaves
|
|
|
|
for idx = 1, nslaves do -- idx=nmaster+1,#p.clients do
|
|
|
|
local c = p.clients[idx + nmaster]
|
2021-11-06 19:33:58 +01:00
|
|
|
local g
|
2021-08-27 20:01:22 +02:00
|
|
|
if idx % 2 == 0 then
|
|
|
|
g = {
|
|
|
|
x = area.x,
|
|
|
|
y = area.y
|
|
|
|
+ left_iterator
|
|
|
|
* (area.height / number_of_left_sided_slaves),
|
|
|
|
width = slave_area_width / 2,
|
|
|
|
height = area.height / number_of_left_sided_slaves,
|
|
|
|
}
|
|
|
|
left_iterator = left_iterator + 1
|
|
|
|
else
|
|
|
|
g = {
|
|
|
|
x = area.x + master_area_width + slave_area_width / 2,
|
|
|
|
y = area.y
|
|
|
|
+ right_iterator
|
|
|
|
* (area.height / number_of_right_sided_slaves),
|
|
|
|
width = slave_area_width / 2,
|
|
|
|
height = area.height / number_of_right_sided_slaves,
|
|
|
|
}
|
|
|
|
right_iterator = right_iterator + 1
|
|
|
|
end
|
|
|
|
p.geometries[c] = g
|
2020-10-19 17:25:05 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-06 19:33:58 +01:00
|
|
|
return mylayout
|