From ce8a8992443567d1c7ff9336240c47154e6ace30 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Mon, 23 Feb 2026 04:52:30 -0600 Subject: [PATCH] fix(window): use Script.run() instead of Scripting.start() for KWin SSD The KWin D-Bus scripting API requires calling run() on the specific script object (/Scripting/Script{id}) returned by loadScript(), not start() on the /Scripting root. Also unloads previous script instance before reloading, and adds 500ms delay to ensure window is mapped. --- src-tauri/src/lib.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index c7d13db83..3a03355a3 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -198,6 +198,16 @@ workspace.windowAdded.connect(forceDecorations); file.write_all(script_content.as_bytes()) .map_err(|e| format!("Failed to write KWin script: {}", e))?; + // Unload previous script instance if it exists + let _ = std::process::Command::new("qdbus6") + .args([ + "org.kde.KWin", + "/Scripting", + "org.kde.kwin.Scripting.unloadScript", + "qbz-ssd", + ]) + .output(); + // Load script via qdbus6 (KDE Plasma 6) let output = std::process::Command::new("qdbus6") .args([ @@ -217,19 +227,25 @@ workspace.windowAdded.connect(forceDecorations); )); } - // Start the script + // Parse script ID from loadScript output (returns an integer) + let script_id = String::from_utf8_lossy(&output.stdout) + .trim() + .to_string(); + + // Run the specific script using its D-Bus object path + let script_path_dbus = format!("/Scripting/Script{}", script_id); let output = std::process::Command::new("qdbus6") .args([ "org.kde.KWin", - "/Scripting", - "org.kde.kwin.Scripting.start", + &script_path_dbus, + "org.kde.kwin.Script.run", ]) .output() - .map_err(|e| format!("Failed to start KWin script: {}", e))?; + .map_err(|e| format!("Failed to run KWin script: {}", e))?; if !output.status.success() { return Err(format!( - "qdbus6 start failed: {}", + "qdbus6 Script.run failed: {}", String::from_utf8_lossy(&output.stderr) )); } @@ -487,8 +503,10 @@ pub fn run() { })?; // Load KWin script to force server-side decorations for QBZ + // Small delay ensures the window is mapped in KWin before script runs if use_kwin_ssd { std::thread::spawn(|| { + std::thread::sleep(std::time::Duration::from_millis(500)); if let Err(e) = load_kwin_ssd_script() { log::warn!("Failed to load KWin SSD script: {}", e); }