From 946494ecf0b075e1cdace30bbb7f9e8ea8421a72 Mon Sep 17 00:00:00 2001 From: Xinhao Yuan Date: Sun, 28 Feb 2021 23:17:35 -0500 Subject: [PATCH] Let default name function depend on the icon name. --- README.md | 2 +- layout.lua | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5de4da5..1d195d9 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/layout.lua b/layout.lua index 9e81e54..16f033f 100644 --- a/layout.lua +++ b/layout.lua @@ -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