Skip to content

Instantly share code, notes, and snippets.

@gavinhungry
Last active May 27, 2022 23:03
Show Gist options
  • Save gavinhungry/99de2acf2a01240932320023e05a6d47 to your computer and use it in GitHub Desktop.
Save gavinhungry/99de2acf2a01240932320023e05a6d47 to your computer and use it in GitHub Desktop.
D-Bus service providing org.gnome.ScreenSaver GetActive method for xsecurelock
#!/usr/bin/env python2
# /usr/share/dbus-1/scripts/org.gnome.ScreenSaver.py
import dbus
import dbus.mainloop.glib
import dbus.service
import gobject
import psutil
class ScreenSaver(dbus.service.Object):
def __init__(self):
self.session_bus = dbus.SessionBus()
name = dbus.service.BusName("org.gnome.ScreenSaver", bus=self.session_bus)
dbus.service.Object.__init__(self, name, "/")
@dbus.service.method("org.gnome.ScreenSaver", in_signature='', out_signature='b')
def GetActive(self):
for pid in psutil.process_iter():
if pid.name() == "xsecurelock":
return True
return False
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
loop = gobject.MainLoop()
object = ScreenSaver()
loop.run()
# /usr/share/dbus-1/services/org.gnome.ScreenSaver.service
[D-BUS Service]
Name=org.gnome.ScreenSaver
Exec=/usr/share/dbus-1/scripts/org.gnome.ScreenSaver.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment