Class: Gtk::Gesture

Inherits:
EventController show all
Defined in:
(unknown)

Direct Known Subclasses

GestureRotate, GestureSingle, GestureZoom

Instance Method Summary collapse

Methods inherited from EventController

#current_event, #current_event_device, #current_event_state, #current_event_time, #name, #name=, #propagation_limit, #propagation_limit=, #propagation_phase, #propagation_phase=, #reset, #static_name=, #widget, #widget=

Instance Method Details

#deviceGdk::Device

Returns the logical GdkDevice that is currently operating on gesture.

This returns nil if the gesture is not being interacted.

Returns:

#get_bounding_box(rect) ⇒ Boolean

If there are touch sequences being currently handled by gesture, returns true and fills in rect with the bounding box containing all active touches.

Otherwise, false will be returned.

Note: This function will yield unexpected results on touchpad gestures. Since there is no correlation between physical and pixel distances, these will look as if constrained in an infinitely small area, rect width and height will thus be 0 regardless of the number of touchpoints.

Parameters:

  • rect (Gdk::Rectangle)

    bounding box containing all active touches.

Returns:

  • (Boolean)

    true if there are active touches, false otherwise

#get_bounding_box_center(x, y) ⇒ Boolean

If there are touch sequences being currently handled by gesture, returns true and fills in x and y with the center of the bounding box containing all active touches.

Otherwise, false will be returned.

Parameters:

  • x (Float)

    X coordinate for the bounding box center

  • y (Float)

    Y coordinate for the bounding box center

Returns:

  • (Boolean)

    false if no active touches are present, true otherwise

#get_last_event(sequence) ⇒ Gdk::Event

Returns the last event that was processed for sequence.

Note that the returned pointer is only valid as long as the sequence is still interpreted by the gesture. If in doubt, you should make a copy of the event.

Parameters:

  • sequence (Gdk::EventSequence)

    a GdkEventSequence

Returns:

#get_point(sequence, x, y) ⇒ Boolean

If sequence is currently being interpreted by gesture, returns true and fills in x and y with the last coordinates stored for that event sequence.

The coordinates are always relative to the widget allocation.

Parameters:

  • sequence (Gdk::EventSequence)

    a GdkEventSequence, or nil for pointer events

  • x (Float)

    return location for X axis of the sequence coordinates

  • y (Float)

    return location for Y axis of the sequence coordinates

Returns:

  • (Boolean)

    true if sequence is currently interpreted

#get_sequence_state(sequence) ⇒ Gtk::EventSequenceState

Returns the sequence state, as seen by gesture.

Parameters:

  • sequence (Gdk::EventSequence)

    a GdkEventSequence

Returns:

#group(gesture) ⇒ nil

Adds gesture to the same group than group_gesture.

Gestures are by default isolated in their own groups.

Both gestures must have been added to the same widget before they can be grouped.

When gestures are grouped, the state of GdkEventSequences is kept in sync for all of those, so calling [methodGtk.Gesture.set_sequence_state], on one will transfer the same value to the others.

Groups also perform an "implicit grabbing" of sequences, if a GdkEventSequence state is set to %GTK_EVENT_SEQUENCE_CLAIMED on one group, every other gesture group attached to the same GtkWidget will switch the state for that sequence to %GTK_EVENT_SEQUENCE_DENIED.

Parameters:

Returns:

  • (nil)

#handles_sequence(sequence) ⇒ Boolean

Returns true if gesture is currently handling events corresponding to sequence.

Parameters:

  • sequence (Gdk::EventSequence)

    a GdkEventSequence

Returns:

  • (Boolean)

    true if gesture is handling sequence, false otherwise

#is_activeBoolean

Returns true if the gesture is currently active.

A gesture is active while there are touch sequences interacting with it.

Returns:

  • (Boolean)

    true if gesture is active

#is_grouped_with(other) ⇒ Boolean

Returns true if both gestures pertain to the same group.

Parameters:

Returns:

  • (Boolean)

    whether the gestures are grouped

#is_recognizedBoolean

Returns true if the gesture is currently recognized.

A gesture is recognized if there are as many interacting touch sequences as required by gesture.

Returns:

  • (Boolean)

    true if gesture is recognized

#last_updated_sequenceGdk::EventSequence

Returns the GdkEventSequence that was last updated on gesture.

Returns:

  • (Gdk::EventSequence)

    The last updated sequence

#n_pointsInteger

The number of touch points that trigger recognition on this gesture.

Returns:

  • (Integer)

    n-points

#n_points=(n_points) ⇒ Integer

The number of touch points that trigger recognition on this gesture.

Parameters:

  • n_points (Integer)

Returns:

  • (Integer)

    n-points

  • (Integer)

    n-points

#sequencesGLib::List<Gdk::EventSequence>

Returns the list of GdkEventSequences currently being interpreted by gesture.

Returns:

  • (GLib::List<Gdk::EventSequence>)

    A list of GdkEventSequence, the list elements are owned by GTK and must not be freed or modified, the list itself must be deleted through g_list_free()

#set_sequence_state(sequence, state) ⇒ Boolean

Sets the state of sequence in gesture.

Sequences start in state %GTK_EVENT_SEQUENCE_NONE, and whenever they change state, they can never go back to that state. Likewise, sequences in state %GTK_EVENT_SEQUENCE_DENIED cannot turn back to a not denied state. With these rules, the lifetime of an event sequence is constrained to the next four:

  • None
  • None → Denied
  • None → Claimed
  • None → Claimed → Denied

Note: Due to event handling ordering, it may be unsafe to set the state on another gesture within a [signalGtk.Gesture::begin] signal handler, as the callback might be executed before the other gesture knows about the sequence. A safe way to perform this could be:

static void
first_gesture_begin_cb (GtkGesture       *first_gesture,
                        GdkEventSequence *sequence,
                        gpointer          user_data)
{
  gtk_gesture_set_sequence_state (first_gesture, sequence, GTK_EVENT_SEQUENCE_CLAIMED);
  gtk_gesture_set_sequence_state (second_gesture, sequence, GTK_EVENT_SEQUENCE_DENIED);
}

static void
second_gesture_begin_cb (GtkGesture       *second_gesture,
                         GdkEventSequence *sequence,
                         gpointer          user_data)
{
  if (gtk_gesture_get_sequence_state (first_gesture, sequence) == GTK_EVENT_SEQUENCE_CLAIMED)
    gtk_gesture_set_sequence_state (second_gesture, sequence, GTK_EVENT_SEQUENCE_DENIED);
}

If both gestures are in the same group, just set the state on the gesture emitting the event, the sequence will be already be initialized to the group's global state when the second gesture processes the event.

Parameters:

Returns:

  • (Boolean)

    true if sequence is handled by gesture, and the state is changed successfully

#state=(state) ⇒ Boolean

Sets the state of all sequences that gesture is currently interacting with.

Sequences start in state %GTK_EVENT_SEQUENCE_NONE, and whenever they change state, they can never go back to that state. Likewise, sequences in state %GTK_EVENT_SEQUENCE_DENIED cannot turn back to a not denied state. With these rules, the lifetime of an event sequence is constrained to the next four:

  • None
  • None → Denied
  • None → Claimed
  • None → Claimed → Denied

Note: Due to event handling ordering, it may be unsafe to set the state on another gesture within a [signalGtk.Gesture::begin] signal handler, as the callback might be executed before the other gesture knows about the sequence. A safe way to perform this could be:

static void
first_gesture_begin_cb (GtkGesture       *first_gesture,
                        GdkEventSequence *sequence,
                        gpointer          user_data)
{
  gtk_gesture_set_state (first_gesture, GTK_EVENT_SEQUENCE_CLAIMED);
  gtk_gesture_set_state (second_gesture, GTK_EVENT_SEQUENCE_DENIED);
}

static void
second_gesture_begin_cb (GtkGesture       *second_gesture,
                         GdkEventSequence *sequence,
                         gpointer          user_data)
{
  if (gtk_gesture_get_sequence_state (first_gesture, sequence) == GTK_EVENT_SEQUENCE_CLAIMED)
    gtk_gesture_set_state (second_gesture, GTK_EVENT_SEQUENCE_DENIED);
}

If both gestures are in the same group, just set the state on the gesture emitting the event, the sequence will be already be initialized to the group's global state when the second gesture processes the event.

Parameters:

Returns:

  • (Boolean)

    true if the state of at least one sequence was changed successfully

#ungroupnil

Separates gesture into an isolated group.

Returns:

  • (nil)