Feed in region dependent tag data for nested layouts.

This commit is contained in:
Xinhao Yuan 2021-02-15 10:29:24 -05:00
parent 82bea05e26
commit 79cae17233
2 changed files with 59 additions and 36 deletions

View File

@ -136,6 +136,7 @@ function module.create(args_or_name, editor, default_cmd)
args.default_cmd = args.default_cmd or default_cmd or global_default_cmd args.default_cmd = args.default_cmd or default_cmd or global_default_cmd
args.persistent = args.persistent == nil or args.persistent args.persistent = args.persistent == nil or args.persistent
local layout = {}
local instances = {} local instances = {}
local function get_instance_info(tag) local function get_instance_info(tag)
@ -146,8 +147,10 @@ function module.create(args_or_name, editor, default_cmd)
local name, persistent = get_instance_info(tag) local name, persistent = get_instance_info(tag)
if instances[name] == nil then if instances[name] == nil then
instances[name] = { instances[name] = {
layout = layout,
cmd = persistent and args.editor.get_last_cmd(name) or nil, cmd = persistent and args.editor.get_last_cmd(name) or nil,
regions_cache = {}, regions_cache = {},
tag_data = {},
} }
if instances[name].cmd == nil then if instances[name].cmd == nil then
instances[name].cmd = args.default_cmd instances[name].cmd = args.default_cmd
@ -180,24 +183,32 @@ function module.create(args_or_name, editor, default_cmd)
local useless_gap = p.useless_gap local useless_gap = p.useless_gap
local wa = get_screen(p.screen).workarea -- get the real workarea without the gap (instead of p.workarea) local wa = get_screen(p.screen).workarea -- get the real workarea without the gap (instead of p.workarea)
local cls = p.clients local cls = p.clients
local regions, draft_mode = get_regions(wa, get_screen(p.screen).selected_tag) local tag = get_screen(p.screen).selected_tag
local instance = get_instance_(tag)
local regions, draft_mode = get_regions(wa, tag)
if #regions == 0 then return end if #regions == 0 then return end
local nested_clients = {} local nested_clients = {}
for _, c in ipairs(cls) do
if c.machi == nil then
c.machi = setmetatable({}, {__mode = "v"})
end
end
if draft_mode then if draft_mode then
for i, c in ipairs(cls) do for i, c in ipairs(cls) do
if c.floating or c.immobilized then if c.floating or c.immobilized then
log(DEBUG, "Ignore client " .. tostring(c)) log(DEBUG, "Ignore client " .. tostring(c))
else else
local skip = false local skip = false
if c.machi_lu ~= nil and c.machi_rd ~= nil and if c.machi.lu ~= nil and c.machi.rd ~= nil and
c.machi_lu <= #regions and c.machi_rd <= #regions c.machi.lu <= #regions and c.machi.rd <= #regions
then then
if regions[c.machi_lu].x == c.x and if regions[c.machi.lu].x == c.x and
regions[c.machi_lu].y == c.y and regions[c.machi.lu].y == c.y and
regions[c.machi_rd].x + regions[c.machi_rd].width - c.border_width * 2 == c.x + c.width and regions[c.machi.rd].x + regions[c.machi.rd].width - c.border_width * 2 == c.x + c.width and
regions[c.machi_rd].y + regions[c.machi_rd].height - c.border_width * 2 == c.y + c.height regions[c.machi.rd].y + regions[c.machi.rd].height - c.border_width * 2 == c.y + c.height
then then
skip = true skip = true
end end
@ -216,7 +227,8 @@ function module.create(args_or_name, editor, default_cmd)
end end
if lu ~= nil and rd ~= nil then if lu ~= nil and rd ~= nil then
c.machi_lu, c.machi_rd = lu, rd c.machi.instance = instance
c.machi.region, c.machi.lu, c.machi.rd = nil, lu, rd
p.geometries[c] = {} p.geometries[c] = {}
module.set_geometry(p.geometries[c], regions[lu], regions[rd], useless_gap, 0) module.set_geometry(p.geometries[c], regions[lu], regions[rd], useless_gap, 0)
end end
@ -227,17 +239,18 @@ function module.create(args_or_name, editor, default_cmd)
if c.floating or c.immobilized then if c.floating or c.immobilized then
log(DEBUG, "Ignore client " .. tostring(c)) log(DEBUG, "Ignore client " .. tostring(c))
else else
if c.machi_region ~= nil and if c.machi.region ~= nil and
regions[c.machi_region].layout == nil and regions[c.machi.region].layout == nil and
regions[c.machi_region].x == c.x and regions[c.machi.region].x == c.x and
regions[c.machi_region].y == c.y and regions[c.machi.region].y == c.y and
regions[c.machi_region].width - c.border_width * 2 == c.width and regions[c.machi.region].width - c.border_width * 2 == c.width and
regions[c.machi_region].height - c.border_width * 2 == c.height regions[c.machi.region].height - c.border_width * 2 == c.height
then then
else else
log(DEBUG, "Compute regions for " .. (c.name or ("<untitled:" .. tostring(c) .. ">"))) log(DEBUG, "Compute regions for " .. (c.name or ("<untitled:" .. tostring(c) .. ">")))
local region = find_region(c, regions) local region = find_region(c, regions)
c.machi_region = region c.machi.instance = instance
c.machi.region, c.machi.lu, c.machi.rd = region, nil, nil
p.geometries[c] = {} p.geometries[c] = {}
if regions[region].layout ~= nil then if regions[region].layout ~= nil then
local clients = nested_clients[region] local clients = nested_clients[region]
@ -251,11 +264,22 @@ function module.create(args_or_name, editor, default_cmd)
end end
for region, clients in pairs(nested_clients) do for region, clients in pairs(nested_clients) do
local nested_params = { if instance.tag_data[region] == nil then
tags = { -- TODO: Make the default more flexible.
-- Any tag properties to fake? instance.tag_data[region] = {
column_count = 1,
master_count = 1,
master_fill_policy = "expand",
useless_gap = 0, useless_gap = 0,
}, master_width_factor = 0.5,
_private = {
awful_tag_properties = {
},
},
}
end
local nested_params = {
tag = instance.tag_data[region],
screen = p.screen, screen = p.screen,
clients = clients, clients = clients,
padding = 0, padding = 0,
@ -325,8 +349,8 @@ function module.create(args_or_name, editor, default_cmd)
end end
if lu ~= nil and rd ~= nil then if lu ~= nil and rd ~= nil then
c.machi_lu = lu c.machi.lu = lu
c.machi_rd = rd c.machi.rd = rd
module.set_geometry(c, regions[lu], regions[rd], 0, c.border_width) module.set_geometry(c, regions[lu], regions[rd], 0, c.border_width)
end end
end end
@ -351,21 +375,20 @@ function module.create(args_or_name, editor, default_cmd)
end end
end end
if c.machi_region ~= choice then if c.machi.region ~= choice then
c.machi_region = choice c.machi.region = choice
module.set_geometry(c, regions[choice], regions[choice], 0, c.border_width) module.set_geometry(c, regions[choice], regions[choice], 0, c.border_width)
end end
end end
end end
return { layout.name = "machi"
name = "machi", layout.arrange = arrange
arrange = arrange, layout.resize_handler = resize_handler
resize_handler = resize_handler, layout.machi_get_instance_info = get_instance_info
machi_get_instance_info = get_instance_info, layout.machi_set_cmd = set_cmd
machi_set_cmd = set_cmd, layout.machi_get_regions = get_regions
machi_get_regions = get_regions, return layout
}
end end
return module return module

View File

@ -391,8 +391,8 @@ function module.start(c, exit_keys)
tablist = nil tablist = nil
if c and ctrl and draft_mode then if c and ctrl and draft_mode then
local lu = c.machi_lu local lu = c.machi.lu
local rd = c.machi_rd local rd = c.machi.rd
if shift then if shift then
lu = choice lu = choice
@ -419,8 +419,8 @@ function module.start(c, exit_keys)
c.y = min(c.y, regions[rd].y) c.y = min(c.y, regions[rd].y)
machi.layout.set_geometry(c, nil, regions[rd], 0, c.border_width) machi.layout.set_geometry(c, nil, regions[rd], 0, c.border_width)
end end
c.machi_lu = lu c.machi.lu = lu
c.machi_rd = rd c.machi.rd = rd
c:emit_signal("request::activate", "mouse.move", {raise=false}) c:emit_signal("request::activate", "mouse.move", {raise=false})
c:raise() c:raise()
@ -432,7 +432,7 @@ function module.start(c, exit_keys)
c.y = regions[choice].y c.y = regions[choice].y
else else
machi.layout.set_geometry(c, regions[choice], regions[choice], 0, c.border_width) machi.layout.set_geometry(c, regions[choice], regions[choice], 0, c.border_width)
c.machi_region = choice c.machi.region = choice
end end
c:emit_signal("request::activate", "mouse.move", {raise=false}) c:emit_signal("request::activate", "mouse.move", {raise=false})
c:raise() c:raise()