def editing_started(self, renderer, editable, path):
        if not self.teaching:
            self.path = path
            device = Gtk.get_current_event_device()
            if device.get_source() == Gdk.InputSource.KEYBOARD:
                self.keyboard = device
            else:
                self.keyboard = device.get_associated_device()

            self.keyboard.grab(self.a_widget.get_window(), Gdk.GrabOwnership.WINDOW, False,
                               Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK,
                               None, Gdk.CURRENT_TIME)

            editable.set_text(_("Pick an accelerator"))
            # NOTE: Set to expand horizontally because in certain versions of GTK
            # the unbelievable idiotic editable Gtk.Entry inside the Gtk.CellRendererText
            # can't decide where the frak to place itself! ¬¬
            # So, expand it so the freaking text can be seen!!!!!!!
            editable.set_hexpand(True)
            self.accel_editable = editable

            self.release_event_id = self.accel_editable.connect(
                "key-release-event", self.on_key_release)
            self.press_event_id = self.accel_editable.connect("key-press-event", self.on_key_press)
            self.focus_id = self.accel_editable.connect("focus-out-event", self.on_focus_out)
            self.teaching = True
        else:
            self.ungrab()
            self.update_label()
            self.teaching = False
Beispiel #2
0
    def on_button_clicked(self, widget):
        screen = widget.get_screen()
        self.time = Gtk.get_current_event_time()
        self.device = Gtk.get_current_event_device()

        self.grab_widget = Gtk.Window(Gtk.WindowType.POPUP)
        self.grab_widget.set_screen(screen)
        self.grab_widget.resize(1, 1)
        self.grab_widget.move(-100, -100)
        self.grab_widget.show()

        self.grab_widget.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.POINTER_MOTION_MASK)
        toplevel = widget.get_toplevel()

        if isinstance(toplevel, Gtk.Window):
            if toplevel.has_group():
                toplevel.add_window(grab_widget)

        window = self.grab_widget.get_window()

        picker_cursor = Gdk.Cursor(screen.get_display(), Gdk.CursorType.CROSSHAIR);

        grab_status = self.device.grab(window, Gdk.GrabOwnership.APPLICATION, False,
                                       Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.POINTER_MOTION_MASK,
                                       picker_cursor, self.time)

        if grab_status != Gdk.GrabStatus.SUCCESS:
            return

        Gtk.device_grab_add(self.grab_widget, self.device, True)

        self.bp_handler = self.grab_widget.connect("button-press-event", self.mouse_press)
        self.kp_handler = self.grab_widget.connect("key-press-event", self.key_press)
Beispiel #3
0
    def editing_started(self, renderer, editable, path):
        if not self.teaching:
            self.cur_val = self.get_label()
            self.path = path
            device = Gtk.get_current_event_device()
            if device.get_source() == Gdk.InputSource.KEYBOARD:
                self.keyboard = device
            else:
                self.keyboard = device.get_associated_device()

            self.keyboard.grab(
                self.treeview.get_window(),
                Gdk.GrabOwnership.WINDOW,
                False,
                Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK,
                None,
                Gdk.CURRENT_TIME,
            )

            editable.set_text(_("Pick an accelerator"))

            self.event_id = self.treeview.connect("key-release-event", self.on_key_release)
            self.teaching = True
        else:
            if self.event_id:
                self.treeview.disconnect(self.event_id)
            self.ungrab()
            self.set_label()
            self.teaching = False
Beispiel #4
0
    def _add_grab(self):
        window = self.get_window()

        dev = Gtk.get_current_event_device()
        grab_val = dev.grab(window, Gdk.GrabOwnership.WINDOW, True,
            Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK,
            None, Gtk.get_current_event_time())
        if grab_val == Gdk.GrabStatus.SUCCESS:
            self.grab_add()
 def on_keypress(self, widget, event):
     grab = False
     device = Gtk.get_current_event_device()
     if device.get_source() == Gdk.InputSource.KEYBOARD:
         grab = Gdk.Display.get_default().device_is_grabbed(device)
     if not grab and event.keyval == Gdk.KEY_BackSpace and (type(self.window.get_focus()) not in
                 (Gtk.TreeView, Gtk.Entry, Gtk.SpinButton, Gtk.TextView)):
         self.back_to_icon_view(None)
         return True
     return False
Beispiel #6
0
    def dialog_key_press_cb(self, source, event):

        keyval = event.keyval
        modifier_mask = event.state & gtk.accelerator_get_default_mod_mask()

        if gtk.accelerator_valid(keyval, modifier_mask):
            self.set_value(gtk.accelerator_name(keyval, modifier_mask))
            self.emit('changed')
            gdk.Device.ungrab(gtk.get_current_event_device(), gtk.get_current_event_time())
            self.dialog.hide()
Beispiel #7
0
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]
Beispiel #8
0
    def clicked_cb(self, source):

        self.dialog.show_all()

        device = gtk.get_current_event_device()
        window = self.dialog.get_window()
        ownership = gdk.GrabOwnership.NONE
        t = gtk.get_current_event_time()
        while gdk.Device.grab(device, window, ownership, False, 0, None, t) != gdk.GrabStatus.SUCCESS:
            time.sleep(0.1)
        self.dialog.run()
        self.dialog.hide()
Beispiel #9
0
    def __undisplay(self, *args, **kwargs):
        if not self.__view:
            return

        send_leave = kwargs.pop("send_leave", True)

        # XXXXXXXX!: for overlay scrollbars the parent scrolled window
        # listens to notify-leave events to hide them. In case we show
        # the tooltip and leave the SW through the tooltip the SW will never
        # get an event and the scrollbar stays visible forever.
        # This creates a half broken leave event which is just enough
        # to make this work.
        parent = self.__view.get_parent()
        fake_event = None
        if parent and isinstance(parent, Gtk.ScrolledWindow) and send_leave:
            fake_event = Gdk.Event.new(Gdk.EventType.LEAVE_NOTIFY)
            fake_event.any.window = parent.get_window()
            struct = fake_event.crossing
            struct.time = Gtk.get_current_event_time()
            ok, state = Gtk.get_current_event_state()
            if ok:
                struct.state = state
            device = Gtk.get_current_event_device()
            if device is not None:
                struct.set_device(device)

        if self.__current_renderer and self.__edit_id:
            self.__current_renderer.disconnect(self.__edit_id)
        self.__current_renderer = self.__edit_id = None
        self.__current_path = self.__current_col = None
        self.__view = None

        def hide(fake_event):
            if fake_event is not None:
                Gtk.main_do_event(fake_event)

            self.__hide_id = None
            self.hide()
            return False

        if gtk_version < (3, 13):
            # https://bugzilla.gnome.org/show_bug.cgi?id=731055
            # Work around Gnome Shell redraw bugs: it doesn't like
            # multiple hide()/show(), so we try to reduce calls to hide
            # by aborting it if the pointer is on a new cell shortly after.
            self.__hide_id = GLib.timeout_add(20, hide, fake_event)
        else:
            # mutter3.12 and gtk3.14 are a bit broken together, so it's safe
            # to assume we have a fixed mutter release..
            hide(fake_event)
Beispiel #10
0
 def translate_enter_leave_event(event):
     # enter/leave events have different x/y values as motion events
     # so it makes sense to push them to the underlying view as
     # additional motion events.
     # Warning: this may result in motion events outside of the
     # view window.. ?
     new_event = Gdk.Event.new(Gdk.EventType.MOTION_NOTIFY)
     struct = new_event.motion
     for attr in ["x", "y", "x_root", "y_root", "time", "window", "state", "send_event"]:
         setattr(struct, attr, getattr(event.crossing, attr))
     device = Gtk.get_current_event_device()
     if device is not None:
         struct.set_device(device)
     return new_event
Beispiel #11
0
    def _get_screen_color(self):
        time = Gtk.get_current_event_time()
        screen = self.__editor._pick_button.get_screen()
        display = self.__editor._pick_button.get_display()

        # XXX(JFlesch): Assumption: mouse is used
        pointer_device = Gtk.get_current_event_device()

        if not self.__dropper_grab_widget:
            self.__dropper_grab_widget = Gtk.Window.new(Gtk.WindowType.POPUP)
            self.__dropper_grab_widget.set_screen(screen)
            self.__dropper_grab_widget.resize(1, 1)
            self.__dropper_grab_widget.move(-100, -100)
            self.__dropper_grab_widget.show()
            self.__dropper_grab_widget.add_events(
                Gdk.EventMask.BUTTON_RELEASE_MASK
            )
            toplevel = self.__editor._pick_button.get_toplevel()

            if isinstance(toplevel, Gtk.Window):
                if toplevel.has_group():
                    toplevel.get_group().add_window(self.__dropper_grab_widget)

        window = self.__dropper_grab_widget.get_window()

        picker_cursor = self._make_picker_cursor(display)
        if (pointer_device.grab(
                window,
                Gdk.GrabOwnership.APPLICATION, False,
                Gdk.EventMask.BUTTON_RELEASE_MASK,
                picker_cursor, time) != Gdk.GrabStatus.SUCCESS):
            logger.warning("Pointer device grab failed !")
            return

        Gtk.device_grab_add(self.__dropper_grab_widget, pointer_device, True)

        self.__grab_time = time
        self.__pointer_device = pointer_device
        self.__has_grab = True

        self.__dropper_grab_widget.connect("button-release-event",
                                           self._on_mouse_release)
    def clicked(self, widget):
        if not self.teaching:
            device = Gtk.get_current_event_device()
            if device.get_source() == Gdk.InputSource.KEYBOARD:
                self.keyboard = device
            else:
                self.keyboard = device.get_associated_device()

            self.keyboard.grab(self.get_window(), Gdk.GrabOwnership.WINDOW, False,
                               Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK,
                               None, Gdk.CURRENT_TIME)

            self.button.set_label(_("Pick an accelerator"))
            self.event_id = self.connect( "key-release-event", self.on_key_release )
            self.teaching = True
        else:
            if self.event_id:
                self.disconnect(self.event_id)
            self.ungrab()
            self.set_button_text()
            self.teaching = False
Beispiel #13
0
    def editing_started(self, renderer, editable, path):
        if not self.teaching:
            self.path = path
            device = Gtk.get_current_event_device()
            if device.get_source() == Gdk.InputSource.KEYBOARD:
                self.keyboard = device
            else:
                self.keyboard = device.get_associated_device()

            self.keyboard.grab(self.a_widget.get_window(), Gdk.GrabOwnership.WINDOW, False,
                               Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK,
                               None, Gdk.CURRENT_TIME)

            editable.set_text(_("Pick an accelerator"))
            self.accel_editable = editable

            self.release_event_id = self.accel_editable.connect( "key-release-event", self.on_key_release )
            self.press_event_id = self.accel_editable.connect( "key-press-event", self.on_key_press )
            self.focus_id = self.accel_editable.connect( "focus-out-event", self.on_focus_out )
            self.teaching = True
        else:
            self.ungrab()
            self.update_label()
            self.teaching = False
Beispiel #14
0
 def _remove_grab(self):
     self.grab_remove()
     dev = Gtk.get_current_event_device()
     dev.ungrab(Gtk.get_current_event_time())