fix: eliminate double-click theme bug by integrating sync_kde color scheme generation before plasma-apply-colorscheme execution

This commit is contained in:
Sho 2026-08-02 02:33:16 +09:00
parent d8c03e59a3
commit d6858dd940
2 changed files with 64 additions and 3 deletions

View File

@ -111,6 +111,69 @@ def restart_app_if_running(name, search_patterns, launch_commands):
raw_cmd = " || ".join(launch_commands) raw_cmd = " || ".join(launch_commands)
subprocess.Popen(f"sh -c '{raw_cmd} &'", shell=True, start_new_session=True) 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): def sync_gtk(bg, surface, current_line, fg, accent, is_dark):
css_content = f"""/* Auto-generated by Quickshell Theme Engine */ css_content = f"""/* Auto-generated by Quickshell Theme Engine */
@define-color window_bg_color {bg}; @define-color window_bg_color {bg};
@ -1936,6 +1999,7 @@ def main():
is_dark = args.isDark.lower() == 'true' is_dark = args.isDark.lower() == 'true'
sync_gtk(args.bg, args.surface, args.currentLine, args.fg, args.accent, is_dark) 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_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_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) sync_vscode(args.bg, args.surface, args.currentLine, args.fg, args.accent, args.subAccent, is_dark, args.variantName)

View File

@ -160,9 +160,6 @@ Item {
Quickshell.execDetached(["gsettings", "set", "org.gnome.desktop.interface", "color-scheme", isDark ? "prefer-dark" : "prefer-light"]) Quickshell.execDetached(["gsettings", "set", "org.gnome.desktop.interface", "color-scheme", isDark ? "prefer-dark" : "prefer-light"])
Quickshell.execDetached(["kwriteconfig6", "--group", "Icons", "--key", "Theme", iconTheme]) 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([ Quickshell.execDetached([
"python3", Quickshell.env("HOME") + "/.config/quickshell/services/python/theme_sync.py", "python3", Quickshell.env("HOME") + "/.config/quickshell/services/python/theme_sync.py",
"--bg", v.bg, "--bg", v.bg,