Ticket #3895: tab_simon.patch

File tab_simon.patch, 4.1 KB (added by erikos, 8 years ago)

testing patch with new API

  • src/jarabe/view/tabbinghandler.py

    diff --git a/src/jarabe/view/tabbinghandler.py b/src/jarabe/view/tabbinghandler.py
    index 0d42c3f..7029276 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:
    38             logging.debug('Grabing the input.')
     49            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            keyboard_grab_result = self._keyboard.grab(window, Gdk.GrabOwnership.WINDOW, False,
     54                                                       Gdk.EventMask.ALL_EVENTS_MASK, None,
     55                                                       event_time)
     56            mouse_grab_result = self._mouse.grab(window, Gdk.GrabOwnership.WINDOW, False,
     57                                                 Gdk.EventMask.ALL_EVENTS_MASK, None,
     58                                                 event_time)
    4459
    4560            self._tabbing = (keyboard_grab_result == Gdk.GrabStatus.SUCCESS and
    46                              pointer_grab_result == Gdk.GrabStatus.SUCCESS)
     61                             mouse_grab_result == Gdk.GrabStatus.SUCCESS)
    4762
    4863            # Now test that the modifier is still active to prevent race
    4964            # conditions. We also test if one of the grabs failed.
    50             mask = window.get_pointer()[2]
    51             if not self._tabbing or not (mask & self._modifier):
    52                 logging.debug('Releasing grabs again.')
     65            _pointer = window.get_pointer()
     66            # mask is in position 3 now
     67            mask = _pointer[3]
     68            logging.debug('==> pointer=%s mask=%s', _pointer, mask)
     69            if not self._tabbing or (mask in (0, self._modifier)):
     70                logging.debug('==> Releasing grabs again. mask=%s', mask)
    5371
    5472                # ungrab keyboard/pointer if the grab was successfull.
    5573                if keyboard_grab_result == Gdk.GrabStatus.SUCCESS:
    56                     Gdk.keyboard_ungrab()
    57                 if pointer_grab_result == Gdk.GrabStatus.SUCCESS:
    58                     Gdk.pointer_ungrab()
     74                    self._keyboard.ungrab(event_time)
     75                if mouse_grab_result == Gdk.GrabStatus.SUCCESS:
     76                    self._mouse.ungrab(event_time)
    5977
    6078                self._tabbing = False
    6179            else:
     80                logging.debug('==> show frame')
    6281                self._frame.show()
    6382
    6483    def __timeout_cb(self, event_time):
    class TabbingHandler(object): 
    85104    def next_activity(self, event_time):
    86105        if not self._tabbing:
    87106            first_switch = True
    88             self._start_tabbing()
     107            self._start_tabbing(event_time)
    89108        else:
    90109            first_switch = False
    91110
    class TabbingHandler(object): 
    108127    def previous_activity(self, event_time):
    109128        if not self._tabbing:
    110129            first_switch = True
    111             self._start_tabbing()
     130            self._start_tabbing(event_time)
    112131        else:
    113132            first_switch = False
    114133
    class TabbingHandler(object): 
    134153            next_activity.get_window().activate(event_time)
    135154
    136155    def stop(self, event_time):
    137         Gdk.keyboard_ungrab()
    138         Gdk.pointer_ungrab()
     156        logging.debug('===> stop tabbing')
     157        self._keyboard.ungrab(event_time)
     158        self._mouse.ungrab(event_time)
    139159        self._tabbing = False
    140160
    141161        self._frame.hide()