Accept raw X windows in the shell

This commit is contained in:
Marco Pesenti Gritti 2007-04-08 19:20:59 +02:00
parent 3da95e9236
commit 09304e8e5a
7 changed files with 51 additions and 44 deletions

View File

@ -11,4 +11,5 @@ sugar_PYTHON = \
MeshModel.py \
ShellModel.py \
homeactivity.py \
homemodel.py
homemodel.py \
homerawwindow.py

View File

@ -24,9 +24,6 @@ from sugar.graphics.xocolor import XoColor
from sugar.presence import PresenceService
from sugar import profile
_ACTIVITY_SERVICE_NAME = "org.laptop.Activity"
_ACTIVITY_SERVICE_PATH = "/org/laptop/Activity"
class HomeActivity(gobject.GObject):
__gsignals__ = {
'launch-timeout': (gobject.SIGNAL_RUN_FIRST,
@ -39,29 +36,32 @@ class HomeActivity(gobject.GObject):
self._window = None
self._xid = None
self._service = None
self._id = activity_id
self._type = bundle.get_service_name()
self._icon_name = bundle.get_icon()
self._activity_id = activity_id
self._bundle = bundle
self._launch_time = time.time()
self._launched = False
self._launch_timeout_id = gobject.timeout_add(20000, self._launch_timeout_cb)
self._launch_timeout_id = gobject.timeout_add(
20000, self._launch_timeout_cb)
logging.debug("Activity %s (%s) launching..." % (self._id, self._type))
logging.debug("Activity %s (%s) launching..." %
(self._activity_id, self.get_type))
def __del__(self):
gobject.source_remove(self._launch_timeout_id)
self._launch_timeout_id = 0
def _launch_timeout_cb(self, user_data=None):
logging.debug("Activity %s (%s) launch timed out" % (self._id, self._type))
logging.debug("Activity %s (%s) launch timed out" %
(self._activity_id, self.get_type))
self._launch_timeout_id = 0
self.emit('launch-timeout')
return False
def set_window(self, window):
"""An activity is 'launched' once we get its window."""
logging.debug("Activity %s (%s) finished launching" % (self._id, self._type))
logging.debug("Activity %s (%s) finished launching" %
(self._activity_id, self.get_type))
self._launched = True
gobject.source_remove(self._launch_timeout_id)
self._launch_timeout_id = 0
@ -74,17 +74,8 @@ class HomeActivity(gobject.GObject):
self._window = window
self._xid = window.get_xid()
bus = dbus.SessionBus()
self._service = bus.get_object(_ACTIVITY_SERVICE_NAME + '%d' % self._xid,
_ACTIVITY_SERVICE_PATH + "/%s" % self._xid)
# verify id and type details
act_id = self._service.get_id()
if act_id != self._id:
raise RuntimeError("Activity's real ID (%s) didn't match expected (%s)." % (act_id, self._id))
act_type = self._service.get_service_name()
if act_type != self._type:
raise RuntimeError("Activity's real type (%s) didn't match expected (%s)." % (act_type, self._type))
def set_service(self, service):
self._service = service
def get_service(self):
return self._service
@ -95,17 +86,18 @@ class HomeActivity(gobject.GObject):
return self._window.get_name()
def get_icon_name(self):
return self._icon_name
return self._bundle.get_icon()
def get_icon_color(self):
activity = PresenceService.get_instance().get_activity(self._id)
pservice = PresenceService.get_instance()
activity = pservice.get_activity(self._activity_id)
if activity != None:
return XoColor(activity.get_color())
else:
return profile.get_color()
def get_id(self):
return self._id
def get_activity_id(self):
return self._activity_id
def get_xid(self):
if not self._launched:
@ -118,7 +110,7 @@ class HomeActivity(gobject.GObject):
return self._window
def get_type(self):
return self._type
return self._bundle.get_service_name()
def get_shared(self):
if not self._launched:

View File

@ -21,10 +21,11 @@ import wnck
import dbus
from model.homeactivity import HomeActivity
from model.homerawwindow import HomeRawWindow
from sugar.activity import bundleregistry
_ACTIVITY_SERVICE_NAME = "org.laptop.Activity"
_ACTIVITY_SERVICE_PATH = "/org/laptop/Activity"
_SERVICE_NAME = "org.laptop.Activity"
_SERVICE_PATH = "/org/laptop/Activity"
class HomeModel(gobject.GObject):
@ -116,15 +117,28 @@ class HomeModel(gobject.GObject):
logging.error('Model for window %d does not exist.' % xid)
self.emit('active-activity-changed', self._current_activity)
def _add_window(self, window):
home_window = HomeRawWindow(window)
self._activities[home_window.get_activity_id()] = home_window
self.emit('activity-added', home_window)
def _add_activity(self, window):
bus = dbus.SessionBus()
xid = window.get_xid()
act_service = bus.get_object(_ACTIVITY_SERVICE_NAME + '%d' % xid,
_ACTIVITY_SERVICE_PATH + "/%s" % xid)
act_id = act_service.get_id()
try:
service = bus.get_object(_SERVICE_NAME + '%d' % xid,
_SERVICE_PATH + "/%s" % xid)
except dbus.DBusException:
service = None
if not service:
self._add_window(window)
return
activity = None
act_id = service.get_id()
act_type = service.get_service_name()
if self._activities.has_key(act_id):
activity = self._activities[act_id]
else:
@ -138,6 +152,7 @@ class HomeModel(gobject.GObject):
activity = HomeActivity(bundle, act_id)
self._activities[act_id] = activity
activity.set_service(service)
activity.set_window(window)
self.emit('activity-added', activity)
@ -146,7 +161,7 @@ class HomeModel(gobject.GObject):
self._current_activity = None
self.emit('activity-removed', activity)
act_id = activity.get_id()
act_id = activity.get_activity_id()
del self._activities[act_id]
def _remove_activity(self, xid):
@ -157,7 +172,7 @@ class HomeModel(gobject.GObject):
logging.error('Model for window %d does not exist.' % xid)
def _activity_launch_timeout_cb(self, activity):
act_id = activity.get_id()
act_id = activity.get_activity_id()
if not act_id in self._activities.keys():
return
self._internal_remove_activity(activity)

View File

@ -57,5 +57,5 @@ class ShellService(dbus.service.Object):
def _cur_activity_changed_cb(self, owner, new_activity):
new_id = ""
if new_activity:
new_id = new_activity.get_id()
new_id = new_activity.get_activity_id()
self.CurrentActivityChanged(new_id)

View File

@ -38,7 +38,6 @@ class ActivityChatWindow(gtk.Window):
class ActivityHost:
def __init__(self, model):
self._model = model
self._id = model.get_id()
self._window = model.get_window()
self._activity = model.get_service()
self._gdk_window = gtk.gdk.window_foreign_new(self.get_xid())
@ -57,7 +56,7 @@ class ActivityHost:
self._frame_was_visible = False
def get_id(self):
return self._id
return self._model.get_activity_id()
def get_xid(self):
return self._window.get_xid()

View File

@ -110,7 +110,7 @@ class FriendsBox(hippo.CanvasBox):
def _active_activity_changed_cb(self, home_model, home_activity):
if home_activity:
activity_id = home_activity.get_id()
activity_id = home_activity.get_activity_id()
ps = self._pservice.get_activity(activity_id)
self._set_activity_ps(ps)
else:

View File

@ -141,7 +141,7 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
def _activity_added_cb(self, model, activity):
# Mark the activity as launched
act_id = activity.get_id()
act_id = activity.get_activity_id()
if not self._activities.has_key(act_id):
self._add_activity(activity)
icon = self._activities[act_id]
@ -154,7 +154,7 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
self.emit_paint_needed(0, 0, -1, -1)
def _remove_activity(self, activity):
act_id = activity.get_id()
act_id = activity.get_activity_id()
if not self._activities.has_key(act_id):
return
icon = self._activities[act_id]
@ -167,7 +167,7 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
icon.connect('activated', self._activity_icon_clicked_cb)
self.append(icon, hippo.PACK_FIXED)
self._activities[activity.get_id()] = icon
self._activities[activity.get_activity_id()] = icon
self.emit_paint_needed(0, 0, -1, -1)
@ -176,7 +176,7 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
if not icon.get_launched():
return
activity_host = self._shell.get_activity(activity.get_id())
activity_host = self._shell.get_activity(activity.get_activity_id())
if activity_host:
activity_host.present()
@ -250,7 +250,7 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
i = 0
for h_activity in self._model:
icon = self._activities[h_activity.get_id()]
icon = self._activities[h_activity.get_activity_id()]
[angle_start, angle_end] = self._get_angles(i)
angle = angle_start + (angle_end - angle_start) / 2