Gtk 4 and GtkGestureClick and Shift/Ctrl

So in new brave world of Gtk 4 we don’t rely on gesture signals from widget themselves, we attach controllers to them. All is fine and good, I even figured out how to listen to all mouse buttons, but now I am wondering how to get Ctrl/Shift keys used with clicks?

A GtkGestureClick is a GtkGestureSingle and a GtkGesture, so you will need to ask for the current event sequence, and ask for the modifier state of that sequence:

current_seq = gesture.get_current_sequence()
state = gesture.get_sequence_state(current_seq)

The state variable will hold the modifiers currently being set.

1 Like

Thanks for a hint, get_current_sequence() on GtkGestureClick object however returns None (which seems to be allowed by API) :thinking:

Where are you calling it? Can you give a small code fragment?

self.mouse_controller =
self.mouse_controller.connect("pressed", self.on_mouse_down)

def on_mouse_down(self, press_count, press_x, press_y, user_data):
      current_seq = self.mouse_controller.get_current_sequence()
      state = self.mouse_controller.get_sequence_state(current_seq)

Of course, I’m dumb. It’s not Gtk.Gesture.get_sequence_state(): it’s Gtk.EventController.get_current_event_state():

state = gesture.get_current_event_state()

Excellent, that’s what I need!
/writes it all down for eventual tutorial :smiley:

As it is quite related, and I did not want to create new thread:
If you have parent and add button to it, parent also gets clicks for this button. How to claim event in button callback? :thinking:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.