After setting property on global object in one script like this
workspace.activeWindow.my_property = 1;
I expected to be able to access this property in another script but it doesn’t seem to be present there which seems strange as the active window is global state as calling print(workspace.activeWindow)
from both scrips results in the same output
js: KWin::XdgToplevelWindow(0x5602f3a08220)
Any idea why doesn’t this work?i
Is there some other way to share data between KWin scripts?
Is there some other way to share data between KWin scripts?
I’ve never tried sending data from a KWin script to another but I did need to share it with an external program (the silly cursor-eyes widget) using callDBus
, AFAIK any other external currently interacting with KWin uses that, e.g. kdotool
According to KWin scripting API | Developer and also looking at the code kwin/src/scripting/scripting.cpp at 1b2f706d168cba0ca6fb74ec99a55180bf2a4fff · KDE/kwin · GitHub you can pass a callback to get the response from D-Bus, so in theory it should be possible to send and receive data with outside using a D-Bus service.
But AFAIK there is no way to register a D-Bus service from JS KWin script (it is possible with a QML KWin script and a C++ plugin but that’s way more complex)
You can try setting up a python script that creates D-Bus service to store your data, then in the service expose a setter and getter methods that you will then call from your scripts using callDBus
.
Examples of a service plasma-cursor-eyes/package/contents/ui/tools/service.py at main · luisbocanegra/plasma-cursor-eyes · GitHub or getter and setter in a single method: plasma-panel-colorizer/package/contents/ui/tools/service.py at main · luisbocanegra/plasma-panel-colorizer · GitHub
callDBus
usage plasma-cursor-eyes/.old/kwin_script_js/package/contents/code/main.js at main · luisbocanegra/plasma-cursor-eyes · GitHub
2 Likes