forked from Shinonome/dots-hyprland
qs: fix hyprland overrides (game mode, anti flashbang)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.")
|
||||
|
||||
@@ -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", //
|
||||
|
||||
Reference in New Issue
Block a user