Make Journal active at startup. #2159

Also distinguish between "active" in the sense of "the user is actually
using this activity" and "active" in the sense of "the activity would
be active *if* the user switched to Activity view". It's the latter sense,
now called "pending" that the Journal is in at startup. Pending is also
used for the next-up activity when you quit the current active activity.
This commit is contained in:
Dan Winship 2007-08-08 09:30:45 -04:00
parent 6ca80a7146
commit c85c89ce83
3 changed files with 89 additions and 43 deletions

View File

@ -51,6 +51,9 @@ class HomeModel(gobject.GObject):
([gobject.TYPE_PYOBJECT])),
'active-activity-changed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'pending-activity-changed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT]))
}
@ -59,7 +62,8 @@ class HomeModel(gobject.GObject):
self._activities = []
self._bundle_registry = bundleregistry.get_registry()
self._current_activity = None
self._active_activity = None
self._pending_activity = None
screen = wnck.screen_get_default()
screen.connect('window-opened', self._window_opened_cb)
@ -67,8 +71,55 @@ class HomeModel(gobject.GObject):
screen.connect('active-window-changed',
self._active_window_changed_cb)
def get_current_activity(self):
return self._current_activity
def get_pending_activity(self):
"""Returns the activity that would be seen in the Activity zoom level
In the Home (or Neighborhood or Groups) zoom level, this
indicates the activity that would become active if the user
switched to the Activity zoom level. (In the Activity zoom
level, this just returns the currently-active activity.)
Unlike get_active_activity(), this never returns None as long
as there is any activity running.
"""
return self._pending_activity
def _set_pending_activity(self, activity):
if self._pending_activity == activity:
return
self._pending_activity = activity
self.emit('pending-activity-changed', self._pending_activity)
def get_active_activity(self):
"""Returns the activity that the user is currently working in
In the Activity zoom level, this returns the currently-active
activity. In the other zoom levels, it returns the activity
that was most-recently active in the Activity zoom level, or
None if the most-recently-active activity is no longer
running.
"""
return self._active_activity
def _set_active_activity(self, activity):
if self._active_activity == activity:
return
if self._active_activity:
service = self._active_activity.get_service()
if service:
service.set_active(False,
reply_handler=self._set_active_success,
error_handler=self._set_active_error)
if activity:
service = activity.get_service()
if service:
service.set_active(True,
reply_handler=self._set_active_success,
error_handler=self._set_active_error)
self._active_activity = activity
self.emit('active-activity-changed', self._active_activity)
def __iter__(self):
return iter(self._activities)
@ -106,12 +157,12 @@ class HomeModel(gobject.GObject):
activity.props.launching = False
self.emit('activity-started', activity)
if self._pending_activity is None:
self._set_pending_activity(activity)
def _window_closed_cb(self, screen, window):
if window.get_window_type() == wnck.WINDOW_NORMAL:
self._remove_activity_by_xid(window.get_xid())
if not self._activities:
self.emit('active-activity-changed', None)
self._notify_activity_activation(self._current_activity, None)
def _get_activity_by_xid(self, xid):
for activity in self._activities:
@ -125,24 +176,6 @@ class HomeModel(gobject.GObject):
return activity
return None
def _notify_activity_activation(self, old_activity, new_activity):
if old_activity == new_activity:
return
if old_activity:
service = old_activity.get_service()
if service:
service.set_active(False,
reply_handler=self._set_active_success,
error_handler=self._set_active_error)
if new_activity:
service = new_activity.get_service()
if service:
service.set_active(True,
reply_handler=self._set_active_success,
error_handler=self._set_active_error)
def _set_active_success(self):
pass
@ -151,32 +184,34 @@ class HomeModel(gobject.GObject):
def _active_window_changed_cb(self, screen):
window = screen.get_active_window()
if window == None:
self.emit('active-activity-changed', None)
self._notify_activity_activation(self._current_activity, None)
return
if window.get_window_type() != wnck.WINDOW_NORMAL:
if window is None or window.get_window_type() != wnck.WINDOW_NORMAL:
return
xid = window.get_xid()
act = self._get_activity_by_xid(window.get_xid())
if act:
self._notify_activity_activation(self._current_activity, act)
self._current_activity = act
else:
self._notify_activity_activation(self._current_activity, None)
self._current_activity = None
act = self._get_activity_by_xid(xid)
if act is None:
logging.error('Model for window %d does not exist.' % xid)
self.emit('active-activity-changed', self._current_activity)
self._set_pending_activity(act)
self._set_active_activity(act)
def _add_activity(self, activity):
self._activities.append(activity)
self.emit('activity-added', activity)
def _remove_activity(self, activity):
if activity == self._current_activity:
self._current_activity = None
if activity == self._active_activity:
self._set_active_activity(None)
# Figure out the new _pending_activity.
windows = wnck.screen_get_default().get_windows_stacked()
windows.reverse()
for window in windows:
new_activity = self._get_activity_by_xid(window.get_xid())
if new_activity is not None:
self._set_pending_activity(new_activity)
break
else:
logging.error('No activities are running')
self._set_pending_activity(None)
self.emit('activity-removed', activity)
self._activities.remove(activity)

View File

@ -47,6 +47,7 @@ class Shell(gobject.GObject):
self._hosts = {}
self._screen = wnck.screen_get_default()
self._current_host = None
self._pending_host = None
self._screen_rotation = 0
self._key_handler = KeyHandler(self)
@ -65,6 +66,8 @@ class Shell(gobject.GObject):
home_model.connect('activity-removed', self._activity_removed_cb)
home_model.connect('active-activity-changed',
self._active_activity_changed_cb)
home_model.connect('pending-activity-changed',
self._pending_activity_changed_cb)
# Unfreeze the display when it's stable
hw_manager = hardwaremanager.get_manager()
@ -100,6 +103,12 @@ class Shell(gobject.GObject):
self._current_host = host
def _pending_activity_changed_cb(self, home_model, home_activity):
if home_activity:
self._pending_host = self._hosts[home_activity.get_xid()]
else:
self._pending_host = None
def get_model(self):
return self._model
@ -156,6 +165,8 @@ class Shell(gobject.GObject):
return
if level == ShellModel.ZOOM_ACTIVITY:
if self._pending_host is not None:
self._pending_host.present()
self._screen.toggle_showing_desktop(False)
else:
self._model.set_zoom_level(level)

View File

@ -189,7 +189,7 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
self._model = shell.get_model().get_home()
self._model.connect('activity-added', self._activity_added_cb)
self._model.connect('activity-removed', self._activity_removed_cb)
self._model.connect('active-activity-changed', self._activity_changed_cb)
self._model.connect('pending-activity-changed', self._activity_changed_cb)
self.connect('button-release-event', self._button_release_event_cb)
@ -385,7 +385,7 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
cr.fill()
# Selected Wedge
current_activity = self._model.get_current_activity()
current_activity = self._model.get_pending_activity()
if current_activity is not None:
selected_index = self._model.index(current_activity)
[angle_start, angle_end] = self._get_angles(selected_index)