diff --git a/Configs/.local/lib/hyde/keybinds/hint-hyprland.py b/Configs/.local/lib/hyde/keybinds/hint-hyprland.py index 27c5d31fbc..31ebc7b097 100755 --- a/Configs/.local/lib/hyde/keybinds/hint-hyprland.py +++ b/Configs/.local/lib/hyde/keybinds/hint-hyprland.py @@ -7,28 +7,78 @@ import time +def parse_bool(value): + """Parse boolean values accepting both string ('true'/'false') and numeric (1/0) forms.""" + return value.lower() in {"1", "true"} + + def get_hyprctl_binds(): - while True: + try: + result = subprocess.run( + ["hyprctl", "binds", "-j"], capture_output=True, text=True, check=True, timeout=5 + ) try: - result = subprocess.run( - ["hyprctl", "binds", "-j"], capture_output=True, text=True, check=True - ) - while result.returncode != 0: - print("Waiting for hyprctl command to succeed...") - time.sleep(1) - result = subprocess.run( - ["hyprctl", "binds", "-j"], - capture_output=True, - text=True, - check=True, - ) binds = json.loads(result.stdout) return binds - except subprocess.CalledProcessError as e: - print(f"Error executing hyprctl: {e}") - return None except json.JSONDecodeError: - time.sleep(1) + pass + except (subprocess.CalledProcessError, subprocess.TimeoutExpired): + pass + + try: + result = subprocess.run( + ["hyprctl", "binds"], capture_output=True, text=True, check=True, timeout=5 + ) + binds = [] + current = {} + for line in result.stdout.strip().split("\n"): + line = line.strip() + if line.startswith("bind"): + if current: + binds.append(current) + current = {} + elif ":" in line: + key, _, value = line.partition(":") + key = key.strip() + value = value.strip() + if key == "modmask": + current["modmask"] = int(value) if value.isdigit() else 0 + elif key == "submap": + current["submap"] = value + elif key == "key": + current["key"] = value + elif key == "keycode": + try: + current["keycode"] = int(value) + except ValueError: + current["keycode"] = 0 + elif key == "catchall": + current["catch_all"] = parse_bool(value) + elif key == "description": + current["description"] = value + current["has_description"] = bool(value) + elif key == "dispatcher": + current["dispatcher"] = value + elif key == "arg": + current["arg"] = value + elif key == "repeat": + current["repeat"] = parse_bool(value) + elif key == "locked": + current["locked"] = parse_bool(value) + elif key == "mouse": + current["mouse"] = parse_bool(value) + elif key == "release": + current["release"] = parse_bool(value) + elif key == "non_consuming": + current["non_consuming"] = parse_bool(value) + elif key == "allow_input_capture": + current["allow_input_capture"] = parse_bool(value) + if current: + binds.append(current) + return binds if binds else None + except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e: + print(f"Error executing hyprctl: {e}") + return None def parse_description(description): diff --git a/Configs/.local/lib/hyde/keybinds_hint.sh b/Configs/.local/lib/hyde/keybinds_hint.sh index bfd78342bc..2b224f2afa 100755 --- a/Configs/.local/lib/hyde/keybinds_hint.sh +++ b/Configs/.local/lib/hyde/keybinds_hint.sh @@ -58,7 +58,7 @@ dispatch=$(awk -F ':::' '{print $2}' <<< "$selected" | xargs) arg=$(awk -F ':::' '{print $3}' <<< "$selected" | xargs) repeat=$(awk -F ':::' '{print $4}' <<< "$selected" | xargs) RUN() { - case "$(eval "hyprctl dispatch '$dispatch' '$arg'")" in *"Not enough arguments"*) exec $0 ;; esac + case "$(eval "hyprctl dispatch '$dispatch' '$arg'")" in *"Not enough arguments"*) exit 0 ;; esac } if [ -n "$dispatch" ] && [ "$(echo "$dispatch" | wc -l)" -eq 1 ]; then if [ "$repeat" = repeat ]; then @@ -74,5 +74,5 @@ if [ -n "$dispatch" ] && [ "$(echo "$dispatch" | wc -l)" -eq 1 ]; then RUN fi else - exec $0 + exit 0 fi