From 2e161911bcda384ff1f5e5a155009be1775cbefc Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Tue, 12 May 2026 07:54:56 +0200 Subject: [PATCH] qs: fix hyprland overrides (game mode, anti flashbang) --- .../hypr/hyprland/shellOverrides/main.conf | 0 .../hypr/hyprland/shellOverrides/main.lua | 3 +- .../ii/scripts/hyprland/hyprconfigurator.py | 41 ++++++++++++++++--- .../quickshell/ii/services/HyprlandConfig.qml | 2 +- 4 files changed, 39 insertions(+), 7 deletions(-) delete mode 100644 dots/.config/hypr/hyprland/shellOverrides/main.conf diff --git a/dots/.config/hypr/hyprland/shellOverrides/main.conf b/dots/.config/hypr/hyprland/shellOverrides/main.conf deleted file mode 100644 index e69de29bb..000000000 diff --git a/dots/.config/hypr/hyprland/shellOverrides/main.lua b/dots/.config/hypr/hyprland/shellOverrides/main.lua index 8b1378917..0ed02c205 100644 --- a/dots/.config/hypr/hyprland/shellOverrides/main.lua +++ b/dots/.config/hypr/hyprland/shellOverrides/main.lua @@ -1 +1,2 @@ - +-- DO NOT EDIT THIS FILE. IT IS MANAGED BY THE SHELL AND FOLLOWS STRICT RULES +-- In other words, I ain't writing a lua parser for this, so please be a good boi/girl/whatever diff --git a/dots/.config/quickshell/ii/scripts/hyprland/hyprconfigurator.py b/dots/.config/quickshell/ii/scripts/hyprland/hyprconfigurator.py index b458bbe3c..10bf4ea7d 100755 --- a/dots/.config/quickshell/ii/scripts/hyprland/hyprconfigurator.py +++ b/dots/.config/quickshell/ii/scripts/hyprland/hyprconfigurator.py @@ -4,6 +4,29 @@ import re import os import tempfile +def format_value(value): + """Format value: quote strings, leave numbers and booleans as-is""" + if value in ('true', 'false'): + return value + try: + float(value) + return value + except ValueError: + return f'"{value}"' + +def build_nested_structure(key_parts, value): + """Recursively build nested structure from key parts""" + if len(key_parts) == 1: + return f'{key_parts[0]}={format_value(value)}' + else: + return f'{key_parts[0]}={{{build_nested_structure(key_parts[1:], value)}}}' + +def generate_config_line(key, value): + """Generate hl.config line for given key and value""" + key_parts = key.split(':') + nested_structure = build_nested_structure(key_parts, value) + return f'hl.config({{{nested_structure}}})\n' + def edit_hyprland_config(file_path, set_args, reset_args): if os.path.exists(file_path): with open(file_path, 'r') as file: @@ -19,7 +42,15 @@ def edit_hyprland_config(file_path, set_args, reset_args): patterns = {} for k in list(set_dict.keys()) + list(reset_set): - patterns[k] = re.compile(rf'^\s*{re.escape(k)}\s*=') + key_parts = k.split(':') + main_key = key_parts[0] + if len(key_parts) > 1: + # Build pattern to match nested structure + pattern_parts = [rf'\s*{re.escape(part)}\s*=' for part in key_parts] + nested_pattern = '\{'.join(pattern_parts) + patterns[k] = re.compile(rf'^\s*hl\.config\(\{{\s*{nested_pattern}') + else: + patterns[k] = re.compile(rf'^\s*hl\.config\(\{{\s*{re.escape(main_key)}\s*=') for line in lines: matched = False @@ -36,7 +67,7 @@ def edit_hyprland_config(file_path, set_args, reset_args): # Check if line matches a key to be set for key, value in set_dict.items(): if patterns[key].match(line): - new_line = f"{key} = {value}\n" + new_line = generate_config_line(key, value) new_lines.append(new_line) found_keys.add(key) matched = True @@ -52,7 +83,7 @@ def edit_hyprland_config(file_path, set_args, reset_args): if key not in found_keys: if new_lines and not new_lines[-1].endswith('\n'): new_lines[-1] += '\n' - new_lines.append(f"{key} = {value}\n") + new_lines.append(generate_config_line(key, value)) dir_name = os.path.dirname(os.path.abspath(file_path)) os.makedirs(dir_name, exist_ok=True) @@ -77,10 +108,10 @@ def edit_hyprland_config(file_path, set_args, reset_args): for key in reset_set: print(f"Removed '{key}' from '{file_path}'") for key, value in set_dict.items(): - print(f"Updated '{file_path}' with {key} = {value}") + print(f"Updated '{file_path}' with {generate_config_line(key, value).strip()}") if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Edit a Hyprland config file.") + parser = argparse.ArgumentParser(description="Edit a Hyprland config file. Subkeys use colon (:) for nesting.") parser.add_argument("--file", default="~/.config/hypr/hyprland.conf", help="Path to the Hyprland config file (default: ~/.config/hypr/hyprland.conf).") parser.add_argument("--set", nargs=2, action="append", metavar=("KEY", "VALUE"), help="Set a configuration key to a value.") diff --git a/dots/.config/quickshell/ii/services/HyprlandConfig.qml b/dots/.config/quickshell/ii/services/HyprlandConfig.qml index cf5eb0e30..0f2f3f2ca 100644 --- a/dots/.config/quickshell/ii/services/HyprlandConfig.qml +++ b/dots/.config/quickshell/ii/services/HyprlandConfig.qml @@ -17,7 +17,7 @@ Singleton { signal reloaded() readonly property string configuratorScriptPath: Quickshell.shellPath("scripts/hyprland/hyprconfigurator.py") - readonly property string shellOverridesPath: FileUtils.trimFileProtocol(`${Directories.config}/hypr/hyprland/shellOverrides/main.conf`) + readonly property string shellOverridesPath: FileUtils.trimFileProtocol(`${Directories.config}/hypr/hyprland/shellOverrides/main.lua`) function set(key: string, value: var) { Quickshell.execDetached(["bash", "-c", //