I want to run some commands when the active window changes in KDE. How can I do this from within a kwin script?
My use case is that I want to change monitor color preset for some applications, and another use case is to toggle input remap depending on active application.
There is a similar question: How can I run a kwin script from the command line? But this question is not related.
Previously, I could use Window Actions for X11 to partly solve the problem, but that UI was removed (see Bug 455444) as it does not work in Wayland.
I have heard that kwin scripts could not explicitly run an arbitrary commands, and the only way to interect with outside world is running dbus commands. But I am not completely sire about this statement. And if that is true, which is the dbus command, that runs an arbitrary shell command?
I tried searching, and found only few info. Question on reddit that says that maybe dbus call to krunner can help. I think this probably is a key to solve the task. And this another question, but it has nothing useful in answers.
Any help and code example would be appreciated.