Accept raw X windows in the shell
This commit is contained in:
parent
3da95e9236
commit
09304e8e5a
@ -11,4 +11,5 @@ sugar_PYTHON = \
|
|||||||
MeshModel.py \
|
MeshModel.py \
|
||||||
ShellModel.py \
|
ShellModel.py \
|
||||||
homeactivity.py \
|
homeactivity.py \
|
||||||
homemodel.py
|
homemodel.py \
|
||||||
|
homerawwindow.py
|
||||||
|
@ -24,9 +24,6 @@ from sugar.graphics.xocolor import XoColor
|
|||||||
from sugar.presence import PresenceService
|
from sugar.presence import PresenceService
|
||||||
from sugar import profile
|
from sugar import profile
|
||||||
|
|
||||||
_ACTIVITY_SERVICE_NAME = "org.laptop.Activity"
|
|
||||||
_ACTIVITY_SERVICE_PATH = "/org/laptop/Activity"
|
|
||||||
|
|
||||||
class HomeActivity(gobject.GObject):
|
class HomeActivity(gobject.GObject):
|
||||||
__gsignals__ = {
|
__gsignals__ = {
|
||||||
'launch-timeout': (gobject.SIGNAL_RUN_FIRST,
|
'launch-timeout': (gobject.SIGNAL_RUN_FIRST,
|
||||||
@ -39,29 +36,32 @@ class HomeActivity(gobject.GObject):
|
|||||||
self._window = None
|
self._window = None
|
||||||
self._xid = None
|
self._xid = None
|
||||||
self._service = None
|
self._service = None
|
||||||
self._id = activity_id
|
self._activity_id = activity_id
|
||||||
self._type = bundle.get_service_name()
|
self._bundle = bundle
|
||||||
self._icon_name = bundle.get_icon()
|
|
||||||
|
|
||||||
self._launch_time = time.time()
|
self._launch_time = time.time()
|
||||||
self._launched = False
|
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):
|
def __del__(self):
|
||||||
gobject.source_remove(self._launch_timeout_id)
|
gobject.source_remove(self._launch_timeout_id)
|
||||||
self._launch_timeout_id = 0
|
self._launch_timeout_id = 0
|
||||||
|
|
||||||
def _launch_timeout_cb(self, user_data=None):
|
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._launch_timeout_id = 0
|
||||||
self.emit('launch-timeout')
|
self.emit('launch-timeout')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def set_window(self, window):
|
def set_window(self, window):
|
||||||
"""An activity is 'launched' once we get its 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
|
self._launched = True
|
||||||
gobject.source_remove(self._launch_timeout_id)
|
gobject.source_remove(self._launch_timeout_id)
|
||||||
self._launch_timeout_id = 0
|
self._launch_timeout_id = 0
|
||||||
@ -74,17 +74,8 @@ class HomeActivity(gobject.GObject):
|
|||||||
self._window = window
|
self._window = window
|
||||||
self._xid = window.get_xid()
|
self._xid = window.get_xid()
|
||||||
|
|
||||||
bus = dbus.SessionBus()
|
def set_service(self, service):
|
||||||
self._service = bus.get_object(_ACTIVITY_SERVICE_NAME + '%d' % self._xid,
|
self._service = service
|
||||||
_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 get_service(self):
|
def get_service(self):
|
||||||
return self._service
|
return self._service
|
||||||
@ -95,17 +86,18 @@ class HomeActivity(gobject.GObject):
|
|||||||
return self._window.get_name()
|
return self._window.get_name()
|
||||||
|
|
||||||
def get_icon_name(self):
|
def get_icon_name(self):
|
||||||
return self._icon_name
|
return self._bundle.get_icon()
|
||||||
|
|
||||||
def get_icon_color(self):
|
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:
|
if activity != None:
|
||||||
return XoColor(activity.get_color())
|
return XoColor(activity.get_color())
|
||||||
else:
|
else:
|
||||||
return profile.get_color()
|
return profile.get_color()
|
||||||
|
|
||||||
def get_id(self):
|
def get_activity_id(self):
|
||||||
return self._id
|
return self._activity_id
|
||||||
|
|
||||||
def get_xid(self):
|
def get_xid(self):
|
||||||
if not self._launched:
|
if not self._launched:
|
||||||
@ -118,7 +110,7 @@ class HomeActivity(gobject.GObject):
|
|||||||
return self._window
|
return self._window
|
||||||
|
|
||||||
def get_type(self):
|
def get_type(self):
|
||||||
return self._type
|
return self._bundle.get_service_name()
|
||||||
|
|
||||||
def get_shared(self):
|
def get_shared(self):
|
||||||
if not self._launched:
|
if not self._launched:
|
||||||
|
@ -21,10 +21,11 @@ import wnck
|
|||||||
import dbus
|
import dbus
|
||||||
|
|
||||||
from model.homeactivity import HomeActivity
|
from model.homeactivity import HomeActivity
|
||||||
|
from model.homerawwindow import HomeRawWindow
|
||||||
from sugar.activity import bundleregistry
|
from sugar.activity import bundleregistry
|
||||||
|
|
||||||
_ACTIVITY_SERVICE_NAME = "org.laptop.Activity"
|
_SERVICE_NAME = "org.laptop.Activity"
|
||||||
_ACTIVITY_SERVICE_PATH = "/org/laptop/Activity"
|
_SERVICE_PATH = "/org/laptop/Activity"
|
||||||
|
|
||||||
class HomeModel(gobject.GObject):
|
class HomeModel(gobject.GObject):
|
||||||
|
|
||||||
@ -116,15 +117,28 @@ class HomeModel(gobject.GObject):
|
|||||||
logging.error('Model for window %d does not exist.' % xid)
|
logging.error('Model for window %d does not exist.' % xid)
|
||||||
|
|
||||||
self.emit('active-activity-changed', self._current_activity)
|
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):
|
def _add_activity(self, window):
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
xid = window.get_xid()
|
xid = window.get_xid()
|
||||||
act_service = bus.get_object(_ACTIVITY_SERVICE_NAME + '%d' % xid,
|
try:
|
||||||
_ACTIVITY_SERVICE_PATH + "/%s" % xid)
|
service = bus.get_object(_SERVICE_NAME + '%d' % xid,
|
||||||
act_id = act_service.get_id()
|
_SERVICE_PATH + "/%s" % xid)
|
||||||
|
except dbus.DBusException:
|
||||||
|
service = None
|
||||||
|
|
||||||
|
if not service:
|
||||||
|
self._add_window(window)
|
||||||
|
return
|
||||||
|
|
||||||
activity = None
|
activity = None
|
||||||
|
act_id = service.get_id()
|
||||||
|
act_type = service.get_service_name()
|
||||||
if self._activities.has_key(act_id):
|
if self._activities.has_key(act_id):
|
||||||
activity = self._activities[act_id]
|
activity = self._activities[act_id]
|
||||||
else:
|
else:
|
||||||
@ -138,6 +152,7 @@ class HomeModel(gobject.GObject):
|
|||||||
activity = HomeActivity(bundle, act_id)
|
activity = HomeActivity(bundle, act_id)
|
||||||
self._activities[act_id] = activity
|
self._activities[act_id] = activity
|
||||||
|
|
||||||
|
activity.set_service(service)
|
||||||
activity.set_window(window)
|
activity.set_window(window)
|
||||||
self.emit('activity-added', activity)
|
self.emit('activity-added', activity)
|
||||||
|
|
||||||
@ -146,7 +161,7 @@ class HomeModel(gobject.GObject):
|
|||||||
self._current_activity = None
|
self._current_activity = None
|
||||||
|
|
||||||
self.emit('activity-removed', activity)
|
self.emit('activity-removed', activity)
|
||||||
act_id = activity.get_id()
|
act_id = activity.get_activity_id()
|
||||||
del self._activities[act_id]
|
del self._activities[act_id]
|
||||||
|
|
||||||
def _remove_activity(self, xid):
|
def _remove_activity(self, xid):
|
||||||
@ -157,7 +172,7 @@ class HomeModel(gobject.GObject):
|
|||||||
logging.error('Model for window %d does not exist.' % xid)
|
logging.error('Model for window %d does not exist.' % xid)
|
||||||
|
|
||||||
def _activity_launch_timeout_cb(self, activity):
|
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():
|
if not act_id in self._activities.keys():
|
||||||
return
|
return
|
||||||
self._internal_remove_activity(activity)
|
self._internal_remove_activity(activity)
|
||||||
|
@ -57,5 +57,5 @@ class ShellService(dbus.service.Object):
|
|||||||
def _cur_activity_changed_cb(self, owner, new_activity):
|
def _cur_activity_changed_cb(self, owner, new_activity):
|
||||||
new_id = ""
|
new_id = ""
|
||||||
if new_activity:
|
if new_activity:
|
||||||
new_id = new_activity.get_id()
|
new_id = new_activity.get_activity_id()
|
||||||
self.CurrentActivityChanged(new_id)
|
self.CurrentActivityChanged(new_id)
|
||||||
|
@ -38,7 +38,6 @@ class ActivityChatWindow(gtk.Window):
|
|||||||
class ActivityHost:
|
class ActivityHost:
|
||||||
def __init__(self, model):
|
def __init__(self, model):
|
||||||
self._model = model
|
self._model = model
|
||||||
self._id = model.get_id()
|
|
||||||
self._window = model.get_window()
|
self._window = model.get_window()
|
||||||
self._activity = model.get_service()
|
self._activity = model.get_service()
|
||||||
self._gdk_window = gtk.gdk.window_foreign_new(self.get_xid())
|
self._gdk_window = gtk.gdk.window_foreign_new(self.get_xid())
|
||||||
@ -57,7 +56,7 @@ class ActivityHost:
|
|||||||
self._frame_was_visible = False
|
self._frame_was_visible = False
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
return self._id
|
return self._model.get_activity_id()
|
||||||
|
|
||||||
def get_xid(self):
|
def get_xid(self):
|
||||||
return self._window.get_xid()
|
return self._window.get_xid()
|
||||||
|
@ -110,7 +110,7 @@ class FriendsBox(hippo.CanvasBox):
|
|||||||
|
|
||||||
def _active_activity_changed_cb(self, home_model, home_activity):
|
def _active_activity_changed_cb(self, home_model, home_activity):
|
||||||
if 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)
|
ps = self._pservice.get_activity(activity_id)
|
||||||
self._set_activity_ps(ps)
|
self._set_activity_ps(ps)
|
||||||
else:
|
else:
|
||||||
|
@ -141,7 +141,7 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
|
|
||||||
def _activity_added_cb(self, model, activity):
|
def _activity_added_cb(self, model, activity):
|
||||||
# Mark the activity as launched
|
# Mark the activity as launched
|
||||||
act_id = activity.get_id()
|
act_id = activity.get_activity_id()
|
||||||
if not self._activities.has_key(act_id):
|
if not self._activities.has_key(act_id):
|
||||||
self._add_activity(activity)
|
self._add_activity(activity)
|
||||||
icon = self._activities[act_id]
|
icon = self._activities[act_id]
|
||||||
@ -154,7 +154,7 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
self.emit_paint_needed(0, 0, -1, -1)
|
self.emit_paint_needed(0, 0, -1, -1)
|
||||||
|
|
||||||
def _remove_activity(self, activity):
|
def _remove_activity(self, activity):
|
||||||
act_id = activity.get_id()
|
act_id = activity.get_activity_id()
|
||||||
if not self._activities.has_key(act_id):
|
if not self._activities.has_key(act_id):
|
||||||
return
|
return
|
||||||
icon = self._activities[act_id]
|
icon = self._activities[act_id]
|
||||||
@ -167,7 +167,7 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
icon.connect('activated', self._activity_icon_clicked_cb)
|
icon.connect('activated', self._activity_icon_clicked_cb)
|
||||||
self.append(icon, hippo.PACK_FIXED)
|
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)
|
self.emit_paint_needed(0, 0, -1, -1)
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
if not icon.get_launched():
|
if not icon.get_launched():
|
||||||
return
|
return
|
||||||
|
|
||||||
activity_host = self._shell.get_activity(activity.get_id())
|
activity_host = self._shell.get_activity(activity.get_activity_id())
|
||||||
if activity_host:
|
if activity_host:
|
||||||
activity_host.present()
|
activity_host.present()
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for h_activity in self._model:
|
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_start, angle_end] = self._get_angles(i)
|
||||||
angle = angle_start + (angle_end - angle_start) / 2
|
angle = angle_start + (angle_end - angle_start) / 2
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user