Reliably detect activity launch (fix for #1560)
This commit is contained in:
parent
f3d9d5e334
commit
677c4bc199
@ -68,6 +68,12 @@ class HomeModel(gobject.GObject):
|
||||
screen.connect('window-closed', self._window_closed_cb)
|
||||
screen.connect('active-window-changed',
|
||||
self._active_window_changed_cb)
|
||||
bus = dbus.SessionBus()
|
||||
bus.add_signal_receiver(
|
||||
self._dbus_name_owner_changed_cb,
|
||||
'NameOwnerChanged',
|
||||
'org.freedesktop.DBus',
|
||||
'org.freedesktop.DBus')
|
||||
|
||||
def get_current_activity(self):
|
||||
return self._current_activity
|
||||
@ -103,9 +109,31 @@ class HomeModel(gobject.GObject):
|
||||
self.emit('active-activity-changed', None)
|
||||
self._notify_activity_activation(self._current_activity, None)
|
||||
|
||||
def _dbus_name_owner_changed_cb(self, name, old, new):
|
||||
"""Detect new activity instances on the DBus
|
||||
|
||||
Normally, new activities are detected by
|
||||
the _window_opened_cb callback. However, if the
|
||||
window is opened before the dbus service is up,
|
||||
a RawHomeWindow is created. In here we create
|
||||
a proper HomeActivity replacing the RawHomeWindow.
|
||||
"""
|
||||
if name.startswith(_SERVICE_NAME) and new and not old:
|
||||
xid = name[len(_SERVICE_NAME):]
|
||||
if not xid.isdigit():
|
||||
return
|
||||
logging.debug("Activity instance launch detected: %s" % name)
|
||||
xid = int(xid)
|
||||
act = self._get_activity_by_xid(xid)
|
||||
if isinstance(act, HomeRawWindow):
|
||||
logging.debug("Removing bogus raw activity %s for window %i"
|
||||
% (act.get_activity_id(), xid))
|
||||
self._internal_remove_activity(act)
|
||||
self._add_activity(act.get_window())
|
||||
|
||||
def _get_activity_by_xid(self, xid):
|
||||
for act in self._activities.values():
|
||||
if act.get_xid() == xid:
|
||||
if act.get_launched() and act.get_xid() == xid:
|
||||
return act
|
||||
return None
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user