Skip to content

Gtk.GestureSingle

class — extends Gesture

A GtkGesture subclass optimized for singe-touch and mouse gestures.

Under interaction, these gestures stick to the first interacting sequence, which is accessible through GestureSingle.get_current_sequence while the gesture is being interacted with.

By default gestures react to both Gdk.BUTTON_PRIMARY and touch events. GestureSingle.set_touch_only can be used to change the touch behavior. Callers may also specify a different mouse button number to interact with through GestureSingle.set_button, or react to any mouse button by setting it to 0. While the gesture is active, the button being currently pressed can be known through GestureSingle.get_current_button.

Methods

get_button

def get_button(self) -> int

Returns the button number gesture listens for.

If this is 0, the gesture reacts to any button press.

get_current_button

def get_current_button(self) -> int

Returns the button number currently interacting with gesture, or 0 if there is none.

get_current_sequence

def get_current_sequence(self) -> Gdk.EventSequence | None

Returns the event sequence currently interacting with gesture.

This is only meaningful if Gesture.is_active returns True.

get_exclusive

def get_exclusive(self) -> bool

Gets whether a gesture is exclusive.

For more information, see GestureSingle.set_exclusive.

get_touch_only

def get_touch_only(self) -> bool

Returns True if the gesture is only triggered by touch events.

set_button

def set_button(self, button: int) -> None

Sets the button number gesture listens to.

If non-0, every button press from a different button number will be ignored. Touch events implicitly match with button 1.

Parameters:

  • button — button number to listen to, or 0 for any button

set_exclusive

def set_exclusive(self, exclusive: bool) -> None

Sets whether gesture is exclusive.

An exclusive gesture will only handle pointer and "pointer emulated" touch events, so at any given time, there is only one sequence able to interact with those.

Parameters:

  • exclusiveTrue to make gesture exclusive

set_touch_only

def set_touch_only(self, touch_only: bool) -> None

Sets whether to handle only touch events.

If touch_only is True, gesture will only handle events of type Gdk.EventType.TOUCH_BEGIN, Gdk.EventType.TOUCH_UPDATE or Gdk.EventType.TOUCH_END. If False, mouse events will be handled too.

Parameters:

  • touch_only — whether gesture handles only touch events

Properties

button

button: int  # read/write

Mouse button number to listen to, or 0 to listen for any button.

exclusive

exclusive: bool  # read/write

Whether the gesture is exclusive.

Exclusive gestures only listen to pointer and pointer emulated events.

touch_only

touch_only: bool  # read/write

Whether the gesture handles only touch events.