Commit 02cca30d authored by André's avatar André Committed by Philipp Hörist

Support idle time from org.freedesktop.ScreenSaver

parent c36a2b30
Pipeline #6785 passed with stages
in 9 minutes and 35 seconds
......@@ -21,6 +21,7 @@ finish-args:
- --talk-name=org.mpris.MediaPlayer2.*
- --talk-name=org.freedesktop.portal.Fcitx
# Automatic status
- --talk-name=org.freedesktop.ScreenSaver
- --talk-name=org.gnome.Mutter.IdleMonitor
# Keyring
- --talk-name=org.freedesktop.secrets
......
......@@ -33,6 +33,57 @@
log = logging.getLogger('gajim.c.idle')
class DBusFreedesktopIdleMonitor:
def __init__(self):
self.last_idle_time = 0
self._extended_away = False
log.debug('Connecting to D-Bus')
self.dbus_proxy = Gio.DBusProxy.new_for_bus_sync(
Gio.BusType.SESSION,
Gio.DBusProxyFlags.NONE,
None,
'org.freedesktop.ScreenSaver',
'/org/freedesktop/ScreenSaver',
'org.freedesktop.ScreenSaver',
None
)
log.debug('D-Bus connected')
# Only the following call will trigger exceptions if the D-Bus
# interface/method/... does not exist. Using the failing method
# for class init to allow other idle monitors to be used on failure.
self._get_idle_sec_fail()
log.debug('D-Bus call test successful')
def _get_idle_sec_fail(self):
(idle_time,) = self.dbus_proxy.call_sync(
'GetSessionIdleTime',
None,
Gio.DBusCallFlags.NO_AUTO_START,
-1,
None
)
return idle_time//1000
def get_idle_sec(self):
try:
self.last_idle_time = self._get_idle_sec_fail()
except GLib.Error as error:
log.warning(
'org.freedesktop.ScreenSaver.GetSessionIdleTime() failed: %s',
error)
return self.last_idle_time
def set_extended_away(self, state):
self._extended_away = state
def is_extended_away(self):
return self._extended_away
class DBusGnomeIdleMonitor:
def __init__(self):
......@@ -257,15 +308,19 @@ def _get_idle_monitor():
return WindowsIdleMonitor()
try:
return DBusGnomeIdleMonitor()
return DBusFreedesktopIdleMonitor()
except GLib.Error as error:
log.info('Idle time via D-Bus not available: %s', error)
try:
return XssIdleMonitor()
except OSError as error:
log.info('Idle time via XScreenSaverInfo '
'not available: %s', error)
try:
return DBusGnomeIdleMonitor()
except GLib.Error as error:
log.info('Idle time via D-Bus (GNOME) not available: %s', error)
try:
return XssIdleMonitor()
except OSError as error:
log.info('Idle time via XScreenSaverInfo not available: %s', error)
def get_idle_sec(self):
return self._idle_monitor.get_idle_sec()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment