Ticket #3981: 0001-Handling-gestures-to-show-hide-the-frame.patch

File 0001-Handling-gestures-to-show-hide-the-frame.patch, 4.9 KB (added by erikos, 12 years ago)

Implementation in the shell (Frame hide missing)

  • bin/sugar-session

    From a654b57db59dc2df7730effe4794b29b3a1264c2 Mon Sep 17 00:00:00 2001
    From: Simon Schampijer <simon@laptop.org>
    Date: Thu, 4 Oct 2012 11:35:52 +0200
    Subject: [PATCH shell] Handling gestures to show/hide the frame
    
    We use SugarExt.GestureGrabber to listen for gestures
    on the root window. Swiping from the frame area towards
    the center does reveal the Frame. Swiping from the
    center and ending the swipe on the Frame area does
    hide the Frame.
    
    Signed-off-by: Simon Schampijer <simon@laptop.org>
    ---
     bin/sugar-session                 |  7 ++++
     src/jarabe/view/Makefile.am       |  1 +
     src/jarabe/view/gesturehandler.py | 78 +++++++++++++++++++++++++++++++++++++++
     3 files changed, 86 insertions(+)
     create mode 100644 src/jarabe/view/gesturehandler.py
    
    diff --git a/bin/sugar-session b/bin/sugar-session
    index 1519a20..42e7beb 100755
    a b def setup_keyhandler_cb(): 
    111111    from jarabe import frame
    112112    keyhandler.setup(frame.get_view())
    113113
     114def setup_gesturehandler_cb():
     115    logging.debug('STARTUP: setup_gesturehandler_cb')
     116    from jarabe.view import gesturehandler
     117    from jarabe import frame
     118    gesturehandler.setup(frame.get_view())
     119
    114120def setup_journal_cb():
    115121    logging.debug('STARTUP: setup_journal_cb')
    116122    from jarabe.journal import journalactivity
    def bootstrap(): 
    210216
    211217    GObject.idle_add(setup_frame_cb)
    212218    GObject.idle_add(setup_keyhandler_cb)
     219    GObject.idle_add(setup_gesturehandler_cb)
    213220    GObject.idle_add(setup_journal_cb)
    214221    GObject.idle_add(setup_notification_service_cb)
    215222    GObject.idle_add(setup_file_transfer_cb)
  • src/jarabe/view/Makefile.am

    diff --git a/src/jarabe/view/Makefile.am b/src/jarabe/view/Makefile.am
    index 630f184..1e8b0eb 100644
    a b sugar_PYTHON = \ 
    44        buddyicon.py                    \
    55        buddymenu.py                    \
    66        customizebundle.py              \
     7        gesturehandler.py               \
    78        keyhandler.py                   \
    89        launcher.py                     \
    910        palettes.py                     \
  • new file src/jarabe/view/gesturehandler.py

    diff --git a/src/jarabe/view/gesturehandler.py b/src/jarabe/view/gesturehandler.py
    new file mode 100644
    index 0000000..a9e2bcf
    - +  
     1# Copyright (C) 2012 One Laptop Per Child
     2#
     3# This program is free software; you can redistribute it and/or modify
     4# it under the terms of the GNU General Public License as published by
     5# the Free Software Foundation; either version 2 of the License, or
     6# (at your option) any later version.
     7#
     8# This program is distributed in the hope that it will be useful,
     9# but WITHOUT ANY WARRANTY; without even the implied warranty of
     10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11# GNU General Public License for more details.
     12#
     13# You should have received a copy of the GNU General Public License
     14# along with this program; if not, write to the Free Software
     15# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     16
     17from gi.repository import Gdk
     18
     19from gi.repository import SugarExt
     20from gi.repository import SugarGestures
     21
     22from sugar3.graphics import style
     23
     24_instance = None
     25
     26
     27class GestureHandler(object):
     28    '''Handling gestures to show/hide the frame
     29
     30    We use SugarExt.GestureGrabber to listen for
     31    gestures on the root window. Swiping from
     32    the frame area towards the center does reveal
     33    the Frame. Swiping from the center and ending
     34    the swipe on the Frame area does hide the
     35    Frame.
     36
     37    '''
     38    def __init__(self, frame):
     39        self._frame = frame
     40
     41        self._gesture_grabber = SugarExt.GestureGrabber()
     42
     43        # top, bottom, left, right
     44        self._create_grabber(0, 0, Gdk.Screen.width(), style.GRID_CELL_SIZE,
     45                             SugarGestures.SwipeDirection.DOWN)
     46        self._create_grabber(0, Gdk.Screen.height() - style.GRID_CELL_SIZE,
     47                             Gdk.Screen.width(), style.GRID_CELL_SIZE,
     48                             SugarGestures.SwipeDirection.UP)
     49        self._create_grabber(0, 0, style.GRID_CELL_SIZE, Gdk.Screen.height(),
     50                             SugarGestures.SwipeDirection.RIGHT)
     51        self._create_grabber(Gdk.Screen.width() - style.GRID_CELL_SIZE,
     52                             0, style.GRID_CELL_SIZE, Gdk.Screen.height(),
     53                             SugarGestures.SwipeDirection.LEFT)
     54
     55    def _create_grabber(self, x, y, width, height, desired_direction):
     56        rect = Gdk.Rectangle()
     57        rect.x = x
     58        rect.y = y
     59        rect.width = width
     60        rect.height = height
     61
     62        swipe = SugarGestures.SwipeController()
     63        swipe.connect('swipe-ended', self.__swipe_ended_cb,
     64                      desired_direction)
     65        self._gesture_grabber.add(swipe, rect)
     66
     67    def __swipe_ended_cb(self, controller, event_direction, desired_direction):
     68        if event_direction == desired_direction:
     69            self._frame.show()
     70
     71
     72def setup(frame):
     73    global _instance
     74
     75    if _instance:
     76        del _instance
     77
     78    _instance = GestureHandler(frame)