From d6858dd9409bd8db4e927198c5ba50d3e0034f81 Mon Sep 17 00:00:00 2001 From: Sho Date: Sun, 2 Aug 2026 02:33:16 +0900 Subject: [PATCH] fix: eliminate double-click theme bug by integrating sync_kde color scheme generation before plasma-apply-colorscheme execution --- quickshell/services/python/theme_sync.py | 64 ++++++++++++++++++++++++ quickshell/theme/Theme.qml | 3 -- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/quickshell/services/python/theme_sync.py b/quickshell/services/python/theme_sync.py index 7e4043b..2157c60 100644 --- a/quickshell/services/python/theme_sync.py +++ b/quickshell/services/python/theme_sync.py @@ -111,6 +111,69 @@ def restart_app_if_running(name, search_patterns, launch_commands): raw_cmd = " || ".join(launch_commands) subprocess.Popen(f"sh -c '{raw_cmd} &'", shell=True, start_new_session=True) +def sync_kde(bg, surface, current_line, fg, accent, sub_accent, is_dark, variant_name): + import re, subprocess + clean_name = re.sub(r'[^a-zA-Z0-9]', '', variant_name) + color_scheme_dir = os.path.expanduser('~/.local/share/color-schemes') + os.makedirs(color_scheme_dir, exist_ok=True) + scheme_file = os.path.join(color_scheme_dir, f"{clean_name}.colors") + + def hex_to_rgb(hex_str): + hex_str = str(hex_str).lstrip('#') + if len(hex_str) == 3: + hex_str = ''.join([c*2 for c in hex_str]) + try: + return f"{int(hex_str[0:2], 16)},{int(hex_str[2:4], 16)},{int(hex_str[4:6], 16)}" + except Exception: + return "255,255,255" + + rgb_bg = hex_to_rgb(bg) + rgb_fg = hex_to_rgb(fg) + rgb_surf = hex_to_rgb(surface) + rgb_line = hex_to_rgb(current_line) + rgb_acc = hex_to_rgb(accent) + + kde_content = f"""[General] +Name={variant_name} +ColorScheme={clean_name} + +[Colors:Window] +BackgroundNormal={rgb_bg} +ForegroundNormal={rgb_fg} +BackgroundAlternate={rgb_surf} +ForegroundInactive={rgb_line} + +[Colors:View] +BackgroundNormal={rgb_surf} +ForegroundNormal={rgb_fg} +BackgroundAlternate={rgb_bg} +ForegroundInactive={rgb_line} + +[Colors:Button] +BackgroundNormal={rgb_surf} +ForegroundNormal={rgb_fg} +BackgroundAlternate={rgb_line} +ForegroundInactive={rgb_line} + +[Colors:Selection] +BackgroundNormal={rgb_acc} +ForegroundNormal={"255,255,255" if is_dark else "0,0,0"} + +[Colors:Header] +BackgroundNormal={rgb_bg} +ForegroundNormal={rgb_fg} + +[Colors:Tooltip] +BackgroundNormal={rgb_surf} +ForegroundNormal={rgb_fg} +""" + try: + with open(scheme_file, 'w', encoding='utf-8') as f: + f.write(kde_content) + subprocess.run(["plasma-apply-colorscheme", clean_name], capture_output=True) + except Exception: + pass + def sync_gtk(bg, surface, current_line, fg, accent, is_dark): css_content = f"""/* Auto-generated by Quickshell Theme Engine */ @define-color window_bg_color {bg}; @@ -1936,6 +1999,7 @@ def main(): is_dark = args.isDark.lower() == 'true' sync_gtk(args.bg, args.surface, args.currentLine, args.fg, args.accent, is_dark) + sync_kde(args.bg, args.surface, args.currentLine, args.fg, args.accent, args.subAccent, is_dark, args.variantName) sync_alacritty(args.bg, args.surface, args.currentLine, args.fg, args.accent, args.subAccent) sync_discord(args.bg, args.surface, args.currentLine, args.fg, args.accent, args.subAccent, is_dark) sync_vscode(args.bg, args.surface, args.currentLine, args.fg, args.accent, args.subAccent, is_dark, args.variantName) diff --git a/quickshell/theme/Theme.qml b/quickshell/theme/Theme.qml index 362d14d..e1921a4 100644 --- a/quickshell/theme/Theme.qml +++ b/quickshell/theme/Theme.qml @@ -160,9 +160,6 @@ Item { Quickshell.execDetached(["gsettings", "set", "org.gnome.desktop.interface", "color-scheme", isDark ? "prefer-dark" : "prefer-light"]) Quickshell.execDetached(["kwriteconfig6", "--group", "Icons", "--key", "Theme", iconTheme]) - let kdeScheme = v.name.replace(/[^a-zA-Z0-9]/g, '') - Quickshell.execDetached(["plasma-apply-colorscheme", kdeScheme]) - Quickshell.execDetached([ "python3", Quickshell.env("HOME") + "/.config/quickshell/services/python/theme_sync.py", "--bg", v.bg,