Ticket #3895: 0001-Tabbinghandler-port-the-tabbinghandler-to-the-new-GT.patch

File 0001-Tabbinghandler-port-the-tabbinghandler-to-the-new-GT.patch, 5.3 KB (added by erikos, 8 years ago)

Tabbinghandler: port the tabbinghandler to the new GTK+3 API

  • src/jarabe/view/tabbinghandler.py

    From 25f8b7c4553a85f8f90b807858b965ef4daa1f6a Mon Sep 17 00:00:00 2001
    From: Simon Schampijer <simon@laptop.org>
    Date: Thu, 13 Dec 2012 19:50:56 +0100
    Subject: [PATCH shell] Tabbinghandler: port the tabbinghandler to the new
     GTK+3 API, SL #3895
    
    gdk-keyboard-grab [1] and gdk-pointer-grab [2] have been deprecated,
    we have to use gdk_device_grab [3] now in order to grab the events. This
    patch does the port to the new API.
    
    We also switch to gdk_window_get_device_position instead of
    gdk_window_get_pointer [4].
    
    This patch needs as well a fix for the keygrabber (toolkit) to handle
    XI2 key events in order to work.
    
    [1] http://developer.gnome.org/gdk3/stable/gdk3-General.html#gdk-keyboard-grab
    [2] http://developer.gnome.org/gdk3/stable/gdk3-General.html#gdk-pointer-grab
    [3] http://developer.gnome.org/gdk3/stable/GdkDevice.html#gdk-device-grab
    [4] http://developer.gnome.org/gdk3/stable/gdk3-Windows.html#gdk-window-get-pointer
    
    Signed-off-by: Simon Schampijer <simon@laptop.org>
    ---
     src/jarabe/view/tabbinghandler.py | 51 +++++++++++++++++++++++++++++----------
     1 file changed, 38 insertions(+), 13 deletions(-)
    
    diff --git a/src/jarabe/view/tabbinghandler.py b/src/jarabe/view/tabbinghandler.py
    index 0d42c3f..66dd7ca 100644
    a b class TabbingHandler(object): 
    3232        self._tabbing = False
    3333        self._modifier = modifier
    3434        self._timeout = None
    35 
    36     def _start_tabbing(self):
     35        self._keyboard = None
     36        self._mouse = None
     37
     38        display = Gdk.Display.get_default()
     39        device_manager = display.get_device_manager()
     40        devices = device_manager.list_devices(Gdk.DeviceType.MASTER)
     41        for device in devices:
     42            if device.get_source() == Gdk.InputSource.KEYBOARD:
     43                self._keyboard = device
     44            if device.get_source() == Gdk.InputSource.MOUSE:
     45                self._mouse = device
     46
     47    def _start_tabbing(self, event_time):
    3748        if not self._tabbing:
    3849            logging.debug('Grabing the input.')
    3950
    4051            screen = Gdk.Screen.get_default()
    4152            window = screen.get_root_window()
    42             keyboard_grab_result = Gdk.keyboard_grab(window, False)
    43             pointer_grab_result = Gdk.pointer_grab(window)
     53
     54            keyboard_grab_result = self._keyboard.grab(window,
     55                                                       Gdk.GrabOwnership.WINDOW,
     56                                                       False,
     57                                                       Gdk.EventMask.KEY_PRESS_MASK |
     58                                                       Gdk.EventMask.KEY_RELEASE_MASK,
     59                                                       None,
     60                                                       event_time)
     61
     62            mouse_grab_result = self._mouse.grab(window,
     63                                                 Gdk.GrabOwnership.WINDOW,
     64                                                 False,
     65                                                 Gdk.EventMask.BUTTON_PRESS_MASK |
     66                                                 Gdk.EventMask.BUTTON_RELEASE_MASK,
     67                                                 None,
     68                                                 event_time)
    4469
    4570            self._tabbing = (keyboard_grab_result == Gdk.GrabStatus.SUCCESS and
    46                              pointer_grab_result == Gdk.GrabStatus.SUCCESS)
     71                             mouse_grab_result == Gdk.GrabStatus.SUCCESS)
    4772
    4873            # Now test that the modifier is still active to prevent race
    4974            # conditions. We also test if one of the grabs failed.
    50             mask = window.get_pointer()[2]
     75            mask = window.get_device_position(self._mouse)[3]
    5176            if not self._tabbing or not (mask & self._modifier):
    5277                logging.debug('Releasing grabs again.')
    5378
    5479                # ungrab keyboard/pointer if the grab was successfull.
    5580                if keyboard_grab_result == Gdk.GrabStatus.SUCCESS:
    56                     Gdk.keyboard_ungrab()
    57                 if pointer_grab_result == Gdk.GrabStatus.SUCCESS:
    58                     Gdk.pointer_ungrab()
     81                    self._keyboard.ungrab(event_time)
     82                if mouse_grab_result == Gdk.GrabStatus.SUCCESS:
     83                    self._mouse.ungrab(event_time)
    5984
    6085                self._tabbing = False
    6186            else:
    class TabbingHandler(object): 
    85110    def next_activity(self, event_time):
    86111        if not self._tabbing:
    87112            first_switch = True
    88             self._start_tabbing()
     113            self._start_tabbing(event_time)
    89114        else:
    90115            first_switch = False
    91116
    class TabbingHandler(object): 
    108133    def previous_activity(self, event_time):
    109134        if not self._tabbing:
    110135            first_switch = True
    111             self._start_tabbing()
     136            self._start_tabbing(event_time)
    112137        else:
    113138            first_switch = False
    114139
    class TabbingHandler(object): 
    134159            next_activity.get_window().activate(event_time)
    135160
    136161    def stop(self, event_time):
    137         Gdk.keyboard_ungrab()
    138         Gdk.pointer_ungrab()
     162        self._keyboard.ungrab(event_time)
     163        self._mouse.ungrab(event_time)
    139164        self._tabbing = False
    140165
    141166        self._frame.hide()