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

Screensaver: Switch to property signal for portal support

- Move functionality to application.py
parent 628e675b
Pipeline #4517 passed with stages
in 2 minutes and 31 seconds
......@@ -14,7 +14,6 @@ finish-args:
- --socket=pulseaudio
- --system-talk-name=org.freedesktop.GeoClue2
- --system-talk-name=org.freedesktop.login1
- --talk-name=org.gnome.ScreenSaver
- --talk-name=org.mpris.MediaPlayer2.*
- --talk-name=org.freedesktop.portal.Fcitx
# Automatic status
......
......@@ -67,6 +67,9 @@ class GajimApplication(Gtk.Application):
application_id='org.gajim.Gajim',
flags=flags)
# required to track screensaver state
self.props.register_session = True
self.add_main_option(
'version',
ord('V'),
......@@ -168,6 +171,8 @@ class GajimApplication(Gtk.Application):
self.connect('command-line', self._handle_remote_options)
self.connect('startup', self._startup)
self.connect('activate', self._activate)
if sys.platform not in ('win32', 'darwin'):
self.connect("notify::screensaver-active", self._screensaver_active)
self.interface = None
......@@ -566,3 +571,46 @@ class GajimApplication(Gtk.Application):
elif event.feature == nbxmpp.NS_BLOCKING:
action = '%s-blocking' % event.account
self.lookup_action(action).set_enabled(True)
def _screensaver_active(self, application, param):
'''Signal handler for screensaver active change'''
active = self.get_property('screensaver-active')
roster = app.interface.roster
if not active:
for account in app.connections:
if app.account_is_connected(account) and \
app.sleeper_state[account] == 'autoaway-forced':
# We came back online after screensaver autoaway
roster.send_status(account, 'online',
app.status_before_autoaway[account])
app.status_before_autoaway[account] = ''
app.sleeper_state[account] = 'online'
return
if not app.config.get('autoaway'):
# Don't go auto away if user disabled the option
return
for account in app.connections:
if (account not in app.sleeper_state or
not app.sleeper_state[account]):
continue
if app.sleeper_state[account] == 'online':
if not app.account_is_connected(account):
continue
# we save our online status
app.status_before_autoaway[account] = \
app.connections[account].status
# we go away (no auto status) [we pass True to auto param]
auto_message = app.config.get('autoaway_message')
if not auto_message:
auto_message = app.connections[account].status
else:
auto_message = auto_message.replace('$S', '%(status)s')
auto_message = auto_message.replace('$T', '%(time)s')
auto_message = auto_message % {
'status': app.status_before_autoaway[account],
'time': app.config.get('autoxatime')}
roster.send_status(account, 'away', auto_message, auto=True)
app.sleeper_state[account] = 'autoaway-forced'
# Copyright (C) 2018 André Apitzsch <git AT apitzsch.eu>
#
# This file is part of Gajim.
#
# Gajim is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; version 3 only.
#
# Gajim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
import logging
from gi.repository import Gio
from gajim.common import app
log = logging.getLogger('gajim.c.dbus.screensaver')
class ScreensaverListener:
_instance = None
@classmethod
def get(cls):
if cls._instance is None:
cls._instance = cls()
return cls._instance
def __init__(self):
Gio.bus_watch_name(
Gio.BusType.SESSION,
'org.gnome.ScreenSaver',
Gio.BusNameWatcherFlags.NONE,
self._appeared,
None)
@staticmethod
def _signal_received(_connection, _sender_name, _object_path,
interface_name, _signal_name, parameters, *_user_data):
'''Signal handler for screensaver active change'''
log.info('Signal received: %s - %s', interface_name, parameters)
roster = app.interface.roster
if not parameters[0]:
for account in app.connections:
if app.account_is_connected(account) and \
app.sleeper_state[account] == 'autoaway-forced':
# We came back online after screensaver
# autoaway
roster.send_status(account, 'online',
app.status_before_autoaway[account])
app.status_before_autoaway[account] = ''
app.sleeper_state[account] = 'online'
return
if not app.config.get('autoaway'):
# Don't go auto away if user disabled the option
return
for account in app.connections:
if (account not in app.sleeper_state or
not app.sleeper_state[account]):
continue
if app.sleeper_state[account] == 'online':
if not app.account_is_connected(account):
continue
# we save our online status
app.status_before_autoaway[account] = \
app.connections[account].status
# we go away (no auto status) [we pass True to auto param]
auto_message = app.config.get('autoaway_message')
if not auto_message:
auto_message = app.connections[account].status
else:
auto_message = auto_message.replace('$S', '%(status)s')
auto_message = auto_message.replace('$T', '%(time)s')
auto_message = auto_message % {
'status': app.status_before_autoaway[account],
'time': app.config.get('autoxatime')}
roster.send_status(account, 'away', auto_message, auto=True)
app.sleeper_state[account] = 'autoaway-forced'
def _appeared(self, connection, name, _name_owner, *_user_data):
'''Set up a listener for screensaver signals'''
log.info('%s appeared', name)
connection.signal_subscribe(
'org.gnome.ScreenSaver',
'org.gnome.ScreenSaver',
'ActiveChanged',
'/org/gnome/ScreenSaver',
None,
Gio.DBusSignalFlags.NONE,
self._signal_received,
None)
def enable():
ScreensaverListener.get()
......@@ -49,7 +49,6 @@ from nbxmpp.structs import TuneData
from gajim.common import app
from gajim.common import events
from gajim.common.dbus import screensaver
from gajim.common.dbus import location
from gajim.common.dbus import music_track
from gajim.common.dbus import logind
......@@ -2158,10 +2157,8 @@ class Interface:
app.gajim_optional_features[a] = []
app.caps_hash[a] = ''
# Handle screensaver
if sys.platform not in ('win32', 'darwin'):
logind.enable()
screensaver.enable()
self.show_vcard_when_connect = []
......
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