Skip to content

Instantly share code, notes, and snippets.

@x42
Created January 6, 2025 20:45
Show Gist options
  • Save x42/6bd5e37a6672f2fa6de3b84ba662f403 to your computer and use it in GitHub Desktop.
Save x42/6bd5e37a6672f2fa6de3b84ba662f403 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from gi.repository import GLib
import atexit
import dbus
import dbus.service
import dbus.mainloop.glib
class ScreenSaverProxy(dbus.service.Object):
def __init__(self, conn, object_path):
dbus.service.Object.__init__(self, conn, object_path)
proxy = session_bus.get_object('org.mate.ScreenSaver','/org/mate/ScreenSaver')
self.xiface = dbus.Interface(proxy, 'org.mate.ScreenSaver')
self.active = []
@dbus.service.method("org.freedesktop.ScreenSaver", in_signature='ss', out_signature='u')
def Inhibit(self, a, b):
c = self.xiface.Inhibit(a, b)
self.active.append (c);
print("Inhibit:", a, b, c)
return c
@dbus.service.method("org.freedesktop.ScreenSaver", in_signature='u', out_signature='')
def UnInhibit(self, a):
print("UnInhibit:", a)
self.xiface.UnInhibit(a)
self.active.remove (a);
def cleanup (self):
print("Cleanup..")
for a in self.active:
print("UnInhibit:", a)
self.xiface.UnInhibit(a)
def unregister(proxy):
proxy.cleanup()
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
session_bus = dbus.SessionBus()
name = dbus.service.BusName("org.freedesktop.ScreenSaver", session_bus)
proxy = ScreenSaverProxy(session_bus, '/org/freedesktop/ScreenSaver')
atexit.register(unregister, proxy)
mainloop = GLib.MainLoop()
print("Running screensaver proxy.")
mainloop.run()
@stephematician
Copy link

Looks good 👍️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment