From 677c4bc1998dff01a0b36c4c77e58e129351415e Mon Sep 17 00:00:00 2001 From: Bert Freudenberg Date: Wed, 23 May 2007 18:33:30 +0200 Subject: [PATCH] Reliably detect activity launch (fix for #1560) --- shell/model/homemodel.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/shell/model/homemodel.py b/shell/model/homemodel.py index a3afdc4d..39885ed2 100644 --- a/shell/model/homemodel.py +++ b/shell/model/homemodel.py @@ -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