From c11f81cbf8b09e68adecffcc470c600f0c349fe8 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Fri, 22 May 2026 02:45:28 -0700 Subject: [PATCH] feat: improve hyprland action key labels --- dotfiles/lib/bin/hypr_rofi_action | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/dotfiles/lib/bin/hypr_rofi_action b/dotfiles/lib/bin/hypr_rofi_action index f2583e10..3cb6d7a8 100755 --- a/dotfiles/lib/bin/hypr_rofi_action +++ b/dotfiles/lib/bin/hypr_rofi_action @@ -7,6 +7,8 @@ from pathlib import Path PROMPT = "Hyprland action" +HYPER_MODIFIERS = {"SUPER", "CTRL", "ALT"} +MODIFIER_ORDER = ["SHIFT", "SUPER", "CTRL", "ALT"] def ensure_hyprland_instance(): @@ -51,6 +53,32 @@ def rofi_index(entries): return None +def display_keys(keys): + parts = [part.strip() for part in keys.split("+")] + parts = [part for part in parts if part] + modifier_counts = {} + non_modifiers = [] + + for part in parts: + canonical = part.upper() + if canonical in MODIFIER_ORDER: + modifier_counts[canonical] = modifier_counts.get(canonical, 0) + 1 + else: + non_modifiers.append(part) + + modifiers = set(modifier_counts) + if not HYPER_MODIFIERS.issubset(modifiers): + return keys + + remaining_modifiers = [ + modifier + for modifier in MODIFIER_ORDER + if modifier not in HYPER_MODIFIERS and modifier in modifiers + ] + display_parts = ["Hyper", *remaining_modifiers, *non_modifiers] + return " + ".join(display_parts) + + def notify(message): if shutil.which("notify-send"): subprocess.run(["notify-send", "Hyprland action", message], check=False) @@ -104,7 +132,7 @@ def main(): return 1 width = min(max(len(action["description"]) for action in actions), 48) - labels = [f"{action['description']:<{width}} {action['keys']}" for action in actions] + labels = [f"{action['description']:<{width}} {display_keys(action['keys'])}" for action in actions] index = rofi_index(labels) if index is None: return 0