Skip to content

Add kwinscript subcommand for running arbitrary KWin JavaScript#58

Open
marvin1099 wants to merge 1 commit into
jinliu:masterfrom
marvin1099:kwinscript_argumet
Open

Add kwinscript subcommand for running arbitrary KWin JavaScript#58
marvin1099 wants to merge 1 commit into
jinliu:masterfrom
marvin1099:kwinscript_argumet

Conversation

@marvin1099

@marvin1099 marvin1099 commented Jul 3, 2026

Copy link
Copy Markdown

Adds the kwinscript sub-command for custom kde control

Would add request #31

AI was used here, i did checking and testing myself, it is working, and looks correct in my eyes.
Would this be acceptable?

Here are some examples of what can be done with this:

Set opacity (0.0 - 1.0)

kdotool kwinscript --inline 'var w=workspace.activeWindow;if(w){w.opacity=0.5;output_result("50% opacity");}'

Get all the window stats you ever (not), wanted

Create file window_stats.js at preferred location with contents:

// Reports various properties of the currently active window.
// Uses output_result() so kdotool captures and prints the values.

var w = workspace.activeWindow;
if (!w) {
    output_error("No active window");
} else {
    output_result("--- Window Stats ---");
    output_result("ID: " + w.internalId);
    output_result("Title: " + w.caption);
    output_result("Class: " + w.resourceClass + " (" + w.resourceName + ")");
    output_result("Geometry: " + w.x + "x" + w.y + " " + w.width + "x" + w.height);
    output_result("Desktop: " + w.desktops.map(function(d) { return d.x11DesktopNumber; }).join(","));
    output_result("PID: " + w.pid);
    output_result("Minimized: " + w.minimized);
    output_result("Fullscreen: " + w.fullScreen);
    output_result("KeepAbove: " + w.keepAbove);
    output_result("KeepBelow: " + w.keepBelow);
    output_result("SkipTaskbar: " + w.skipTaskbar);
    output_result("NoBorder: " + w.noBorder);
    output_result("Opacity: " + w.opacity);
    output_result("Moveable: " + w.moveable);
    output_result("Resizeable: " + w.resizeable);
    output_result("MaximizeMode: " + w.maximizeMode);
    output_result("OnAllDesktops: " + w.onAllDesktops);
    output_result("Active: " + w.active);
    output_result("DemandsAttention: " + w.demandsAttention);
    output_result("Layer: " + w.layer);
    output_result("WindowType: " + w.windowType);
}

then run:
kdotool kwinscript --file window_stats.js

To get all the stats.

Supports --file <path> and --inline <code> (mutually exclusive) to run
raw KWin JS directly, with full access to the script helper functions
(output_result, output_error, etc.) and D-Bus callback mechanism.

The user's script body is wrapped in a try-catch inside the generated
run() function so that any JavaScript error is reported via output_error
instead of producing a cryptic D-Bus 'No such object path' error.
@marvin1099 marvin1099 force-pushed the kwinscript_argumet branch from 597db9d to d597f68 Compare July 3, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant