Do you know if it’s possible to access the Kwin scripting API from anything else than a KWin script? The reason I ask is I would like to
choose my preferred language rather than use JS
access the file system (to save preferences, macros, etc)
develop and debug the application directly in Qt Creator rather than have to deal with the rather clunky loading/unloading of kwin scripts
In other words, I’d like to manipulate KWin’s windows from a full-fledged application, rather than from a script
Some methods of KWin, which are declared in classes with the Q_CLASSINFO(“D-Bus Interface”, “org.kde.kwin.***”) entry, are directly accessible through qdbus, but most are not. For instance the indispensable methods in Kwin::WorkspaceWrapper or Kwin::Window are not.
Since KWin scripts can be written in QML you could have a C++ plugin that exposes DBus methods, which you would call from your application, then from the script you either could talk back to the application via DBusCall qml type or from the C++ plugin.
The easiest option is, as @luisbocanegra says, probably to use a KWin script and let it communicate with the app using D-Bus.
I think there are even topics here on Discuss which have examples on doing this with Python being used on the app side.
Alternatively there are various C++ plugin APIs in Kwin which could be used to load something that communicates with the app via a different mechanism.
Ultimately it should also be possible, just more work, to integrate a different scripting system.
JavaScript is just the easiest because Qt already has that as a module (via QtDeclarative)
Thank you for your replies.
From what I understand, you guys are saying that all I need is to have a KWin script act as some sort of gateway between its owner (KWin) and my application? That would be great: the script would simply forward calls back and forth.
The simplest way to do that would be through a pure javascript script.
But, the truth is I had thought about that. But I can’t find a way to access DBus from Javascript code. Web searches typically yield results such as ‘gjs’, ‘Node.js’ or ‘Cockpit’. Would any of these solutions be adequate?
As for using a C++ plugin (rather than JS), I’m open to that as well. Would you happen to have pointers as to how to achieve that? I can’t find any documentation or examples…
I had not noticed in Kwin API’s documentation the existence of the callDBus function. Thanks to @luisbocanegra’s link to @supagu’s thread, I am now able to get going!