bling/layout/centered.lua

81 lines
2.4 KiB
Lua
Raw Normal View History

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 nmaster = math.min(t.master_count, #p.clients)
local nslaves = #p.clients - nmaster
local master_area_width = area.width * t.master_width_factor
if t.master_count == 0 then master_area_width = 0 end
local slave_width = 0.5 * (area.width - master_area_width)
local master_area_x = area.x + slave_width
2020-10-19 17:25:05 +02:00
-- Special case: few slaves -> make masters take more space - unless requested otherwise!
if nslaves < 2 and t.master_fill_policy ~= "master_width_factor" and
t.centered_layout_master_fill_policy ~= "master_width_factor" then
master_area_x = area.x
2020-10-19 17:25:05 +02:00
if nslaves == 1 then
slave_width = area.width - master_area_width
else
master_area_width = area.width
end
2021-08-27 20:01:22 +02:00
end
2020-10-19 17:25:05 +02:00
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
local number_of_left_sided_slaves = math.floor(nslaves / 2)
local number_of_right_sided_slaves = nslaves - number_of_left_sided_slaves
local left_iterator = 0
local right_iterator = 0
for idx = 1, nslaves do
2021-08-27 20:01:22 +02:00
local c = p.clients[idx + nmaster]
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_width,
2021-08-27 20:01:22 +02:00
height = area.height / number_of_left_sided_slaves,
}
left_iterator = left_iterator + 1
else
g = {
x = master_area_x + master_area_width,
2021-08-27 20:01:22 +02:00
y = area.y
+ right_iterator
* (area.height / number_of_right_sided_slaves),
width = slave_width,
2021-08-27 20:01:22 +02:00
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
return mylayout