def window_ungrab_and_unmap(window, devices): """Takes the result of window_grab_and_map() and removes the grabs""" event_time = Gtk.get_current_event_time() for device in devices: Gtk.device_grab_remove(window, device) device.ungrab(event_time) window.hide() #gtk3.8 bug: https://bugzilla.gnome.org/show_bug.cgi?id=700185 window.unrealize()
def _on_mouse_release(self, invisible_widget, event): if not self.__has_grab: return try: color = self._grab_color_at_pointer(event.get_screen(), event.get_device(), event.x_root, event.y_root) self.__editor._color_chooser.set_rgba( Gdk.RGBA(red=color[0], green=color[1], blue=color[2], alpha=1.0)) finally: self.__pointer_device.ungrab(self.__grab_time) Gtk.device_grab_remove(self.__dropper_grab_widget, self.__pointer_device) self.__has_grab = False self.__pointer_device = None
def _on_mouse_release(self, invisible_widget, event): if not self.__has_grab: return try: color = self._grab_color_at_pointer( event.get_screen(), event.get_device(), event.x_root, event.y_root ) self.__editor._color_chooser.set_rgba( Gdk.RGBA( red=color[0], green=color[1], blue=color[2], alpha=1.0 ) ) finally: self.__pointer_device.ungrab(self.__grab_time) Gtk.device_grab_remove(self.__dropper_grab_widget, self.__pointer_device) self.__has_grab = False self.__pointer_device = None
def window_grab_and_map(window, mask): """Returns a list of devices that have a grab or an empty list if something failed. If somethings failed the window will be hidden. """ device = Gtk.get_current_event_device() event_time = Gtk.get_current_event_time() if not device: return [] # On wayland we need to grab before mapping and on X11 and everywhere else # we can grab after we are mapped if not is_wayland(): window.show() else: window.realize() Gtk.device_grab_add(window, device, True) status = device.grab( window.get_window(), Gdk.GrabOwnership.WINDOW, True, mask, None, event_time) if status != Gdk.GrabStatus.SUCCESS: Gtk.device_grab_remove(window, device) window.hide() return [] associated_device = device.get_associated_device() if associated_device is None: if is_wayland(): window.show() return [device] Gtk.device_grab_add(window, associated_device, True) status = associated_device.grab( window.get_window(), Gdk.GrabOwnership.WINDOW, True, mask, None, event_time) if status != Gdk.GrabStatus.SUCCESS: Gtk.device_grab_remove(window, associated_device) Gtk.device_grab_remove(window, device) device.ungrab(event_time) window.hide() return [] if is_wayland(): window.show() return [device, associated_device]
def ungrab(self, device): device.ungrab(self.time) Gtk.device_grab_remove(self.grab_widget, device) self.grab_widget.handler_disconnect(self.bp_handler) self.grab_widget.handler_disconnect(self.br_handler) self.grab_widget.handler_disconnect(self.kp_handler)