Let default name function depend on the icon name.

This commit is contained in:
Xinhao Yuan 2021-02-28 23:17:35 -05:00
parent 9f9a558b2f
commit 946494ecf0
2 changed files with 10 additions and 7 deletions

View File

@ -71,7 +71,7 @@ Use `local layout = machi.layout.create(args)` to instantiate the layout with an
- `new_placement_cb`: a callback `function(c, instance, areas, geometry)` that fits new client `c` into the areas.
This is a new and experimental feature. The interface is subject to changes.
If `name` and `name_func` are both nil a default name function will be used, which splits the state based on the tag names.
If `name` and `name_func` are both nil, a default name function will be used, which depends on the tag names, screen geometries, and `icon_name`.
The function is compatible with the previous `machi.layout.create(name, editor, default_cmd)` calls.

View File

@ -121,16 +121,16 @@ function module.set_geometry(c, area_lu, area_rd, useless_gap, border_width)
end
end
function module.default_name_func(tag)
if tag.machi_name_cache == nil then
tag.machi_name_cache =
-- TODO: the string need to be updated when its screen geometry changed.
local function get_machi_tag_string(tag)
if tag.machi_tag_string == nil then
tag.machi_tag_string =
tostring(tag.screen.geometry.width) .. "x" .. tostring(tag.screen.geometry.height) .. "+" ..
tostring(tag.screen.geometry.x) .. "+" .. tostring(tag.screen.geometry.y) .. '+' .. tag.name
end
return tag.machi_name_cache
return tag.machi_tag_string
end
function module.create(args_or_name, editor, default_cmd)
local args
if type(args_or_name) == "string" then
@ -147,7 +147,10 @@ function module.create(args_or_name, editor, default_cmd)
return nil
end
if args.name == nil and args.name_func == nil then
args.name_func = module.default_name_func
local prefix = args.icon_name and (args.icon_name.."-") or ""
args.name_func = function (tag)
return prefix..get_machi_tag_string(tag)
end
end
args.editor = args.editor or editor or machi_editor.default_editor
args.default_cmd = args.default_cmd or default_cmd or global_default_cmd