def window_grab(self, window): mask = gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK | gdk.POINTER_MOTION_MASK | gdk.POINTER_MOTION_HINT_MASK | gdk.ENTER_NOTIFY_MASK | gdk.LEAVE_NOTIFY_MASK gdk.pointer_grab(window.get_window(), owner_events=True, event_mask=mask) #also grab the keyboard so the user won't Alt-Tab away: gdk.keyboard_grab(window.get_window(), owner_events=False)
def popup_grab_on_window(self, window, activate_time): if gdk.pointer_grab(window, True, gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK | gdk.POINTER_MOTION_MASK, None, None, activate_time) == 0: if gdk.keyboard_grab (window, True, activate_time) == 0: return True else: gdk.pointer_ungrab(activate_time) return False return False
def popup_grab_on_window(self, window, activate_time): if gdk.pointer_grab( window, True, gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK | gdk.POINTER_MOTION_MASK, None, None, activate_time) == 0: if gdk.keyboard_grab(window, True, activate_time) == 0: return True else: gdk.pointer_ungrab(activate_time) return False return False
def _popup_grab_window(self): activate_time = 0L if gdk.pointer_grab(self._entry.window, True, (gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK | gdk.POINTER_MOTION_MASK), None, None, activate_time) == 0: if gdk.keyboard_grab(self._entry.window, True, activate_time) == 0: return True else: self._entry.window.get_display().pointer_ungrab(activate_time) return False return False
def popup_grab_window(self): activate_time = 0L if gdk.pointer_grab(self.popup_window.window, True, (gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK | gdk.POINTER_MOTION_MASK), None, None, activate_time) == 0: if gdk.keyboard_grab(self.popup_window.window, True, activate_time) == 0: return True else: self.popup_window.window.get_display().pointer_ungrab(activate_time); return False return False
def _popup_grab_window(self): activate_time = 0L window = self.get_window() if gdk.pointer_grab(window, True, (gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK | gdk.POINTER_MOTION_MASK), None, None, activate_time) == 0: if gdk.keyboard_grab(window, True, activate_time) == 0: return True else: window.pointer_ungrab(activate_time) return False return False
def establish_grab(self, t=0): # Grab, permitting normal interaction with the app (i.e. with the widgets # in the panel). mask = gdk.BUTTON_PRESS_MASK grab_result = gdk.pointer_grab(self.window, True, mask, None, None, t) if grab_result != gdk.GRAB_SUCCESS: print "pointer grab failed:", grab_result return False # Keyboard grab too, to prevent workspace switching. grab_result = gdk.keyboard_grab(self.window, False, t) if grab_result != gdk.GRAB_SUCCESS: print "keyboard grab failed:", grab_result gdk.pointer_ungrab() return False # But limit events to just the panel for neatness and a hint of modality. self.grab_add() self._grabbed = True return True
def establish_grab(self, t=0): # Grab, permitting normal interaction with the app (i.e. with the widgets # in the panel). mask = gdk.BUTTON_PRESS_MASK gdk_window = self.get_window() grab_result = gdk.pointer_grab(gdk_window, True, mask, None, None, t) if grab_result != gdk.GRAB_SUCCESS: logger.warning("pointer grab failed: %r", grab_result) return False # Keyboard grab too, to prevent workspace switching. grab_result = gdk.keyboard_grab(gdk_window, False, t) if grab_result != gdk.GRAB_SUCCESS: logger.warning("keyboard grab failed: %r", grab_result) gdk.pointer_ungrab(gdk.CURRENT_TIME) return False # But limit events to just the panel for neatness and a hint of modality. self.grab_add() self._grabbed = True return True
def _start_drag(self, tdw, event): # Attempt to start a new drag, calling drag_start_cb() if successful. if self.in_drag: return if hasattr(event, "x"): self.start_x = event.x self.start_y = event.y else: #last_x, last_y = tdw.get_pointer() last_t, last_x, last_y = self.doc.get_last_event_info(tdw) self.start_x = last_x self.start_y = last_y tdw_window = tdw.get_window() event_mask = (gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK | gdk.POINTER_MOTION_MASK) cursor = self.active_cursor if cursor is None: cursor = self.inactive_cursor # Grab the pointer grab_status = gdk.pointer_grab(tdw_window, False, event_mask, None, cursor, event.time) if grab_status != gdk.GRAB_SUCCESS: logger.warning("pointer grab failed: %r", grab_status) logger.debug("gdk_pointer_is_grabbed(): %r", gdk.pointer_is_grabbed()) # There seems to be a race condition between this grab under # PyGTK/GTK2 and some other grab - possibly just the implicit grabs # on color selectors: https://gna.org/bugs/?20068 Only pointer # events are affected, and PyGI+GTK3 is unaffected. # # It's probably safest to exit the mode and not start the drag. # This condition should be rare enough for this to be a valid # approach: the irritation of having to click again to do something # should be far less than that of getting "stuck" in a drag. if self is self.doc.modes.top: logger.debug("Exiting mode") self.doc.modes.pop() # Sometimes a pointer ungrab is needed even though the grab # apparently failed to avoid the UI partially "locking up" with the # stylus (and only the stylus). Happens when WMs like Xfwm # intercept an <Alt>Button combination for window management # purposes. Results in gdk.GRAB_ALREADY_GRABBED, but this line is # necessary to avoid the rest of the UI becoming unresponsive even # though the canvas can be drawn on with the stylus. Are we # cancelling an implicit grab here, and why is it device specific? gdk.pointer_ungrab(event.time) return # We managed to establish a grab, so watch for it being broken. # This signal is disconnected when the mode leaves. connid = tdw.connect("grab-broken-event", self.tdw_grab_broken_cb) self._grab_broken_conninfo = (tdw, connid) # Grab the keyboard too, to be certain of getting the key release event # for a spacebar drag. grab_status = gdk.keyboard_grab(tdw_window, False, event.time) if grab_status != gdk.GRAB_SUCCESS: logger.warning("Keyboard grab failed: %r", grab_status) gdk.pointer_ungrab(event.time) if self is self.doc.modes.top: logger.debug("Exiting mode") self.doc.modes.pop() return # GTK too... tdw.grab_add() self._grab_widget = tdw # Drag has started, perform whatever action the mode needs. self.drag_start_cb(tdw, event)
def lock(self): pointer_grab(self.window.window, True) keyboard_grab(self.window.window, True)
def _start_drag(self, tdw, event): # Attempt to start a new drag, calling drag_start_cb() if successful. if self.in_drag: return if hasattr(event, "x"): self.start_x = event.x self.start_y = event.y else: #last_x, last_y = tdw.get_pointer() last_t, last_x, last_y = self.doc.get_last_event_info(tdw) self.start_x = last_x self.start_y = last_y tdw_window = tdw.get_window() event_mask = (gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK | gdk.POINTER_MOTION_MASK) cursor = self.active_cursor if cursor is None: cursor = self.inactive_cursor # Grab the pointer grab_status = gdk.pointer_grab(tdw_window, False, event_mask, None, cursor, event.time) if grab_status != gdk.GRAB_SUCCESS: logger.warning("pointer grab failed: %r", grab_status) logger.debug("gdk_pointer_is_grabbed(): %r", gdk.pointer_is_grabbed()) # There seems to be a race condition between this grab under # PyGTK/GTK2 and some other grab - possibly just the implicit grabs # on colour selectors: https://gna.org/bugs/?20068 Only pointer # events are affected, and PyGI+GTK3 is unaffected. # # It's probably safest to exit the mode and not start the drag. # This condition should be rare enough for this to be a valid # approach: the irritation of having to click again to do something # should be far less than that of getting "stuck" in a drag. if self is self.doc.modes.top: logger.debug("Exiting mode") self.doc.modes.pop() # Sometimes a pointer ungrab is needed even though the grab # apparently failed to avoid the UI partially "locking up" with the # stylus (and only the stylus). Happens when WMs like Xfwm # intercept an <Alt>Button combination for window management # purposes. Results in gdk.GRAB_ALREADY_GRABBED, but this line is # necessary to avoid the rest of the UI becoming unresponsive even # though the canvas can be drawn on with the stylus. Are we # cancelling an implicit grab here, and why is it device specific? gdk.pointer_ungrab(event.time) return # We managed to establish a grab, so watch for it being broken. # This signal is disconnected when the mode leaves. connid = tdw.connect("grab-broken-event", self.tdw_grab_broken_cb) self._grab_broken_conninfo = (tdw, connid) # Grab the keyboard too, to be certain of getting the key release event # for a spacebar drag. grab_status = gdk.keyboard_grab(tdw_window, False, event.time) if grab_status != gdk.GRAB_SUCCESS: logger.warning("Keyboard grab failed: %r", grab_status) gdk.pointer_ungrab(event.time) if self is self.doc.modes.top: logger.debug("Exiting mode") self.doc.modes.pop() return # GTK too... tdw.grab_add() self._grab_widget = tdw # Drag has started, perform whatever action the mode needs. self.drag_start_cb(tdw, event)