From 4bce9a71776464be22e219cbbdbaae1d925f5b50 Mon Sep 17 00:00:00 2001 From: ariasuni Date: Tue, 14 Apr 2026 22:38:35 +0200 Subject: [PATCH] Define layout label for XKB (Linux) in metadata --- kalamine/layout.py | 4 ++++ kalamine/xkb_manager.py | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/kalamine/layout.py b/kalamine/layout.py index 026bbe3..d292f85 100644 --- a/kalamine/layout.py +++ b/kalamine/layout.py @@ -38,6 +38,8 @@ def load_descriptor(file_path: Path) -> Dict: cfg = load_descriptor(layout_path) if "name" not in cfg: cfg["name"] = layout_path.stem + if not "xkb_label": + cfg["xkb_label"] = "" if "extends" in cfg: parent_path = layout_path.parent / cfg["extends"] ext = load_descriptor(parent_path) @@ -77,6 +79,7 @@ class MetaDescr: locale: str = "us" geometry: str = "ISO" description: str = "" + xkb_label: str = "" author: str = "nobody" license: str = "" version: str = "0.0.1" @@ -96,6 +99,7 @@ class SpacebarDescr: "author": "nobody", "license": "WTFPL - Do What The Fuck You Want Public License", "geometry": "ISO", + "xkb_label": "", } SPACEBAR = { diff --git a/kalamine/xkb_manager.py b/kalamine/xkb_manager.py index d66b86f..c43d5cd 100644 --- a/kalamine/xkb_manager.py +++ b/kalamine/xkb_manager.py @@ -365,12 +365,17 @@ def remove_rules_variant(variant_list: ET.Element, name: str) -> None: variant_list.remove(variant) -def add_rules_variant(variant_list: ET.Element, name: str, description: str) -> None: +def add_rules_variant(variant_list: ET.Element, name: str, description: str, xkb_label: str) -> None: """Add a item to .""" variant = ET.SubElement(variant_list, "variant") config = ET.SubElement(variant, "configItem") ET.SubElement(config, "name").text = name + if xkb_label != "": + # Set the label used notably by Fcitx5 in the systray, see: + # https://github.com/fcitx/fcitx5/issues/1555 + # Note: `shortDescription` MUST appear before `description` for the document to be valid + ET.SubElement(config, "shortDescription").text = xkb_label ET.SubElement(config, "description").text = description @@ -394,8 +399,8 @@ def update_rules(xkb_root: Path, kbd_index: KbdIndex) -> None: remove_rules_variant(vlist, name) if layout is not None: description = layout.meta["description"] - add_rules_variant(vlist, name, description) - + xkb_label = layout.meta["xkb_label"] + add_rules_variant(vlist, name, description, xkb_label) if hasattr(ET, "indent"): # Python 3.9+ ET.indent(tree)