Yeah, I think the way you're supposed to do that is you install the kwin script which gives you the option to "connect" to various signals and then communicate the results via dbus to your service / listener (I don't think the script itself can host a dbus service which would be much simpler). One thing I got from looking at this is that KDE's documentation about scripting is either absolutely terrible, insufficient, or non existing.
https://unix.stackexchange.com/questions/706477/is-there-a-w...