Move window management keybindings inside sugar.

Add a TakeScreenshot dbus method and have the shell
call it when the activity can safely take a screenshot
to use as a preview.
This commit is contained in:
Marco Pesenti Gritti 2007-10-23 15:19:17 +02:00
parent 0daccca71f
commit f300006b76
7 changed files with 97 additions and 36 deletions

View File

@ -128,6 +128,7 @@ class ActivityToolbar(gtk.Toolbar):
self._activity.copy() self._activity.copy()
def __stop_clicked_cb(self, button): def __stop_clicked_cb(self, button):
self._activity.take_screenshot()
self._activity.close() self._activity.close()
def __jobject_updated_cb(self, jobject): def __jobject_updated_cb(self, jobject):
@ -461,6 +462,9 @@ class Activity(Window, gtk.Container):
else: else:
return {} return {}
def take_screenshot(self):
self._preview = self._get_preview()
def save(self): def save(self):
"""Request that the activity is saved to the Journal.""" """Request that the activity is saved to the Journal."""
@ -594,8 +598,6 @@ class Activity(Window, gtk.Container):
self._pservice.share_activity(self, private=private) self._pservice.share_activity(self, private=private)
def close(self): def close(self):
self._preview = self._get_preview()
self.save() self.save()
if self._shared_activity: if self._shared_activity:

View File

@ -64,3 +64,7 @@ class ActivityService(dbus.service.Object):
def Invite(self, buddy_key): def Invite(self, buddy_key):
self._activity.invite(buddy_key) self._activity.invite(buddy_key)
@dbus.service.method(_ACTIVITY_INTERFACE)
def TakeScreenshot(self):
self._activity.take_screenshot()

View File

@ -1,9 +1,3 @@
# This is the sugar keyboard configuration for matchbox # This is the sugar keyboard configuration for matchbox
### Window operation short cuts
<Alt>n=next
<Alt>p=prev
<Ctrl>escape=close
<Ctrl>Q=close
<Alt>return=fullscreen <Alt>return=fullscreen

View File

@ -70,6 +70,20 @@ class HomeModel(gobject.GObject):
screen.connect('active-window-changed', screen.connect('active-window-changed',
self._active_window_changed_cb) self._active_window_changed_cb)
def get_previous_activity(self):
i = self._activities.index(self._pending_activity)
if i > 0:
return self._activities[i - 1]
else:
return None
def get_next_activity(self):
i = self._activities.index(self._pending_activity)
if i < len(self._activities) - 1:
return self._activities[i + 1]
else:
return None
def get_pending_activity(self): def get_pending_activity(self):
"""Returns the activity that would be seen in the Activity zoom level """Returns the activity that would be seen in the Activity zoom level

View File

@ -72,6 +72,10 @@ class ActivityHost:
else: else:
logging.error('Invite failed, activity service not ') logging.error('Invite failed, activity service not ')
def toggle_fullscreen(self):
fullscreen = not self._window.is_fullscreen()
self._window.set_fullscreen(fullscreen)
def present(self): def present(self):
# wnck.Window.activate() expects a timestamp, but we don't # wnck.Window.activate() expects a timestamp, but we don't
# always have one, and libwnck will complain if we pass "0", # always have one, and libwnck will complain if we pass "0",

View File

@ -160,10 +160,20 @@ class Shell(gobject.GObject):
self._activities_starting.add(activity_type) self._activities_starting.add(activity_type)
activityfactory.create(activity_type) activityfactory.create(activity_type)
def take_activity_screenshot(self):
home_model = self._model.get_home()
service = home_model.get_active_activity().get_service()
service.TakeScreenshot()
def set_zoom_level(self, level): def set_zoom_level(self, level):
if level == self._model.get_zoom_level(): old_level = self._model.get_zoom_level()
if level == old_level:
return return
if old_level == ShellModel.ZOOM_ACTIVITY and \
not self.get_frame().visible:
self.take_activity_screenshot()
if level == ShellModel.ZOOM_ACTIVITY: if level == ShellModel.ZOOM_ACTIVITY:
if self._pending_host is not None: if self._pending_host is not None:
self._pending_host.present() self._pending_host.present()
@ -173,6 +183,29 @@ class Shell(gobject.GObject):
self._screen.toggle_showing_desktop(True) self._screen.toggle_showing_desktop(True)
self._home_window.set_zoom_level(level) self._home_window.set_zoom_level(level)
def toggle_activity_fullscreen(self):
if self._model.get_zoom_level() == ShellModel.ZOOM_ACTIVITY:
self.get_current_activity().toggle_fullscreen()
def activate_previous_activity(self):
home_model = self._model.get_home()
activity = home_model.get_previous_activity()
if activity:
self.take_activity_screenshot()
activity.get_window().activate(1)
def activate_next_activity(self):
home_model = self._model.get_home()
activity = home_model.get_next_activity()
if activity:
self.take_activity_screenshot()
activity.get_window().activate(1)
def close_current_activity(self):
self.take_activity_screenshot()
if self._model.get_zoom_level() == ShellModel.ZOOM_ACTIVITY:
self.get_current_activity().close()
def get_current_activity(self): def get_current_activity(self):
return self._current_host return self._current_host

View File

@ -53,8 +53,13 @@ _actions_table = {
'0xE0' : 'overlay', '0xE0' : 'overlay',
'0xEB' : 'rotate', '0xEB' : 'rotate',
'<alt>r' : 'rotate', '<alt>r' : 'rotate',
'<alt>Tab' : 'home',
'<alt>q' : 'quit_emulator', '<alt>q' : 'quit_emulator',
'<alt>tab' : 'next_window',
'<alt>n' : 'next_window',
'<ctrl><alt>tab' : 'previous_window',
'<alt>p' : 'previous_window',
'<ctrl>escape' : 'close_window',
'<ctrl>q' : 'close_window'
} }
class KeyHandler(object): class KeyHandler(object):
@ -103,6 +108,15 @@ class KeyHandler(object):
else: else:
hw_manager.set_display_mode(hardwaremanager.COLOR_MODE) hw_manager.set_display_mode(hardwaremanager.COLOR_MODE)
def handle_previous_window(self):
self._shell.activate_previous_activity()
def handle_next_window(self):
self._shell.activate_next_activity()
def handle_close_window(self):
self._shell.close_current_activity()
def handle_zoom_mesh(self): def handle_zoom_mesh(self):
self._shell.set_zoom_level(ShellModel.ZOOM_MESH) self._shell.set_zoom_level(ShellModel.ZOOM_MESH)
@ -166,10 +180,6 @@ class KeyHandler(object):
pid = int(os.environ['SUGAR_EMULATOR_PID']) pid = int(os.environ['SUGAR_EMULATOR_PID'])
os.kill(pid, signal.SIGTERM) os.kill(pid, signal.SIGTERM)
def handle_home(self):
# FIXME: finish alt+tab support
pass
def _key_pressed_cb(self, grabber, keycode, state): def _key_pressed_cb(self, grabber, keycode, state):
key = grabber.get_key(keycode, state) key = grabber.get_key(keycode, state)
logging.debug('_key_pressed_cb: %i %i %s' % (keycode, state, key)) logging.debug('_key_pressed_cb: %i %i %s' % (keycode, state, key))