I'm trying to write some python to listen to signals.
Using dbus-monitor, as shown below, I can filter the signals I want.
dbus-monitor "type='signal',sender='org.kde.KWin',path='/ColorCorrect',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged'"
signal time=1653997355.732016 sender=:1.4 -> destination=(null destination) serial=13165 path=/ColorCorrect; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
string "org.kde.kwin.ColorCorrect"
array [
dict entry(
string "enabled"
variant boolean false
)
]
array [
]
But when I try the same thing with python, see below, nothing gets printed.
import dbus
from gi.repository import GLib
from dbus.mainloop.glib import DBusGMainLoop
def signal_handler(*args, **kwargs):
for i, arg in enumerate(args):
print("arg:%d %s" % (i, str(arg)))
print('kwargs:')
print(kwargs)
print('---end----')
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
# register your signal callback
bus.add_signal_receiver(signal_handler,
bus_name='org.kde.KWin',
interface_keyword='org.freedesktop.DBus.Properties',
member_keyword='PropertiesChanged',
path_keyword='/ColorCorrect'
# message_keyword='msg')
)
loop = GLib.MainLoop()
loop.run()
You might be interested in: NightColor.py for Setting Temp From Terminal which explains using
pydbus
to communicate the Night Color effect done by KWin using codename “ColorCorrect”.Solution
See the docs of pydbus, Connecting to the Bus:
Session bus in KDE
Default: session bus
From the
dbus-monitor
manpage:So, the message you saw in the output was apparently form default session-bus.
Same default bus explained in KDE's Developer guide: Accessing D-Bus Interfaces:
Note
The given DBus-Service name for KDE's Plasma Desktop window manager KWin (
org.kde.KWin
) can also have a suffix, see environment-variableKWIN_DBUS_SERVICE_SUFFIX