Ticket #3981: 0001-Frame-gesture-only-make-the-top-area-recognizing-the.patch

File 0001-Frame-gesture-only-make-the-top-area-recognizing-the.patch, 6.3 KB (added by erikos, 12 years ago)

Only the top area to invoke gesture

  • src/jarabe/view/gesturehandler.py

    From ebe5d2efd9fc92b30326d184745a2ff336c4fef6 Mon Sep 17 00:00:00 2001
    From: Simon Schampijer <simon@laptop.org>
    Date: Tue, 9 Oct 2012 20:48:26 +0200
    Subject: [PATCH shell] Frame gesture: only make the top area recognizing the
     gesture
    
    After testing and running into several trickier cases with
    the Activity canvas (SL #3994) we agreed on using only the
    area at the top to trigger the Frame. The same gesture is
    used to show/hide the Frame as we discovered that swiping
    towards the bezel is not as pleasant.
    
    Signed-off-by: Simon Schampijer <simon@laptop.org>
    ---
     src/jarabe/view/gesturehandler.py | 118 +++++++-------------------------------
     1 file changed, 22 insertions(+), 96 deletions(-)
    
    diff --git a/src/jarabe/view/gesturehandler.py b/src/jarabe/view/gesturehandler.py
    index 06fa044..47b9f8f 100644
    a b class GestureHandler(object): 
    2828    '''Handling gestures to show/hide the frame
    2929
    3030    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 towards one of the edges
    34     does hide the Frame.
     31    gestures on the root window. We use a toggle
     32    gesture to either hide or show the frame: Swiping
     33    from the frame area at the top towards the center
     34    does reveal the Frame or hide it.
    3535    '''
    3636
    37     _HIDE = 0
    38     _SHOW = 1
    39 
    4037    def __init__(self, frame):
    4138        self._frame = frame
    4239
    class GestureHandler(object): 
    5552        for controller in self._controller:
    5653            self._gesture_grabber.remove(controller)
    5754
    58         rectangle = self._create_rectangle(0, 0, Gdk.Screen.width(),
    59                                            style.GRID_CELL_SIZE)
    60         swipe = SugarGestures.SwipeController( \
    61             directions=SugarGestures.SwipeDirectionFlags.DOWN)
    62         swipe.connect('swipe-ended', self.__top_show_cb)
    63         self._gesture_grabber.add(swipe, rectangle)
    64 
    65         rectangle = self._create_rectangle(0, 0, Gdk.Screen.width(),
    66                                            style.GRID_CELL_SIZE * 2)
    67         swipe = SugarGestures.SwipeController( \
    68             directions=SugarGestures.SwipeDirectionFlags.UP)
    69         swipe.connect('swipe-ended', self.__top_hide_cb)
    70         self._gesture_grabber.add(swipe, rectangle)
    71 
    72         rectangle = self._create_rectangle( \
    73             0, Gdk.Screen.height() - style.GRID_CELL_SIZE,
    74             Gdk.Screen.width(), style.GRID_CELL_SIZE)
    75         swipe = SugarGestures.SwipeController( \
    76             directions=SugarGestures.SwipeDirectionFlags.UP)
    77         swipe.connect('swipe-ended', self.__bottom_show_cb)
    78         self._gesture_grabber.add(swipe, rectangle)
    79 
    80         rectangle = self._create_rectangle( \
    81             0, Gdk.Screen.height() - style.GRID_CELL_SIZE * 2,
    82             Gdk.Screen.width(), style.GRID_CELL_SIZE * 2)
    83         swipe = SugarGestures.SwipeController( \
    84             directions=SugarGestures.SwipeDirectionFlags.DOWN)
    85         swipe.connect('swipe-ended', self.__bottom_hide_cb)
    86         self._gesture_grabber.add(swipe, rectangle)
    87 
    88         rectangle = self._create_rectangle( \
    89                 0, 0, style.GRID_CELL_SIZE, Gdk.Screen.height())
    90         swipe = SugarGestures.SwipeController( \
    91             directions=SugarGestures.SwipeDirectionFlags.RIGHT)
    92         swipe.connect('swipe-ended', self.__left_show_cb)
     55        self._track_gesture_for_area(SugarGestures.SwipeDirectionFlags.DOWN,
     56                                     0, 0, Gdk.Screen.width(),
     57                                     style.GRID_CELL_SIZE)
     58
     59    def _track_gesture_for_area(self, directions, x, y, width, height):
     60        rectangle = Gdk.Rectangle()
     61        rectangle.x = x
     62        rectangle.y = y
     63        rectangle.width = width
     64        rectangle.height = height
     65        swipe = SugarGestures.SwipeController(directions=directions)
     66        swipe.connect('swipe-ended', self.__swipe_ended_cb)
    9367        self._gesture_grabber.add(swipe, rectangle)
     68        self._controller.append(swipe)
    9469
    95         rectangle = self._create_rectangle( \
    96                 0, 0, style.GRID_CELL_SIZE * 2, Gdk.Screen.height())
    97         swipe = SugarGestures.SwipeController( \
    98             directions=SugarGestures.SwipeDirectionFlags.LEFT)
    99         swipe.connect('swipe-ended', self.__left_hide_cb)
    100         self._gesture_grabber.add(swipe, rectangle)
    101 
    102         rectangle = self._create_rectangle( \
    103                 Gdk.Screen.width() - style.GRID_CELL_SIZE, 0,
    104                 style.GRID_CELL_SIZE, Gdk.Screen.height())
    105         swipe = SugarGestures.SwipeController( \
    106             directions=SugarGestures.SwipeDirectionFlags.LEFT)
    107         swipe.connect('swipe-ended', self.__right_show_cb)
    108         self._gesture_grabber.add(swipe, rectangle)
    109 
    110         rectangle = self._create_rectangle( \
    111                 Gdk.Screen.width() - style.GRID_CELL_SIZE * 2, 0,
    112                 style.GRID_CELL_SIZE * 2, Gdk.Screen.height())
    113         swipe = SugarGestures.SwipeController( \
    114             directions=SugarGestures.SwipeDirectionFlags.RIGHT)
    115         swipe.connect('swipe-ended', self.__right_hide_cb)
    116         self._gesture_grabber.add(swipe, rectangle)
    117 
    118     def _create_rectangle(self, x, y, width, height):
    119         rect = Gdk.Rectangle()
    120         rect.x = x
    121         rect.y = y
    122         rect.width = width
    123         rect.height = height
    124         return rect
    125 
    126     def __top_show_cb(self, controller, event_direction):
    127         self._frame.show()
    128 
    129     def __top_hide_cb(self, controller, event_direction):
    130         self._frame.hide()
    131 
    132     def __bottom_show_cb(self, controller, event_direction):
    133         self._frame.show()
    134 
    135     def __bottom_hide_cb(self, controller, event_direction):
    136         self._frame.hide()
    137 
    138     def __left_show_cb(self, controller, event_direction):
    139         self._frame.show()
    140 
    141     def __left_hide_cb(self, controller, event_direction):
    142         self._frame.hide()
    143 
    144     def __right_show_cb(self, controller, event_direction):
    145         self._frame.show()
    146 
    147     def __right_hide_cb(self, controller, event_direction):
    148         self._frame.hide()
     70    def __swipe_ended_cb(self, controller, event_direction):
     71        if self._frame.is_visible():
     72            self._frame.hide()
     73        else:
     74            self._frame.show()
    14975
    15076
    15177def setup(frame):