2013-01-17 19:59:07 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2012, One Laptop Per Child.
|
|
|
|
* Copyright (C) 2014, Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author(s): Carlos Garnacho <carlosg@gnome.org>
|
|
|
|
*/
|
2014-04-09 16:27:42 +00:00
|
|
|
|
|
|
|
/**
|
2021-03-01 06:38:10 +00:00
|
|
|
* GtkGesture:
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* `GtkGesture` is the base class for gesture recognition.
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* Although `GtkGesture` is quite generalized to serve as a base for
|
|
|
|
* multi-touch gestures, it is suitable to implement single-touch and
|
|
|
|
* pointer-based gestures (using the special %NULL `GdkEventSequence`
|
|
|
|
* value for these).
|
|
|
|
*
|
|
|
|
* The number of touches that a `GtkGesture` need to be recognized is
|
|
|
|
* controlled by the [property@Gtk.Gesture:n-points] property, if a
|
|
|
|
* gesture is keeping track of less or more than that number of sequences,
|
|
|
|
* it won't check whether the gesture is recognized.
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2020-08-05 01:17:49 +00:00
|
|
|
* As soon as the gesture has the expected number of touches, it will check
|
|
|
|
* regularly if it is recognized, the criteria to consider a gesture as
|
2021-03-01 06:38:10 +00:00
|
|
|
* "recognized" is left to `GtkGesture` subclasses.
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
|
|
|
* A recognized gesture will then emit the following signals:
|
2021-03-01 06:38:10 +00:00
|
|
|
*
|
|
|
|
* - [signal@Gtk.Gesture::begin] when the gesture is recognized.
|
|
|
|
* - [signal@Gtk.Gesture::update], whenever an input event is processed.
|
|
|
|
* - [signal@Gtk.Gesture::end] when the gesture is no longer recognized.
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2014-05-20 01:24:46 +00:00
|
|
|
* ## Event propagation
|
|
|
|
*
|
2020-08-05 01:17:49 +00:00
|
|
|
* In order to receive events, a gesture needs to set a propagation phase
|
2021-03-01 06:38:10 +00:00
|
|
|
* through [method@Gtk.EventController.set_propagation_phase].
|
|
|
|
*
|
|
|
|
* In the capture phase, events are propagated from the toplevel down
|
|
|
|
* to the target widget, and gestures that are attached to containers
|
|
|
|
* above the widget get a chance to interact with the event before it
|
|
|
|
* reaches the target.
|
|
|
|
*
|
|
|
|
* In the bubble phase, events are propagated up from the target widget
|
|
|
|
* to the toplevel, and gestures that are attached to containers above
|
|
|
|
* the widget get a chance to interact with events that have not been
|
|
|
|
* handled yet.
|
|
|
|
*
|
|
|
|
* ## States of a sequence
|
|
|
|
*
|
|
|
|
* Whenever input interaction happens, a single event may trigger a cascade
|
|
|
|
* of `GtkGesture`s, both across the parents of the widget receiving the
|
|
|
|
* event and in parallel within an individual widget. It is a responsibility
|
|
|
|
* of the widgets using those gestures to set the state of touch sequences
|
|
|
|
* accordingly in order to enable cooperation of gestures around the
|
|
|
|
* `GdkEventSequence`s triggering those.
|
|
|
|
*
|
|
|
|
* Within a widget, gestures can be grouped through [method@Gtk.Gesture.group].
|
|
|
|
* Grouped gestures synchronize the state of sequences, so calling
|
|
|
|
* [method@Gtk.Gesture.set_sequence_state] on one will effectively propagate
|
2014-05-20 01:24:46 +00:00
|
|
|
* the state throughout the group.
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* By default, all sequences start out in the %GTK_EVENT_SEQUENCE_NONE state,
|
2014-04-09 16:27:42 +00:00
|
|
|
* sequences in this state trigger the gesture event handler, but event
|
|
|
|
* propagation will continue unstopped by gestures.
|
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* If a sequence enters into the %GTK_EVENT_SEQUENCE_DENIED state, the gesture
|
2014-04-10 11:43:15 +00:00
|
|
|
* group will effectively ignore the sequence, letting events go unstopped
|
|
|
|
* through the gesture, but the "slot" will still remain occupied while
|
|
|
|
* the touch is active.
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* If a sequence enters in the %GTK_EVENT_SEQUENCE_CLAIMED state, the gesture
|
2014-04-09 16:27:42 +00:00
|
|
|
* group will grab all interaction on the sequence, by:
|
2021-03-01 06:38:10 +00:00
|
|
|
*
|
|
|
|
* - Setting the same sequence to %GTK_EVENT_SEQUENCE_DENIED on every other
|
|
|
|
* gesture group within the widget, and every gesture on parent widgets
|
|
|
|
* in the propagation chain.
|
|
|
|
* - Emitting [signal@Gtk.Gesture::cancel] on every gesture in widgets
|
|
|
|
* underneath in the propagation chain.
|
2014-04-10 11:43:15 +00:00
|
|
|
* - Stopping event propagation after the gesture group handles the event.
|
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* Note: if a sequence is set early to %GTK_EVENT_SEQUENCE_CLAIMED on
|
|
|
|
* %GDK_TOUCH_BEGIN/%GDK_BUTTON_PRESS (so those events are captured before
|
|
|
|
* reaching the event widget, this implies %GTK_PHASE_CAPTURE), one similar
|
|
|
|
* event will emulated if the sequence changes to %GTK_EVENT_SEQUENCE_DENIED.
|
2014-04-10 11:43:15 +00:00
|
|
|
* This way event coherence is preserved before event propagation is unstopped
|
|
|
|
* again.
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* Sequence states can't be changed freely.
|
|
|
|
* See [method@Gtk.Gesture.set_sequence_state] to know about the possible
|
|
|
|
* lifetimes of a `GdkEventSequence`.
|
2015-07-24 16:52:38 +00:00
|
|
|
*
|
|
|
|
* ## Touchpad gestures
|
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* On the platforms that support it, `GtkGesture` will handle transparently
|
|
|
|
* touchpad gesture events. The only precautions users of `GtkGesture` should
|
|
|
|
* do to enable this support are:
|
|
|
|
*
|
2015-07-24 16:52:38 +00:00
|
|
|
* - If the gesture has %GTK_PHASE_NONE, ensuring events of type
|
2021-03-01 06:38:10 +00:00
|
|
|
* %GDK_TOUCHPAD_SWIPE and %GDK_TOUCHPAD_PINCH are handled by the `GtkGesture`
|
2014-04-09 16:27:42 +00:00
|
|
|
*/
|
|
|
|
|
2013-01-17 19:59:07 +00:00
|
|
|
#include "config.h"
|
2014-05-06 02:40:18 +00:00
|
|
|
#include "gtkgesture.h"
|
2014-05-06 13:50:01 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2014-05-26 10:08:55 +00:00
|
|
|
#include "gtkeventcontrollerprivate.h"
|
2014-05-06 02:40:18 +00:00
|
|
|
#include "gtkgestureprivate.h"
|
2013-01-17 19:59:07 +00:00
|
|
|
#include "gtktypebuiltins.h"
|
|
|
|
#include "gtkprivate.h"
|
2014-03-24 12:04:51 +00:00
|
|
|
#include "gtkmain.h"
|
2013-01-17 19:59:07 +00:00
|
|
|
#include "gtkintl.h"
|
2019-06-02 21:07:27 +00:00
|
|
|
#include "gtkmarshalers.h"
|
2019-05-20 00:38:08 +00:00
|
|
|
#include "gtknative.h"
|
2013-01-17 19:59:07 +00:00
|
|
|
|
|
|
|
typedef struct _GtkGesturePrivate GtkGesturePrivate;
|
|
|
|
typedef struct _PointData PointData;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_N_POINTS = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
BEGIN,
|
|
|
|
END,
|
|
|
|
UPDATE,
|
widget: Implement hierarchy-level mechanism to claim/deny sequences
The policy of sequence states has been made tighter on GtkGesture,
so gestures can never return to a "none" state, nor get out of a
"denied" state, a "claimed" sequence can go "denied" though.
The helper API at the widget level will first emit
GtkWidget::sequence-state-changed on the called widget, and then
notify through the same signal to every other widget in the captured
event chain. So the effect of that signal is twofold, on one hand
it lets the original widget set the state on its attached controllers,
and on the other hand it lets the other widgets freely adapt to the
sequence state changing elsewhere in the event widget chain.
By default, that signal updates every controller on the first usecase,
and propagates the default gesture policy to every other widget in the
chain on the second. This means that, by default:
1) Sequences start out on the "none" state, and get propagated through
all the event widget chain.
2) If a widget in the chain denies the sequence, all other widgets are
unaffected.
3) If a widget in the chain claims the sequence, then:
3.1) Every widget below the claiming widget (ie. towards the event widget)
will get the sequence cancelled.
3.2) Every widget above the claiming widget that had the sequence as "none"
will remain as such, if it was claimed it will go denied, but that should
rarely happen.
This behavior can be tweaked through the GtkWidget::sequence-state-changed and
GtkGesture::event-handled vmethods, although this should be very rarely done.
2014-03-03 13:08:45 +00:00
|
|
|
CANCEL,
|
2013-01-17 19:59:07 +00:00
|
|
|
SEQUENCE_STATE_CHANGED,
|
|
|
|
N_SIGNALS
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _PointData
|
|
|
|
{
|
|
|
|
GdkEvent *event;
|
2020-02-16 07:46:40 +00:00
|
|
|
GtkWidget *target;
|
2020-07-24 20:32:16 +00:00
|
|
|
double widget_x;
|
|
|
|
double widget_y;
|
2015-07-24 09:48:44 +00:00
|
|
|
|
|
|
|
/* Acummulators for touchpad events */
|
2020-07-24 20:32:16 +00:00
|
|
|
double accum_dx;
|
|
|
|
double accum_dy;
|
2015-07-24 09:48:44 +00:00
|
|
|
|
2014-03-03 19:46:10 +00:00
|
|
|
guint press_handled : 1;
|
2013-01-17 19:59:07 +00:00
|
|
|
guint state : 2;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkGesturePrivate
|
|
|
|
{
|
|
|
|
GHashTable *points;
|
|
|
|
GdkEventSequence *last_sequence;
|
|
|
|
GdkDevice *device;
|
2014-04-08 18:47:38 +00:00
|
|
|
GList *group_link;
|
2013-01-17 19:59:07 +00:00
|
|
|
guint n_points;
|
|
|
|
guint recognized : 1;
|
2015-07-09 17:18:09 +00:00
|
|
|
guint touchpad : 1;
|
2013-01-17 19:59:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[N_SIGNALS] = { 0 };
|
|
|
|
|
|
|
|
#define BUTTONS_MASK (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)
|
|
|
|
|
2017-08-26 02:53:42 +00:00
|
|
|
#define EVENT_IS_TOUCHPAD_GESTURE(e) (gdk_event_get_event_type (e) == GDK_TOUCHPAD_SWIPE || \
|
|
|
|
gdk_event_get_event_type (e) == GDK_TOUCHPAD_PINCH)
|
2015-07-09 17:04:59 +00:00
|
|
|
|
2014-06-01 19:44:55 +00:00
|
|
|
GList * _gtk_gesture_get_group_link (GtkGesture *gesture);
|
|
|
|
|
2013-01-17 19:59:07 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GtkGesture, gtk_gesture, GTK_TYPE_EVENT_CONTROLLER)
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_gesture_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv = gtk_gesture_get_instance_private (GTK_GESTURE (object));
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_N_POINTS:
|
|
|
|
g_value_set_uint (value, priv->n_points);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_gesture_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv = gtk_gesture_get_instance_private (GTK_GESTURE (object));
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_N_POINTS:
|
|
|
|
priv->n_points = g_value_get_uint (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_gesture_finalize (GObject *object)
|
|
|
|
{
|
2014-06-29 00:15:12 +00:00
|
|
|
GtkGesture *gesture = GTK_GESTURE (object);
|
|
|
|
GtkGesturePrivate *priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
|
|
|
|
gtk_gesture_ungroup (gesture);
|
|
|
|
g_list_free (priv->group_link);
|
2013-01-17 19:59:07 +00:00
|
|
|
|
|
|
|
g_hash_table_destroy (priv->points);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_gesture_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2015-07-09 17:18:09 +00:00
|
|
|
static guint
|
|
|
|
_gtk_gesture_get_n_touchpad_points (GtkGesture *gesture,
|
|
|
|
gboolean only_active)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
PointData *data;
|
2017-08-25 14:47:11 +00:00
|
|
|
GdkEventType event_type;
|
2020-02-18 03:11:56 +00:00
|
|
|
GdkTouchpadGesturePhase phase = 0;
|
2017-08-26 02:53:42 +00:00
|
|
|
guint n_fingers = 0;
|
2015-07-09 17:18:09 +00:00
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
|
|
|
|
if (!priv->touchpad)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
data = g_hash_table_lookup (priv->points, NULL);
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return 0;
|
|
|
|
|
2017-08-25 14:47:11 +00:00
|
|
|
event_type = gdk_event_get_event_type (data->event);
|
|
|
|
|
2020-02-18 03:11:56 +00:00
|
|
|
if (EVENT_IS_TOUCHPAD_GESTURE (data->event))
|
|
|
|
{
|
|
|
|
phase = gdk_touchpad_event_get_gesture_phase (data->event);
|
|
|
|
n_fingers = gdk_touchpad_event_get_n_fingers (data->event);
|
|
|
|
}
|
2017-08-26 02:53:42 +00:00
|
|
|
|
2015-07-09 17:18:09 +00:00
|
|
|
if (only_active &&
|
|
|
|
(data->state == GTK_EVENT_SEQUENCE_DENIED ||
|
2017-08-26 02:53:42 +00:00
|
|
|
(event_type == GDK_TOUCHPAD_SWIPE && phase == GDK_TOUCHPAD_GESTURE_PHASE_END) ||
|
|
|
|
(event_type == GDK_TOUCHPAD_PINCH && phase == GDK_TOUCHPAD_GESTURE_PHASE_END)))
|
2015-07-09 17:18:09 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-08-26 02:53:42 +00:00
|
|
|
return n_fingers;
|
2015-07-09 17:18:09 +00:00
|
|
|
}
|
|
|
|
|
2013-01-17 19:59:07 +00:00
|
|
|
static guint
|
2015-07-09 17:11:04 +00:00
|
|
|
_gtk_gesture_get_n_touch_points (GtkGesture *gesture,
|
|
|
|
gboolean only_active)
|
2013-01-17 19:59:07 +00:00
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
GHashTableIter iter;
|
|
|
|
guint n_points = 0;
|
|
|
|
PointData *data;
|
2017-08-25 14:47:11 +00:00
|
|
|
GdkEventType event_type;
|
2013-01-17 19:59:07 +00:00
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
g_hash_table_iter_init (&iter, priv->points);
|
|
|
|
|
|
|
|
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &data))
|
|
|
|
{
|
2017-08-25 14:47:11 +00:00
|
|
|
event_type = gdk_event_get_event_type (data->event);
|
|
|
|
|
2015-07-09 17:11:04 +00:00
|
|
|
if (only_active &&
|
|
|
|
(data->state == GTK_EVENT_SEQUENCE_DENIED ||
|
2017-08-25 14:47:11 +00:00
|
|
|
event_type == GDK_TOUCH_END ||
|
|
|
|
event_type == GDK_BUTTON_RELEASE))
|
2013-01-17 19:59:07 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
n_points++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n_points;
|
|
|
|
}
|
|
|
|
|
2015-07-09 17:11:04 +00:00
|
|
|
static guint
|
|
|
|
_gtk_gesture_get_n_physical_points (GtkGesture *gesture,
|
|
|
|
gboolean only_active)
|
|
|
|
{
|
2015-07-09 17:18:09 +00:00
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
|
|
|
|
if (priv->touchpad)
|
|
|
|
return _gtk_gesture_get_n_touchpad_points (gesture, only_active);
|
|
|
|
else
|
|
|
|
return _gtk_gesture_get_n_touch_points (gesture, only_active);
|
2015-07-09 17:11:04 +00:00
|
|
|
}
|
|
|
|
|
2013-01-17 19:59:07 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_gesture_check_impl (GtkGesture *gesture)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
guint n_points;
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
2015-07-09 17:11:04 +00:00
|
|
|
n_points = _gtk_gesture_get_n_physical_points (gesture, TRUE);
|
2013-01-17 19:59:07 +00:00
|
|
|
|
|
|
|
return n_points == priv->n_points;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_gesture_set_recognized (GtkGesture *gesture,
|
|
|
|
gboolean recognized,
|
|
|
|
GdkEventSequence *sequence)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
|
|
|
|
if (priv->recognized == recognized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->recognized = recognized;
|
|
|
|
|
|
|
|
if (recognized)
|
|
|
|
g_signal_emit (gesture, signals[BEGIN], 0, sequence);
|
|
|
|
else
|
|
|
|
g_signal_emit (gesture, signals[END], 0, sequence);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_gtk_gesture_do_check (GtkGesture *gesture)
|
|
|
|
{
|
2014-05-06 16:04:25 +00:00
|
|
|
GtkGestureClass *gesture_class;
|
|
|
|
gboolean retval = FALSE;
|
2013-01-17 19:59:07 +00:00
|
|
|
|
2014-05-06 16:04:25 +00:00
|
|
|
gesture_class = GTK_GESTURE_GET_CLASS (gesture);
|
2013-01-17 19:59:07 +00:00
|
|
|
|
2014-05-06 16:04:25 +00:00
|
|
|
if (!gesture_class->check)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
retval = gesture_class->check (gesture);
|
2013-01-17 19:59:07 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-06-24 17:08:51 +00:00
|
|
|
_gtk_gesture_has_matching_touchpoints (GtkGesture *gesture)
|
2013-01-17 19:59:07 +00:00
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv = gtk_gesture_get_instance_private (gesture);
|
2015-07-09 17:11:04 +00:00
|
|
|
guint active_n_points, current_n_points;
|
2013-01-17 19:59:07 +00:00
|
|
|
|
2015-07-09 17:11:04 +00:00
|
|
|
current_n_points = _gtk_gesture_get_n_physical_points (gesture, FALSE);
|
|
|
|
active_n_points = _gtk_gesture_get_n_physical_points (gesture, TRUE);
|
2013-01-17 19:59:07 +00:00
|
|
|
|
2015-07-09 17:11:04 +00:00
|
|
|
return (active_n_points == priv->n_points &&
|
|
|
|
current_n_points == priv->n_points);
|
2014-06-24 17:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_gtk_gesture_check_recognized (GtkGesture *gesture,
|
|
|
|
GdkEventSequence *sequence)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
gboolean has_matching_touchpoints;
|
|
|
|
|
|
|
|
has_matching_touchpoints = _gtk_gesture_has_matching_touchpoints (gesture);
|
|
|
|
|
|
|
|
if (priv->recognized && !has_matching_touchpoints)
|
2013-01-17 19:59:07 +00:00
|
|
|
_gtk_gesture_set_recognized (gesture, FALSE, sequence);
|
2014-06-24 17:08:51 +00:00
|
|
|
else if (!priv->recognized && has_matching_touchpoints &&
|
2013-01-17 19:59:07 +00:00
|
|
|
_gtk_gesture_do_check (gesture))
|
|
|
|
_gtk_gesture_set_recognized (gesture, TRUE, sequence);
|
|
|
|
|
|
|
|
return priv->recognized;
|
|
|
|
}
|
|
|
|
|
2015-07-24 09:48:44 +00:00
|
|
|
static void
|
|
|
|
_update_touchpad_deltas (PointData *data)
|
|
|
|
{
|
|
|
|
GdkEvent *event = data->event;
|
2017-08-26 14:51:49 +00:00
|
|
|
GdkTouchpadGesturePhase phase;
|
|
|
|
double dx;
|
|
|
|
double dy;
|
2015-07-24 09:48:44 +00:00
|
|
|
|
|
|
|
if (!event)
|
|
|
|
return;
|
|
|
|
|
2020-02-18 03:11:56 +00:00
|
|
|
if (EVENT_IS_TOUCHPAD_GESTURE (event))
|
2015-07-24 09:48:44 +00:00
|
|
|
{
|
2020-02-18 03:11:56 +00:00
|
|
|
phase = gdk_touchpad_event_get_gesture_phase (event);
|
|
|
|
gdk_touchpad_event_get_deltas (event, &dx, &dy);
|
2017-08-26 14:51:49 +00:00
|
|
|
if (phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN)
|
2015-07-24 09:48:44 +00:00
|
|
|
data->accum_dx = data->accum_dy = 0;
|
2017-08-26 14:51:49 +00:00
|
|
|
else if (phase == GDK_TOUCHPAD_GESTURE_PHASE_UPDATE)
|
2015-07-24 09:48:44 +00:00
|
|
|
{
|
2017-08-26 14:51:49 +00:00
|
|
|
data->accum_dx += dx;
|
|
|
|
data->accum_dy += dy;
|
2015-07-24 09:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-01 19:44:55 +00:00
|
|
|
static GtkEventSequenceState
|
|
|
|
gtk_gesture_get_group_state (GtkGesture *gesture,
|
|
|
|
GdkEventSequence *sequence)
|
|
|
|
{
|
|
|
|
GtkEventSequenceState state = GTK_EVENT_SEQUENCE_NONE;
|
|
|
|
GList *group_elem;
|
|
|
|
|
|
|
|
group_elem = g_list_first (_gtk_gesture_get_group_link (gesture));
|
|
|
|
|
|
|
|
for (; group_elem; group_elem = group_elem->next)
|
|
|
|
{
|
|
|
|
if (group_elem->data == gesture)
|
|
|
|
continue;
|
|
|
|
if (!gtk_gesture_handles_sequence (group_elem->data, sequence))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
state = gtk_gesture_get_sequence_state (group_elem->data, sequence);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2013-01-17 19:59:07 +00:00
|
|
|
static gboolean
|
|
|
|
_gtk_gesture_update_point (GtkGesture *gesture,
|
2020-02-16 16:09:02 +00:00
|
|
|
GdkEvent *event,
|
2020-02-16 07:46:40 +00:00
|
|
|
GtkWidget *target,
|
2020-02-13 05:08:49 +00:00
|
|
|
double x,
|
|
|
|
double y,
|
2013-01-17 19:59:07 +00:00
|
|
|
gboolean add)
|
|
|
|
{
|
|
|
|
GdkEventSequence *sequence;
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
GdkDevice *device;
|
2015-07-09 17:18:09 +00:00
|
|
|
gboolean existed, touchpad;
|
2013-01-17 19:59:07 +00:00
|
|
|
PointData *data;
|
|
|
|
|
|
|
|
device = gdk_event_get_device (event);
|
|
|
|
|
|
|
|
if (!device)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
2015-07-09 17:18:09 +00:00
|
|
|
touchpad = EVENT_IS_TOUCHPAD_GESTURE (event);
|
|
|
|
|
2014-03-21 16:14:53 +00:00
|
|
|
if (add)
|
|
|
|
{
|
|
|
|
/* If the event happens with the wrong device, or
|
|
|
|
* on the wrong window, ignore.
|
|
|
|
*/
|
|
|
|
if (priv->device && priv->device != device)
|
|
|
|
return FALSE;
|
2015-07-09 17:18:09 +00:00
|
|
|
|
|
|
|
/* Make touchpad and touchscreen gestures mutually exclusive */
|
|
|
|
if (touchpad && g_hash_table_size (priv->points) > 0)
|
|
|
|
return FALSE;
|
|
|
|
else if (!touchpad && priv->touchpad)
|
|
|
|
return FALSE;
|
2014-03-21 16:14:53 +00:00
|
|
|
}
|
2017-03-31 16:16:19 +00:00
|
|
|
else if (!priv->device)
|
2013-01-17 19:59:07 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
sequence = gdk_event_get_event_sequence (event);
|
2014-05-06 13:20:56 +00:00
|
|
|
existed = g_hash_table_lookup_extended (priv->points, sequence,
|
|
|
|
NULL, (gpointer *) &data);
|
|
|
|
if (!existed)
|
2013-01-17 19:59:07 +00:00
|
|
|
{
|
|
|
|
if (!add)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (g_hash_table_size (priv->points) == 0)
|
|
|
|
{
|
|
|
|
priv->device = device;
|
2015-07-09 17:18:09 +00:00
|
|
|
priv->touchpad = touchpad;
|
2013-01-17 19:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data = g_new0 (PointData, 1);
|
|
|
|
g_hash_table_insert (priv->points, sequence, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->event)
|
2020-02-15 20:07:24 +00:00
|
|
|
gdk_event_unref (data->event);
|
2013-01-17 19:59:07 +00:00
|
|
|
|
2020-02-15 20:07:24 +00:00
|
|
|
data->event = gdk_event_ref ((GdkEvent *)event);
|
2020-05-30 13:15:19 +00:00
|
|
|
g_set_object (&data->target, target);
|
2015-07-24 09:48:44 +00:00
|
|
|
_update_touchpad_deltas (data);
|
2020-02-13 05:08:49 +00:00
|
|
|
data->widget_x = x + data->accum_dx;
|
|
|
|
data->widget_y = y + data->accum_dy;
|
2013-01-17 19:59:07 +00:00
|
|
|
|
2021-05-17 21:34:44 +00:00
|
|
|
if (!existed)
|
|
|
|
{
|
|
|
|
GtkEventSequenceState state;
|
|
|
|
|
|
|
|
/* Deny the sequence right away if the expected
|
|
|
|
* number of points is exceeded, so this sequence
|
|
|
|
* can be tracked with gtk_gesture_handles_sequence().
|
|
|
|
*
|
|
|
|
* Otherwise, make the sequence inherit the same state
|
|
|
|
* from other gestures in the same group.
|
|
|
|
*/
|
|
|
|
if (_gtk_gesture_get_n_physical_points (gesture, FALSE) > priv->n_points)
|
|
|
|
state = GTK_EVENT_SEQUENCE_DENIED;
|
|
|
|
else
|
|
|
|
state = gtk_gesture_get_group_state (gesture, sequence);
|
|
|
|
|
|
|
|
gtk_gesture_set_sequence_state (gesture, sequence, state);
|
|
|
|
}
|
2014-05-06 13:20:56 +00:00
|
|
|
|
2013-01-17 19:59:07 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-03-21 16:31:19 +00:00
|
|
|
static void
|
|
|
|
_gtk_gesture_check_empty (GtkGesture *gesture)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
|
|
|
|
if (g_hash_table_size (priv->points) == 0)
|
|
|
|
{
|
|
|
|
priv->device = NULL;
|
2015-07-09 17:18:09 +00:00
|
|
|
priv->touchpad = FALSE;
|
2014-03-21 16:31:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-17 19:59:07 +00:00
|
|
|
static void
|
|
|
|
_gtk_gesture_remove_point (GtkGesture *gesture,
|
2020-02-16 16:09:02 +00:00
|
|
|
GdkEvent *event)
|
2013-01-17 19:59:07 +00:00
|
|
|
{
|
|
|
|
GdkEventSequence *sequence;
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
GdkDevice *device;
|
|
|
|
|
|
|
|
sequence = gdk_event_get_event_sequence (event);
|
|
|
|
device = gdk_event_get_device (event);
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
|
2014-03-21 16:31:19 +00:00
|
|
|
if (priv->device != device)
|
|
|
|
return;
|
|
|
|
|
2013-01-17 19:59:07 +00:00
|
|
|
g_hash_table_remove (priv->points, sequence);
|
2014-03-21 16:31:19 +00:00
|
|
|
_gtk_gesture_check_empty (gesture);
|
|
|
|
}
|
2013-01-17 19:59:07 +00:00
|
|
|
|
2014-03-21 16:31:19 +00:00
|
|
|
static void
|
|
|
|
_gtk_gesture_cancel_all (GtkGesture *gesture)
|
|
|
|
{
|
|
|
|
GdkEventSequence *sequence;
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
g_hash_table_iter_init (&iter, priv->points);
|
|
|
|
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer*) &sequence, NULL))
|
2013-01-17 19:59:07 +00:00
|
|
|
{
|
2014-03-21 16:31:19 +00:00
|
|
|
g_signal_emit (gesture, signals[CANCEL], 0, sequence);
|
|
|
|
g_hash_table_iter_remove (&iter);
|
|
|
|
_gtk_gesture_check_recognized (gesture, sequence);
|
2013-01-17 19:59:07 +00:00
|
|
|
}
|
2014-03-21 16:31:19 +00:00
|
|
|
|
|
|
|
_gtk_gesture_check_empty (gesture);
|
2013-01-17 19:59:07 +00:00
|
|
|
}
|
|
|
|
|
2014-05-10 18:46:47 +00:00
|
|
|
static gboolean
|
2018-03-21 10:49:14 +00:00
|
|
|
gesture_within_surface (GtkGesture *gesture,
|
2019-03-22 18:24:39 +00:00
|
|
|
GdkSurface *surface)
|
2014-05-10 18:46:47 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
2019-05-20 00:38:08 +00:00
|
|
|
return surface == gtk_native_get_surface (gtk_widget_get_native (widget));
|
2014-05-10 18:46:47 +00:00
|
|
|
}
|
|
|
|
|
2015-07-09 17:04:59 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_gesture_filter_event (GtkEventController *controller,
|
2020-02-16 16:09:02 +00:00
|
|
|
GdkEvent *event)
|
2015-07-09 17:04:59 +00:00
|
|
|
{
|
|
|
|
/* Even though GtkGesture handles these events, we want
|
|
|
|
* touchpad gestures disabled by default, it will be
|
|
|
|
* subclasses which punch the holes in for the events
|
|
|
|
* they can possibly handle.
|
|
|
|
*/
|
2019-05-02 19:10:49 +00:00
|
|
|
if (EVENT_IS_TOUCHPAD_GESTURE (event))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return GTK_EVENT_CONTROLLER_CLASS (gtk_gesture_parent_class)->filter_event (controller, event);
|
2015-07-09 17:04:59 +00:00
|
|
|
}
|
|
|
|
|
2013-01-17 19:59:07 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_gesture_handle_event (GtkEventController *controller,
|
2020-02-16 16:09:02 +00:00
|
|
|
GdkEvent *event,
|
2020-02-13 05:08:49 +00:00
|
|
|
double x,
|
|
|
|
double y)
|
2013-01-17 19:59:07 +00:00
|
|
|
{
|
|
|
|
GtkGesture *gesture = GTK_GESTURE (controller);
|
|
|
|
GdkEventSequence *sequence;
|
|
|
|
GtkGesturePrivate *priv;
|
2014-03-21 16:17:42 +00:00
|
|
|
GdkDevice *source_device;
|
2014-03-21 14:31:12 +00:00
|
|
|
gboolean was_recognized;
|
2017-08-25 14:47:11 +00:00
|
|
|
GdkEventType event_type;
|
2020-02-18 03:11:56 +00:00
|
|
|
GdkTouchpadGesturePhase phase = 0;
|
2017-08-26 14:51:49 +00:00
|
|
|
GdkModifierType state;
|
2020-02-16 07:46:40 +00:00
|
|
|
GtkWidget *target;
|
2013-01-17 19:59:07 +00:00
|
|
|
|
2020-07-28 22:03:48 +00:00
|
|
|
source_device = gdk_event_get_device (event);
|
2014-03-21 16:17:42 +00:00
|
|
|
|
|
|
|
if (!source_device)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-01-17 19:59:07 +00:00
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
sequence = gdk_event_get_event_sequence (event);
|
2014-03-21 14:31:12 +00:00
|
|
|
was_recognized = gtk_gesture_is_recognized (gesture);
|
2017-08-25 14:47:11 +00:00
|
|
|
event_type = gdk_event_get_event_type (event);
|
2020-02-18 03:11:56 +00:00
|
|
|
state = gdk_event_get_modifier_state (event);
|
|
|
|
if (EVENT_IS_TOUCHPAD_GESTURE (event))
|
|
|
|
phase = gdk_touchpad_event_get_gesture_phase (event);
|
2013-01-17 19:59:07 +00:00
|
|
|
|
2020-02-16 07:46:40 +00:00
|
|
|
target = gtk_event_controller_get_target (controller);
|
|
|
|
|
2014-03-21 16:34:41 +00:00
|
|
|
if (gtk_gesture_get_sequence_state (gesture, sequence) != GTK_EVENT_SEQUENCE_DENIED)
|
|
|
|
priv->last_sequence = sequence;
|
2013-01-17 19:59:07 +00:00
|
|
|
|
2017-08-25 14:47:11 +00:00
|
|
|
if (event_type == GDK_BUTTON_PRESS ||
|
|
|
|
event_type == GDK_TOUCH_BEGIN ||
|
2017-08-26 14:51:49 +00:00
|
|
|
(event_type == GDK_TOUCHPAD_SWIPE && phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN) ||
|
|
|
|
(event_type == GDK_TOUCHPAD_PINCH && phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN))
|
2013-01-17 19:59:07 +00:00
|
|
|
{
|
2020-02-16 07:46:40 +00:00
|
|
|
if (_gtk_gesture_update_point (gesture, event, target, x, y, TRUE))
|
2014-03-03 19:46:10 +00:00
|
|
|
{
|
2014-06-24 17:08:51 +00:00
|
|
|
gboolean triggered_recognition;
|
|
|
|
|
|
|
|
triggered_recognition =
|
|
|
|
!was_recognized && _gtk_gesture_has_matching_touchpoints (gesture);
|
|
|
|
|
|
|
|
if (_gtk_gesture_check_recognized (gesture, sequence))
|
|
|
|
{
|
|
|
|
PointData *data;
|
|
|
|
|
|
|
|
data = g_hash_table_lookup (priv->points, sequence);
|
|
|
|
|
|
|
|
/* If the sequence was claimed early, the press event will be consumed */
|
|
|
|
if (gtk_gesture_get_sequence_state (gesture, sequence) == GTK_EVENT_SEQUENCE_CLAIMED)
|
|
|
|
data->press_handled = TRUE;
|
|
|
|
}
|
|
|
|
else if (triggered_recognition && g_hash_table_size (priv->points) == 0)
|
|
|
|
{
|
|
|
|
/* Recognition was triggered, but the gesture reset during
|
|
|
|
* ::begin emission. Still, recognition was strictly triggered,
|
|
|
|
* so the event should be consumed.
|
|
|
|
*/
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-03-03 19:46:10 +00:00
|
|
|
}
|
2015-07-24 15:39:35 +00:00
|
|
|
}
|
2017-08-25 14:47:11 +00:00
|
|
|
else if (event_type == GDK_BUTTON_RELEASE ||
|
|
|
|
event_type == GDK_TOUCH_END ||
|
2017-08-26 14:51:49 +00:00
|
|
|
(event_type == GDK_TOUCHPAD_SWIPE && phase == GDK_TOUCHPAD_GESTURE_PHASE_END) ||
|
|
|
|
(event_type == GDK_TOUCHPAD_PINCH && phase == GDK_TOUCHPAD_GESTURE_PHASE_END))
|
2015-07-24 15:39:35 +00:00
|
|
|
{
|
2020-09-14 12:35:44 +00:00
|
|
|
gboolean was_claimed = FALSE;
|
2017-05-24 16:22:00 +00:00
|
|
|
|
2020-02-16 07:46:40 +00:00
|
|
|
if (_gtk_gesture_update_point (gesture, event, target, x, y, FALSE))
|
2013-01-17 19:59:07 +00:00
|
|
|
{
|
2014-03-21 14:31:12 +00:00
|
|
|
if (was_recognized &&
|
|
|
|
_gtk_gesture_check_recognized (gesture, sequence))
|
2013-01-17 19:59:07 +00:00
|
|
|
g_signal_emit (gesture, signals[UPDATE], 0, sequence);
|
|
|
|
|
2020-09-14 12:35:44 +00:00
|
|
|
was_claimed =
|
|
|
|
gtk_gesture_get_sequence_state (gesture, sequence) == GTK_EVENT_SEQUENCE_CLAIMED;
|
|
|
|
|
2013-01-17 19:59:07 +00:00
|
|
|
_gtk_gesture_remove_point (gesture, event);
|
|
|
|
}
|
2017-05-24 16:22:00 +00:00
|
|
|
|
|
|
|
return was_claimed && was_recognized;
|
2015-07-24 15:39:35 +00:00
|
|
|
}
|
2017-08-25 14:47:11 +00:00
|
|
|
else if (event_type == GDK_MOTION_NOTIFY ||
|
|
|
|
event_type == GDK_TOUCH_UPDATE ||
|
2017-08-26 14:51:49 +00:00
|
|
|
(event_type == GDK_TOUCHPAD_SWIPE && phase == GDK_TOUCHPAD_GESTURE_PHASE_UPDATE) ||
|
|
|
|
(event_type == GDK_TOUCHPAD_PINCH && phase == GDK_TOUCHPAD_GESTURE_PHASE_UPDATE))
|
2015-07-24 15:39:35 +00:00
|
|
|
{
|
2017-08-25 14:47:11 +00:00
|
|
|
if (event_type == GDK_MOTION_NOTIFY)
|
2015-07-24 15:39:35 +00:00
|
|
|
{
|
2017-08-26 14:51:49 +00:00
|
|
|
if ((state & BUTTONS_MASK) == 0)
|
2015-07-24 15:39:35 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-01-17 19:59:07 +00:00
|
|
|
|
2020-02-16 07:46:40 +00:00
|
|
|
if (_gtk_gesture_update_point (gesture, event, target, x, y, FALSE) &&
|
2013-01-17 19:59:07 +00:00
|
|
|
_gtk_gesture_check_recognized (gesture, sequence))
|
|
|
|
g_signal_emit (gesture, signals[UPDATE], 0, sequence);
|
2015-07-24 15:39:35 +00:00
|
|
|
}
|
2017-08-25 14:47:11 +00:00
|
|
|
else if (event_type == GDK_TOUCH_CANCEL)
|
2015-07-24 15:39:35 +00:00
|
|
|
{
|
2015-07-09 17:18:09 +00:00
|
|
|
if (!priv->touchpad)
|
|
|
|
_gtk_gesture_cancel_sequence (gesture, sequence);
|
|
|
|
}
|
2017-08-26 14:51:49 +00:00
|
|
|
else if ((event_type == GDK_TOUCHPAD_SWIPE && phase == GDK_TOUCHPAD_GESTURE_PHASE_CANCEL) ||
|
|
|
|
(event_type == GDK_TOUCHPAD_PINCH && phase == GDK_TOUCHPAD_GESTURE_PHASE_CANCEL))
|
2015-07-09 17:18:09 +00:00
|
|
|
{
|
|
|
|
if (priv->touchpad)
|
|
|
|
_gtk_gesture_cancel_sequence (gesture, sequence);
|
2015-07-24 15:39:35 +00:00
|
|
|
}
|
2017-08-25 14:47:11 +00:00
|
|
|
else if (event_type == GDK_GRAB_BROKEN)
|
2015-07-24 15:39:35 +00:00
|
|
|
{
|
2020-02-18 03:11:56 +00:00
|
|
|
GdkSurface *surface;
|
2017-08-26 14:51:49 +00:00
|
|
|
|
2020-02-18 03:11:56 +00:00
|
|
|
surface = gdk_grab_broken_event_get_grab_surface (event);
|
2018-03-21 10:49:14 +00:00
|
|
|
if (!surface || !gesture_within_surface (gesture, surface))
|
2014-05-10 18:46:47 +00:00
|
|
|
_gtk_gesture_cancel_all (gesture);
|
|
|
|
|
|
|
|
return FALSE;
|
2015-07-24 15:39:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-17 19:59:07 +00:00
|
|
|
/* Unhandled event */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gtk_gesture_get_sequence_state (gesture, sequence) != GTK_EVENT_SEQUENCE_CLAIMED)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return priv->recognized;
|
|
|
|
}
|
|
|
|
|
2014-03-21 16:31:19 +00:00
|
|
|
static void
|
|
|
|
gtk_gesture_reset (GtkEventController *controller)
|
|
|
|
{
|
|
|
|
_gtk_gesture_cancel_all (GTK_GESTURE (controller));
|
|
|
|
}
|
|
|
|
|
2013-01-17 19:59:07 +00:00
|
|
|
static void
|
|
|
|
gtk_gesture_class_init (GtkGestureClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkEventControllerClass *controller_class = GTK_EVENT_CONTROLLER_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->get_property = gtk_gesture_get_property;
|
|
|
|
object_class->set_property = gtk_gesture_set_property;
|
|
|
|
object_class->finalize = gtk_gesture_finalize;
|
|
|
|
|
2015-07-09 17:04:59 +00:00
|
|
|
controller_class->filter_event = gtk_gesture_filter_event;
|
2013-01-17 19:59:07 +00:00
|
|
|
controller_class->handle_event = gtk_gesture_handle_event;
|
2014-03-21 16:31:19 +00:00
|
|
|
controller_class->reset = gtk_gesture_reset;
|
2013-01-17 19:59:07 +00:00
|
|
|
|
|
|
|
klass->check = gtk_gesture_check_impl;
|
|
|
|
|
2014-04-09 16:27:42 +00:00
|
|
|
/**
|
|
|
|
* GtkGesture:n-points:
|
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* The number of touch points that trigger
|
|
|
|
* recognition on this gesture.
|
2014-04-09 16:27:42 +00:00
|
|
|
*/
|
2013-01-17 19:59:07 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_N_POINTS,
|
|
|
|
g_param_spec_uint ("n-points",
|
|
|
|
P_("Number of points"),
|
|
|
|
P_("Number of points needed "
|
|
|
|
"to trigger the gesture"),
|
|
|
|
1, G_MAXUINT, 1,
|
|
|
|
GTK_PARAM_READWRITE |
|
2020-12-27 20:06:51 +00:00
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2014-04-09 16:27:42 +00:00
|
|
|
/**
|
2014-04-10 11:43:15 +00:00
|
|
|
* GtkGesture::begin:
|
2014-04-09 16:27:42 +00:00
|
|
|
* @gesture: the object which received the signal
|
2021-03-01 06:38:10 +00:00
|
|
|
* @sequence: (nullable): the `GdkEventSequence` that made the gesture
|
|
|
|
* to be recognized
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* Emitted when the gesture is recognized.
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* This means the number of touch sequences matches
|
|
|
|
* [property@Gtk.Gesture:n-points].
|
|
|
|
*
|
|
|
|
* Note: These conditions may also happen when an extra touch
|
|
|
|
* (eg. a third touch on a 2-touches gesture) is lifted, in that
|
|
|
|
* situation @sequence won't pertain to the current set of active
|
|
|
|
* touches, so don't rely on this being true.
|
2014-04-09 16:27:42 +00:00
|
|
|
*/
|
2013-01-17 19:59:07 +00:00
|
|
|
signals[BEGIN] =
|
2015-09-12 13:13:00 +00:00
|
|
|
g_signal_new (I_("begin"),
|
2013-01-17 19:59:07 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkGestureClass, begin),
|
|
|
|
NULL, NULL, NULL,
|
2014-05-20 12:10:31 +00:00
|
|
|
G_TYPE_NONE, 1, GDK_TYPE_EVENT_SEQUENCE);
|
2021-03-01 06:38:10 +00:00
|
|
|
|
2014-04-09 16:27:42 +00:00
|
|
|
/**
|
2014-04-10 11:43:15 +00:00
|
|
|
* GtkGesture::end:
|
2014-04-09 16:27:42 +00:00
|
|
|
* @gesture: the object which received the signal
|
2021-03-01 06:38:10 +00:00
|
|
|
* @sequence: (nullable): the `GdkEventSequence` that made gesture
|
|
|
|
* recognition to finish
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* Emitted when @gesture either stopped recognizing the event
|
|
|
|
* sequences as something to be handled, or the number of touch
|
|
|
|
* sequences became higher or lower than [property@Gtk.Gesture:n-points].
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* Note: @sequence might not pertain to the group of sequences that
|
|
|
|
* were previously triggering recognition on @gesture (ie. a just
|
|
|
|
* pressed touch sequence that exceeds [property@Gtk.Gesture:n-points]).
|
|
|
|
* This situation may be detected by checking through
|
|
|
|
* [method@Gtk.Gesture.handles_sequence].
|
2014-04-09 16:27:42 +00:00
|
|
|
*/
|
2013-01-17 19:59:07 +00:00
|
|
|
signals[END] =
|
2015-09-12 13:13:00 +00:00
|
|
|
g_signal_new (I_("end"),
|
2013-01-17 19:59:07 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkGestureClass, end),
|
|
|
|
NULL, NULL, NULL,
|
2014-05-20 12:10:31 +00:00
|
|
|
G_TYPE_NONE, 1, GDK_TYPE_EVENT_SEQUENCE);
|
2021-03-01 06:38:10 +00:00
|
|
|
|
2014-04-09 16:27:42 +00:00
|
|
|
/**
|
2014-04-10 11:43:15 +00:00
|
|
|
* GtkGesture::update:
|
2014-04-09 16:27:42 +00:00
|
|
|
* @gesture: the object which received the signal
|
2021-03-01 06:38:10 +00:00
|
|
|
* @sequence: (nullable): the `GdkEventSequence` that was updated
|
|
|
|
*
|
|
|
|
* Emitted whenever an event is handled while the gesture is recognized.
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* @sequence is guaranteed to pertain to the set of active touches.
|
2014-04-09 16:27:42 +00:00
|
|
|
*/
|
2013-01-17 19:59:07 +00:00
|
|
|
signals[UPDATE] =
|
2015-09-12 13:13:00 +00:00
|
|
|
g_signal_new (I_("update"),
|
2013-01-17 19:59:07 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkGestureClass, update),
|
|
|
|
NULL, NULL, NULL,
|
2014-05-20 12:10:31 +00:00
|
|
|
G_TYPE_NONE, 1, GDK_TYPE_EVENT_SEQUENCE);
|
2021-03-01 06:38:10 +00:00
|
|
|
|
2014-04-09 16:27:42 +00:00
|
|
|
/**
|
2014-04-10 11:43:15 +00:00
|
|
|
* GtkGesture::cancel:
|
2014-04-09 16:27:42 +00:00
|
|
|
* @gesture: the object which received the signal
|
2021-03-01 06:38:10 +00:00
|
|
|
* @sequence: (nullable): the `GdkEventSequence` that was cancelled
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* Emitted whenever a sequence is cancelled.
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* This usually happens on active touches when
|
|
|
|
* [method@Gtk.EventController.reset] is called on @gesture
|
|
|
|
* (manually, due to grabs...), or the individual @sequence
|
|
|
|
* was claimed by parent widgets' controllers (see
|
|
|
|
* [method@Gtk.Gesture.set_sequence_state]).
|
|
|
|
*
|
|
|
|
* @gesture must forget everything about @sequence as in
|
|
|
|
* response to this signal.
|
2014-04-09 16:27:42 +00:00
|
|
|
*/
|
widget: Implement hierarchy-level mechanism to claim/deny sequences
The policy of sequence states has been made tighter on GtkGesture,
so gestures can never return to a "none" state, nor get out of a
"denied" state, a "claimed" sequence can go "denied" though.
The helper API at the widget level will first emit
GtkWidget::sequence-state-changed on the called widget, and then
notify through the same signal to every other widget in the captured
event chain. So the effect of that signal is twofold, on one hand
it lets the original widget set the state on its attached controllers,
and on the other hand it lets the other widgets freely adapt to the
sequence state changing elsewhere in the event widget chain.
By default, that signal updates every controller on the first usecase,
and propagates the default gesture policy to every other widget in the
chain on the second. This means that, by default:
1) Sequences start out on the "none" state, and get propagated through
all the event widget chain.
2) If a widget in the chain denies the sequence, all other widgets are
unaffected.
3) If a widget in the chain claims the sequence, then:
3.1) Every widget below the claiming widget (ie. towards the event widget)
will get the sequence cancelled.
3.2) Every widget above the claiming widget that had the sequence as "none"
will remain as such, if it was claimed it will go denied, but that should
rarely happen.
This behavior can be tweaked through the GtkWidget::sequence-state-changed and
GtkGesture::event-handled vmethods, although this should be very rarely done.
2014-03-03 13:08:45 +00:00
|
|
|
signals[CANCEL] =
|
2015-09-12 13:13:00 +00:00
|
|
|
g_signal_new (I_("cancel"),
|
widget: Implement hierarchy-level mechanism to claim/deny sequences
The policy of sequence states has been made tighter on GtkGesture,
so gestures can never return to a "none" state, nor get out of a
"denied" state, a "claimed" sequence can go "denied" though.
The helper API at the widget level will first emit
GtkWidget::sequence-state-changed on the called widget, and then
notify through the same signal to every other widget in the captured
event chain. So the effect of that signal is twofold, on one hand
it lets the original widget set the state on its attached controllers,
and on the other hand it lets the other widgets freely adapt to the
sequence state changing elsewhere in the event widget chain.
By default, that signal updates every controller on the first usecase,
and propagates the default gesture policy to every other widget in the
chain on the second. This means that, by default:
1) Sequences start out on the "none" state, and get propagated through
all the event widget chain.
2) If a widget in the chain denies the sequence, all other widgets are
unaffected.
3) If a widget in the chain claims the sequence, then:
3.1) Every widget below the claiming widget (ie. towards the event widget)
will get the sequence cancelled.
3.2) Every widget above the claiming widget that had the sequence as "none"
will remain as such, if it was claimed it will go denied, but that should
rarely happen.
This behavior can be tweaked through the GtkWidget::sequence-state-changed and
GtkGesture::event-handled vmethods, although this should be very rarely done.
2014-03-03 13:08:45 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkGestureClass, cancel),
|
|
|
|
NULL, NULL, NULL,
|
2014-05-20 12:10:31 +00:00
|
|
|
G_TYPE_NONE, 1, GDK_TYPE_EVENT_SEQUENCE);
|
2021-03-01 06:38:10 +00:00
|
|
|
|
2014-04-09 16:27:42 +00:00
|
|
|
/**
|
2014-04-10 11:43:15 +00:00
|
|
|
* GtkGesture::sequence-state-changed:
|
2014-04-09 16:27:42 +00:00
|
|
|
* @gesture: the object which received the signal
|
2021-03-01 06:38:10 +00:00
|
|
|
* @sequence: (nullable): the `GdkEventSequence` that was cancelled
|
2014-04-09 16:27:42 +00:00
|
|
|
* @state: the new sequence state
|
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* Emitted whenever a sequence state changes.
|
|
|
|
*
|
|
|
|
* See [method@Gtk.Gesture.set_sequence_state] to know
|
|
|
|
* more about the expectable sequence lifetimes.
|
2014-04-09 16:27:42 +00:00
|
|
|
*/
|
2013-01-17 19:59:07 +00:00
|
|
|
signals[SEQUENCE_STATE_CHANGED] =
|
2015-09-12 13:13:00 +00:00
|
|
|
g_signal_new (I_("sequence-state-changed"),
|
2013-01-17 19:59:07 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkGestureClass, sequence_state_changed),
|
2019-06-02 21:07:27 +00:00
|
|
|
NULL, NULL,
|
|
|
|
_gtk_marshal_VOID__BOXED_ENUM,
|
2014-05-20 12:10:31 +00:00
|
|
|
G_TYPE_NONE, 2, GDK_TYPE_EVENT_SEQUENCE,
|
2013-01-17 19:59:07 +00:00
|
|
|
GTK_TYPE_EVENT_SEQUENCE_STATE);
|
2019-06-02 21:07:27 +00:00
|
|
|
g_signal_set_va_marshaller (signals[SEQUENCE_STATE_CHANGED],
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
_gtk_marshal_VOID__BOXED_ENUMv);
|
2013-01-17 19:59:07 +00:00
|
|
|
}
|
|
|
|
|
2016-05-01 17:23:12 +00:00
|
|
|
static void
|
|
|
|
free_point_data (gpointer data)
|
|
|
|
{
|
|
|
|
PointData *point = data;
|
|
|
|
|
|
|
|
if (point->event)
|
2020-02-15 20:07:24 +00:00
|
|
|
gdk_event_unref (point->event);
|
2016-05-01 17:23:12 +00:00
|
|
|
|
2020-02-16 07:46:40 +00:00
|
|
|
if (point->target)
|
|
|
|
g_object_unref (point->target);
|
|
|
|
|
2016-05-01 17:23:12 +00:00
|
|
|
g_free (point);
|
|
|
|
}
|
|
|
|
|
2013-01-17 19:59:07 +00:00
|
|
|
static void
|
|
|
|
gtk_gesture_init (GtkGesture *gesture)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
priv->points = g_hash_table_new_full (NULL, NULL, NULL,
|
2016-05-01 17:23:12 +00:00
|
|
|
(GDestroyNotify) free_point_data);
|
2014-04-08 18:47:38 +00:00
|
|
|
priv->group_link = g_list_prepend (NULL, gesture);
|
2013-01-17 19:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_gesture_get_device:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* Returns the logical `GdkDevice` that is currently operating
|
|
|
|
* on @gesture.
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* This returns %NULL if the gesture is not being interacted.
|
|
|
|
*
|
2021-05-21 00:45:06 +00:00
|
|
|
* Returns: (nullable) (transfer none): a `GdkDevice`
|
2021-03-01 06:38:10 +00:00
|
|
|
*/
|
2013-01-17 19:59:07 +00:00
|
|
|
GdkDevice *
|
|
|
|
gtk_gesture_get_device (GtkGesture *gesture)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), NULL);
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
|
|
|
|
return priv->device;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_gesture_get_sequence_state:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
2021-05-20 13:17:04 +00:00
|
|
|
* @sequence: a `GdkEventSequence`
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
|
|
|
* Returns the @sequence state, as seen by @gesture.
|
|
|
|
*
|
2014-05-20 02:16:03 +00:00
|
|
|
* Returns: The sequence state in @gesture
|
2021-03-01 06:38:10 +00:00
|
|
|
*/
|
2013-01-17 19:59:07 +00:00
|
|
|
GtkEventSequenceState
|
|
|
|
gtk_gesture_get_sequence_state (GtkGesture *gesture,
|
|
|
|
GdkEventSequence *sequence)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
PointData *data;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture),
|
|
|
|
GTK_EVENT_SEQUENCE_NONE);
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
data = g_hash_table_lookup (priv->points, sequence);
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return GTK_EVENT_SEQUENCE_NONE;
|
|
|
|
|
|
|
|
return data->state;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_gesture_set_sequence_state:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
|
|
|
* @sequence: a `GdkEventSequence`
|
2013-01-17 19:59:07 +00:00
|
|
|
* @state: the sequence state
|
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* 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:
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
widget: Implement hierarchy-level mechanism to claim/deny sequences
The policy of sequence states has been made tighter on GtkGesture,
so gestures can never return to a "none" state, nor get out of a
"denied" state, a "claimed" sequence can go "denied" though.
The helper API at the widget level will first emit
GtkWidget::sequence-state-changed on the called widget, and then
notify through the same signal to every other widget in the captured
event chain. So the effect of that signal is twofold, on one hand
it lets the original widget set the state on its attached controllers,
and on the other hand it lets the other widgets freely adapt to the
sequence state changing elsewhere in the event widget chain.
By default, that signal updates every controller on the first usecase,
and propagates the default gesture policy to every other widget in the
chain on the second. This means that, by default:
1) Sequences start out on the "none" state, and get propagated through
all the event widget chain.
2) If a widget in the chain denies the sequence, all other widgets are
unaffected.
3) If a widget in the chain claims the sequence, then:
3.1) Every widget below the claiming widget (ie. towards the event widget)
will get the sequence cancelled.
3.2) Every widget above the claiming widget that had the sequence as "none"
will remain as such, if it was claimed it will go denied, but that should
rarely happen.
This behavior can be tweaked through the GtkWidget::sequence-state-changed and
GtkGesture::event-handled vmethods, although this should be very rarely done.
2014-03-03 13:08:45 +00:00
|
|
|
* * None
|
|
|
|
* * None → Denied
|
|
|
|
* * None → Claimed
|
|
|
|
* * None → Claimed → Denied
|
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* Note: Due to event handling ordering, it may be unsafe to set the
|
|
|
|
* state on another gesture within a [signal@Gtk.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:
|
2014-09-29 13:35:20 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* ```c
|
2014-09-29 13:35:20 +00:00
|
|
|
* static void
|
|
|
|
* first_gesture_begin_cb (GtkGesture *first_gesture,
|
|
|
|
* GdkEventSequence *sequence,
|
|
|
|
* gpointer user_data)
|
|
|
|
* {
|
2018-05-29 11:48:41 +00:00
|
|
|
* gtk_gesture_set_sequence_state (first_gesture, sequence, GTK_EVENT_SEQUENCE_CLAIMED);
|
2014-09-29 13:35:20 +00:00
|
|
|
* 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)
|
|
|
|
* {
|
2018-05-29 11:48:41 +00:00
|
|
|
* if (gtk_gesture_get_sequence_state (first_gesture, sequence) == GTK_EVENT_SEQUENCE_CLAIMED)
|
2014-09-29 13:35:20 +00:00
|
|
|
* gtk_gesture_set_sequence_state (second_gesture, sequence, GTK_EVENT_SEQUENCE_DENIED);
|
|
|
|
* }
|
2021-03-01 06:38:10 +00:00
|
|
|
* ```
|
2014-09-29 13:35:20 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2014-05-20 02:16:03 +00:00
|
|
|
* Returns: %TRUE if @sequence is handled by @gesture,
|
2021-03-01 06:38:10 +00:00
|
|
|
* and the state is changed successfully
|
|
|
|
*/
|
2013-01-17 19:59:07 +00:00
|
|
|
gboolean
|
|
|
|
gtk_gesture_set_sequence_state (GtkGesture *gesture,
|
|
|
|
GdkEventSequence *sequence,
|
|
|
|
GtkEventSequenceState state)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
PointData *data;
|
2021-01-22 16:37:20 +00:00
|
|
|
GtkEventSequenceState current_state;
|
2013-01-17 19:59:07 +00:00
|
|
|
|
2014-04-08 18:41:09 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), FALSE);
|
|
|
|
g_return_val_if_fail (state >= GTK_EVENT_SEQUENCE_NONE &&
|
|
|
|
state <= GTK_EVENT_SEQUENCE_DENIED, FALSE);
|
2013-01-17 19:59:07 +00:00
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
data = g_hash_table_lookup (priv->points, sequence);
|
|
|
|
|
2014-04-08 18:43:52 +00:00
|
|
|
if (!data)
|
2013-01-17 19:59:07 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2014-04-08 18:43:52 +00:00
|
|
|
if (data->state == state)
|
2014-05-07 17:08:50 +00:00
|
|
|
return FALSE;
|
2014-04-08 18:43:52 +00:00
|
|
|
|
widget: Implement hierarchy-level mechanism to claim/deny sequences
The policy of sequence states has been made tighter on GtkGesture,
so gestures can never return to a "none" state, nor get out of a
"denied" state, a "claimed" sequence can go "denied" though.
The helper API at the widget level will first emit
GtkWidget::sequence-state-changed on the called widget, and then
notify through the same signal to every other widget in the captured
event chain. So the effect of that signal is twofold, on one hand
it lets the original widget set the state on its attached controllers,
and on the other hand it lets the other widgets freely adapt to the
sequence state changing elsewhere in the event widget chain.
By default, that signal updates every controller on the first usecase,
and propagates the default gesture policy to every other widget in the
chain on the second. This means that, by default:
1) Sequences start out on the "none" state, and get propagated through
all the event widget chain.
2) If a widget in the chain denies the sequence, all other widgets are
unaffected.
3) If a widget in the chain claims the sequence, then:
3.1) Every widget below the claiming widget (ie. towards the event widget)
will get the sequence cancelled.
3.2) Every widget above the claiming widget that had the sequence as "none"
will remain as such, if it was claimed it will go denied, but that should
rarely happen.
This behavior can be tweaked through the GtkWidget::sequence-state-changed and
GtkGesture::event-handled vmethods, although this should be very rarely done.
2014-03-03 13:08:45 +00:00
|
|
|
/* denied sequences remain denied */
|
|
|
|
if (data->state == GTK_EVENT_SEQUENCE_DENIED)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Sequences can't go from claimed/denied to none */
|
|
|
|
if (state == GTK_EVENT_SEQUENCE_NONE &&
|
|
|
|
data->state != GTK_EVENT_SEQUENCE_NONE)
|
|
|
|
return FALSE;
|
|
|
|
|
2021-01-22 16:37:20 +00:00
|
|
|
current_state = data->state;
|
|
|
|
data->state = state;
|
|
|
|
|
2020-08-05 21:51:50 +00:00
|
|
|
if (state == GTK_EVENT_SEQUENCE_DENIED &&
|
2021-01-22 16:37:20 +00:00
|
|
|
current_state == GTK_EVENT_SEQUENCE_CLAIMED)
|
2020-08-05 21:51:50 +00:00
|
|
|
_gtk_gesture_cancel_sequence (gesture, sequence);
|
|
|
|
|
2018-05-14 17:03:17 +00:00
|
|
|
gtk_widget_cancel_event_sequence (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)),
|
|
|
|
gesture, sequence, state);
|
2013-01-17 19:59:07 +00:00
|
|
|
g_signal_emit (gesture, signals[SEQUENCE_STATE_CHANGED], 0,
|
2014-04-08 18:45:18 +00:00
|
|
|
sequence, state);
|
2014-03-24 12:11:47 +00:00
|
|
|
|
|
|
|
if (state == GTK_EVENT_SEQUENCE_DENIED)
|
|
|
|
_gtk_gesture_check_recognized (gesture, sequence);
|
|
|
|
|
2013-01-17 19:59:07 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-05-20 00:17:12 +00:00
|
|
|
/**
|
|
|
|
* gtk_gesture_set_state:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
2014-05-20 00:17:12 +00:00
|
|
|
* @state: the sequence state
|
|
|
|
*
|
|
|
|
* Sets the state of all sequences that @gesture is currently
|
2021-03-01 06:38:10 +00:00
|
|
|
* interacting with.
|
|
|
|
*
|
|
|
|
* See [method@Gtk.Gesture.set_sequence_state] for more details
|
|
|
|
* on sequence states.
|
2014-05-20 00:17:12 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if the state of at least one sequence
|
2021-03-01 06:38:10 +00:00
|
|
|
* was changed successfully
|
2014-05-20 00:17:12 +00:00
|
|
|
*/
|
2014-04-08 18:46:26 +00:00
|
|
|
gboolean
|
|
|
|
gtk_gesture_set_state (GtkGesture *gesture,
|
|
|
|
GtkEventSequenceState state)
|
|
|
|
{
|
|
|
|
gboolean handled = FALSE;
|
|
|
|
GtkGesturePrivate *priv;
|
2014-05-07 09:18:00 +00:00
|
|
|
GList *sequences, *l;
|
2014-04-08 18:46:26 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), FALSE);
|
|
|
|
g_return_val_if_fail (state >= GTK_EVENT_SEQUENCE_NONE &&
|
|
|
|
state <= GTK_EVENT_SEQUENCE_DENIED, FALSE);
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
2014-05-07 09:18:00 +00:00
|
|
|
sequences = g_hash_table_get_keys (priv->points);
|
2014-04-08 18:46:26 +00:00
|
|
|
|
2014-05-07 09:18:00 +00:00
|
|
|
for (l = sequences; l; l = l->next)
|
|
|
|
handled |= gtk_gesture_set_sequence_state (gesture, l->data, state);
|
|
|
|
|
|
|
|
g_list_free (sequences);
|
2014-04-08 18:46:26 +00:00
|
|
|
|
|
|
|
return handled;
|
|
|
|
}
|
|
|
|
|
2013-01-17 19:59:07 +00:00
|
|
|
/**
|
|
|
|
* gtk_gesture_get_sequences:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* Returns the list of `GdkEventSequences` currently being interpreted
|
2014-05-20 02:16:03 +00:00
|
|
|
* by @gesture.
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
2014-04-10 11:43:15 +00:00
|
|
|
* Returns: (transfer container) (element-type GdkEventSequence): A list
|
2021-03-01 06:38:10 +00:00
|
|
|
* 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()
|
|
|
|
*/
|
2013-01-17 19:59:07 +00:00
|
|
|
GList *
|
|
|
|
gtk_gesture_get_sequences (GtkGesture *gesture)
|
|
|
|
{
|
|
|
|
GdkEventSequence *sequence;
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
GList *sequences = NULL;
|
|
|
|
GHashTableIter iter;
|
|
|
|
PointData *data;
|
2017-08-25 14:47:11 +00:00
|
|
|
GdkEventType event_type;
|
2013-01-17 19:59:07 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), NULL);
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
g_hash_table_iter_init (&iter, priv->points);
|
|
|
|
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *) &sequence, (gpointer *) &data))
|
|
|
|
{
|
|
|
|
if (data->state == GTK_EVENT_SEQUENCE_DENIED)
|
|
|
|
continue;
|
2017-08-25 14:47:11 +00:00
|
|
|
|
|
|
|
event_type = gdk_event_get_event_type (data->event);
|
|
|
|
|
|
|
|
if (event_type == GDK_TOUCH_END ||
|
|
|
|
event_type == GDK_BUTTON_RELEASE)
|
2013-01-17 19:59:07 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
sequences = g_list_prepend (sequences, sequence);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sequences;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_gesture_get_last_updated_sequence:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* Returns the `GdkEventSequence` that was last updated on @gesture.
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
2016-02-08 13:02:25 +00:00
|
|
|
* Returns: (transfer none) (nullable): The last updated sequence
|
2021-03-01 06:38:10 +00:00
|
|
|
*/
|
2013-01-17 19:59:07 +00:00
|
|
|
GdkEventSequence *
|
|
|
|
gtk_gesture_get_last_updated_sequence (GtkGesture *gesture)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), NULL);
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
|
|
|
|
return priv->last_sequence;
|
|
|
|
}
|
|
|
|
|
2014-04-10 11:43:15 +00:00
|
|
|
/**
|
|
|
|
* gtk_gesture_get_last_event:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
|
|
|
* @sequence: (nullable): a `GdkEventSequence`
|
2014-04-10 11:43:15 +00:00
|
|
|
*
|
|
|
|
* Returns the last event that was processed for @sequence.
|
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* 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.
|
2016-05-11 17:25:15 +00:00
|
|
|
*
|
2015-12-11 09:05:37 +00:00
|
|
|
* Returns: (transfer none) (nullable): The last event from @sequence
|
2021-03-01 06:38:10 +00:00
|
|
|
*/
|
2020-02-16 16:09:02 +00:00
|
|
|
GdkEvent *
|
2013-01-17 19:59:07 +00:00
|
|
|
gtk_gesture_get_last_event (GtkGesture *gesture,
|
|
|
|
GdkEventSequence *sequence)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
PointData *data;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), NULL);
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
data = g_hash_table_lookup (priv->points, sequence);
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return data->event;
|
|
|
|
}
|
|
|
|
|
2020-02-16 07:46:40 +00:00
|
|
|
/*
|
|
|
|
* gtk_gesture_get_last_target:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
2020-02-16 07:46:40 +00:00
|
|
|
* @sequence: event sequence
|
|
|
|
*
|
|
|
|
* Returns the widget that the last event was targeted at.
|
2021-03-01 06:38:10 +00:00
|
|
|
*
|
|
|
|
* See [method@Gtk.Gesture.get_last_event].
|
2020-02-16 07:46:40 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer none) (nullable): The target of the last event
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_gesture_get_last_target (GtkGesture *gesture,
|
|
|
|
GdkEventSequence *sequence)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
PointData *data;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), NULL);
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
data = g_hash_table_lookup (priv->points, sequence);
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return data->target;
|
|
|
|
}
|
|
|
|
|
2013-01-17 19:59:07 +00:00
|
|
|
/**
|
|
|
|
* gtk_gesture_get_point:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
2021-05-19 11:24:34 +00:00
|
|
|
* @sequence: (nullable): a `GdkEventSequence`, or %NULL for pointer events
|
|
|
|
* @x: (out) (optional): return location for X axis of the sequence coordinates
|
|
|
|
* @y: (out) (optional): return location for Y axis of the sequence coordinates
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* 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.
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if @sequence is currently interpreted
|
2021-03-01 06:38:10 +00:00
|
|
|
*/
|
2013-01-17 19:59:07 +00:00
|
|
|
gboolean
|
|
|
|
gtk_gesture_get_point (GtkGesture *gesture,
|
|
|
|
GdkEventSequence *sequence,
|
2020-07-24 20:32:16 +00:00
|
|
|
double *x,
|
|
|
|
double *y)
|
2013-01-17 19:59:07 +00:00
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
PointData *data;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), FALSE);
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
|
|
|
|
if (!g_hash_table_lookup_extended (priv->points, sequence,
|
|
|
|
NULL, (gpointer *) &data))
|
|
|
|
return FALSE;
|
|
|
|
|
2014-03-24 12:04:51 +00:00
|
|
|
if (x)
|
|
|
|
*x = data->widget_x;
|
|
|
|
if (y)
|
|
|
|
*y = data->widget_y;
|
|
|
|
|
|
|
|
return TRUE;
|
2013-01-17 19:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2014-05-06 16:22:57 +00:00
|
|
|
_gtk_gesture_get_last_update_time (GtkGesture *gesture,
|
|
|
|
GdkEventSequence *sequence,
|
|
|
|
guint32 *evtime)
|
2013-01-17 19:59:07 +00:00
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
PointData *data;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), FALSE);
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
|
|
|
|
if (!g_hash_table_lookup_extended (priv->points, sequence,
|
|
|
|
NULL, (gpointer *) &data))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (evtime)
|
|
|
|
*evtime = gdk_event_get_time (data->event);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_gesture_get_bounding_box:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
2013-01-17 19:59:07 +00:00
|
|
|
* @rect: (out): bounding box containing all active touches.
|
|
|
|
*
|
|
|
|
* If there are touch sequences being currently handled by @gesture,
|
2021-03-01 06:38:10 +00:00
|
|
|
* returns %TRUE and fills in @rect with the bounding box containing
|
|
|
|
* all active touches.
|
|
|
|
*
|
|
|
|
* Otherwise, %FALSE will be returned.
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
2015-07-24 10:59:59 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2014-05-20 02:16:03 +00:00
|
|
|
* Returns: %TRUE if there are active touches, %FALSE otherwise
|
2021-03-01 06:38:10 +00:00
|
|
|
*/
|
2013-01-17 19:59:07 +00:00
|
|
|
gboolean
|
|
|
|
gtk_gesture_get_bounding_box (GtkGesture *gesture,
|
|
|
|
GdkRectangle *rect)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
2020-07-24 20:32:16 +00:00
|
|
|
double x1, y1, x2, y2;
|
2013-01-17 19:59:07 +00:00
|
|
|
GHashTableIter iter;
|
|
|
|
guint n_points = 0;
|
|
|
|
PointData *data;
|
2017-08-25 14:47:11 +00:00
|
|
|
GdkEventType event_type;
|
2013-01-17 19:59:07 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), FALSE);
|
|
|
|
g_return_val_if_fail (rect != NULL, FALSE);
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
x1 = y1 = G_MAXDOUBLE;
|
|
|
|
x2 = y2 = -G_MAXDOUBLE;
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, priv->points);
|
|
|
|
|
|
|
|
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &data))
|
|
|
|
{
|
|
|
|
if (data->state == GTK_EVENT_SEQUENCE_DENIED)
|
|
|
|
continue;
|
2017-08-25 14:47:11 +00:00
|
|
|
|
|
|
|
event_type = gdk_event_get_event_type (data->event);
|
|
|
|
|
|
|
|
if (event_type == GDK_TOUCH_END ||
|
|
|
|
event_type == GDK_BUTTON_RELEASE)
|
2013-01-17 19:59:07 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
n_points++;
|
2020-03-28 19:03:33 +00:00
|
|
|
x1 = MIN (x1, data->widget_x);
|
|
|
|
y1 = MIN (y1, data->widget_y);
|
|
|
|
x2 = MAX (x2, data->widget_x);
|
|
|
|
y2 = MAX (y2, data->widget_y);
|
2013-01-17 19:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (n_points == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
rect->x = x1;
|
|
|
|
rect->y = y1;
|
|
|
|
rect->width = x2 - x1;
|
|
|
|
rect->height = y2 - y1;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_gesture_get_bounding_box_center:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
2013-01-17 19:59:07 +00:00
|
|
|
* @x: (out): X coordinate for the bounding box center
|
|
|
|
* @y: (out): Y coordinate for the bounding box center
|
|
|
|
*
|
|
|
|
* If there are touch sequences being currently handled by @gesture,
|
2021-03-01 06:38:10 +00:00
|
|
|
* returns %TRUE and fills in @x and @y with the center of the bounding
|
|
|
|
* box containing all active touches.
|
|
|
|
*
|
|
|
|
* Otherwise, %FALSE will be returned.
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
2014-05-20 02:16:03 +00:00
|
|
|
* Returns: %FALSE if no active touches are present, %TRUE otherwise
|
2021-03-01 06:38:10 +00:00
|
|
|
*/
|
2013-01-17 19:59:07 +00:00
|
|
|
gboolean
|
|
|
|
gtk_gesture_get_bounding_box_center (GtkGesture *gesture,
|
2020-07-24 20:32:16 +00:00
|
|
|
double *x,
|
|
|
|
double *y)
|
2013-01-17 19:59:07 +00:00
|
|
|
{
|
2020-02-16 16:09:02 +00:00
|
|
|
GdkEvent *last_event;
|
2013-01-17 19:59:07 +00:00
|
|
|
GdkRectangle rect;
|
2019-12-17 11:28:17 +00:00
|
|
|
GdkEventSequence *sequence;
|
2013-01-17 19:59:07 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), FALSE);
|
|
|
|
g_return_val_if_fail (x != NULL && y != NULL, FALSE);
|
|
|
|
|
2019-12-17 11:28:17 +00:00
|
|
|
sequence = gtk_gesture_get_last_updated_sequence (gesture);
|
|
|
|
last_event = gtk_gesture_get_last_event (gesture, sequence);
|
|
|
|
|
|
|
|
if (EVENT_IS_TOUCHPAD_GESTURE (last_event))
|
|
|
|
return gtk_gesture_get_point (gesture, sequence, x, y);
|
|
|
|
else if (!gtk_gesture_get_bounding_box (gesture, &rect))
|
2013-01-17 19:59:07 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*x = rect.x + rect.width / 2;
|
|
|
|
*y = rect.y + rect.height / 2;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_gesture_is_active:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
|
|
|
* Returns %TRUE if the gesture is currently active.
|
2021-03-01 06:38:10 +00:00
|
|
|
*
|
|
|
|
* A gesture is active while there are touch sequences
|
2013-01-17 19:59:07 +00:00
|
|
|
* interacting with it.
|
|
|
|
*
|
2014-05-20 02:16:03 +00:00
|
|
|
* Returns: %TRUE if gesture is active
|
2021-03-01 06:38:10 +00:00
|
|
|
*/
|
2013-01-17 19:59:07 +00:00
|
|
|
gboolean
|
|
|
|
gtk_gesture_is_active (GtkGesture *gesture)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), FALSE);
|
|
|
|
|
2015-07-09 17:11:04 +00:00
|
|
|
return _gtk_gesture_get_n_physical_points (gesture, TRUE) != 0;
|
2013-01-17 19:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_gesture_is_recognized:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
|
|
|
* Returns %TRUE if the gesture is currently recognized.
|
2021-03-01 06:38:10 +00:00
|
|
|
*
|
2013-01-17 19:59:07 +00:00
|
|
|
* A gesture is recognized if there are as many interacting
|
2020-08-05 01:17:49 +00:00
|
|
|
* touch sequences as required by @gesture.
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
2014-05-20 02:16:03 +00:00
|
|
|
* Returns: %TRUE if gesture is recognized
|
2021-03-01 06:38:10 +00:00
|
|
|
*/
|
2013-01-17 19:59:07 +00:00
|
|
|
gboolean
|
|
|
|
gtk_gesture_is_recognized (GtkGesture *gesture)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), FALSE);
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
|
|
|
|
return priv->recognized;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2014-05-06 16:04:25 +00:00
|
|
|
_gtk_gesture_check (GtkGesture *gesture)
|
2013-01-17 19:59:07 +00:00
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), FALSE);
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
|
|
|
|
return _gtk_gesture_check_recognized (gesture, priv->last_sequence);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_gesture_handles_sequence:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
2021-05-21 00:45:06 +00:00
|
|
|
* @sequence: (nullable): a `GdkEventSequence`
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* Returns %TRUE if @gesture is currently handling events
|
|
|
|
* corresponding to @sequence.
|
2013-01-17 19:59:07 +00:00
|
|
|
*
|
2017-02-16 11:22:33 +00:00
|
|
|
* Returns: %TRUE if @gesture is handling @sequence, %FALSE otherwise
|
2021-03-01 06:38:10 +00:00
|
|
|
*/
|
2013-01-17 19:59:07 +00:00
|
|
|
gboolean
|
|
|
|
gtk_gesture_handles_sequence (GtkGesture *gesture,
|
|
|
|
GdkEventSequence *sequence)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
2014-03-21 17:09:38 +00:00
|
|
|
PointData *data;
|
2013-01-17 19:59:07 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), FALSE);
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
2014-03-21 17:09:38 +00:00
|
|
|
data = g_hash_table_lookup (priv->points, sequence);
|
2013-01-17 19:59:07 +00:00
|
|
|
|
2014-03-21 17:09:38 +00:00
|
|
|
if (!data)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (data->state == GTK_EVENT_SEQUENCE_DENIED)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2013-01-17 19:59:07 +00:00
|
|
|
}
|
widget: Implement hierarchy-level mechanism to claim/deny sequences
The policy of sequence states has been made tighter on GtkGesture,
so gestures can never return to a "none" state, nor get out of a
"denied" state, a "claimed" sequence can go "denied" though.
The helper API at the widget level will first emit
GtkWidget::sequence-state-changed on the called widget, and then
notify through the same signal to every other widget in the captured
event chain. So the effect of that signal is twofold, on one hand
it lets the original widget set the state on its attached controllers,
and on the other hand it lets the other widgets freely adapt to the
sequence state changing elsewhere in the event widget chain.
By default, that signal updates every controller on the first usecase,
and propagates the default gesture policy to every other widget in the
chain on the second. This means that, by default:
1) Sequences start out on the "none" state, and get propagated through
all the event widget chain.
2) If a widget in the chain denies the sequence, all other widgets are
unaffected.
3) If a widget in the chain claims the sequence, then:
3.1) Every widget below the claiming widget (ie. towards the event widget)
will get the sequence cancelled.
3.2) Every widget above the claiming widget that had the sequence as "none"
will remain as such, if it was claimed it will go denied, but that should
rarely happen.
This behavior can be tweaked through the GtkWidget::sequence-state-changed and
GtkGesture::event-handled vmethods, although this should be very rarely done.
2014-03-03 13:08:45 +00:00
|
|
|
|
|
|
|
gboolean
|
2014-05-06 16:10:32 +00:00
|
|
|
_gtk_gesture_cancel_sequence (GtkGesture *gesture,
|
|
|
|
GdkEventSequence *sequence)
|
widget: Implement hierarchy-level mechanism to claim/deny sequences
The policy of sequence states has been made tighter on GtkGesture,
so gestures can never return to a "none" state, nor get out of a
"denied" state, a "claimed" sequence can go "denied" though.
The helper API at the widget level will first emit
GtkWidget::sequence-state-changed on the called widget, and then
notify through the same signal to every other widget in the captured
event chain. So the effect of that signal is twofold, on one hand
it lets the original widget set the state on its attached controllers,
and on the other hand it lets the other widgets freely adapt to the
sequence state changing elsewhere in the event widget chain.
By default, that signal updates every controller on the first usecase,
and propagates the default gesture policy to every other widget in the
chain on the second. This means that, by default:
1) Sequences start out on the "none" state, and get propagated through
all the event widget chain.
2) If a widget in the chain denies the sequence, all other widgets are
unaffected.
3) If a widget in the chain claims the sequence, then:
3.1) Every widget below the claiming widget (ie. towards the event widget)
will get the sequence cancelled.
3.2) Every widget above the claiming widget that had the sequence as "none"
will remain as such, if it was claimed it will go denied, but that should
rarely happen.
This behavior can be tweaked through the GtkWidget::sequence-state-changed and
GtkGesture::event-handled vmethods, although this should be very rarely done.
2014-03-03 13:08:45 +00:00
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
PointData *data;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), FALSE);
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
data = g_hash_table_lookup (priv->points, sequence);
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_signal_emit (gesture, signals[CANCEL], 0, sequence);
|
|
|
|
_gtk_gesture_remove_point (gesture, data->event);
|
2015-02-25 19:30:11 +00:00
|
|
|
_gtk_gesture_check_recognized (gesture, sequence);
|
|
|
|
|
widget: Implement hierarchy-level mechanism to claim/deny sequences
The policy of sequence states has been made tighter on GtkGesture,
so gestures can never return to a "none" state, nor get out of a
"denied" state, a "claimed" sequence can go "denied" though.
The helper API at the widget level will first emit
GtkWidget::sequence-state-changed on the called widget, and then
notify through the same signal to every other widget in the captured
event chain. So the effect of that signal is twofold, on one hand
it lets the original widget set the state on its attached controllers,
and on the other hand it lets the other widgets freely adapt to the
sequence state changing elsewhere in the event widget chain.
By default, that signal updates every controller on the first usecase,
and propagates the default gesture policy to every other widget in the
chain on the second. This means that, by default:
1) Sequences start out on the "none" state, and get propagated through
all the event widget chain.
2) If a widget in the chain denies the sequence, all other widgets are
unaffected.
3) If a widget in the chain claims the sequence, then:
3.1) Every widget below the claiming widget (ie. towards the event widget)
will get the sequence cancelled.
3.2) Every widget above the claiming widget that had the sequence as "none"
will remain as such, if it was claimed it will go denied, but that should
rarely happen.
This behavior can be tweaked through the GtkWidget::sequence-state-changed and
GtkGesture::event-handled vmethods, although this should be very rarely done.
2014-03-03 13:08:45 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-03-03 19:46:10 +00:00
|
|
|
|
2014-04-08 18:47:38 +00:00
|
|
|
GList *
|
|
|
|
_gtk_gesture_get_group_link (GtkGesture *gesture)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
|
|
|
|
return priv->group_link;
|
|
|
|
}
|
|
|
|
|
2014-04-09 16:27:42 +00:00
|
|
|
/**
|
|
|
|
* gtk_gesture_group:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
|
|
|
* @group_gesture: `GtkGesture` to group @gesture with
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* Adds @gesture to the same group than @group_gesture.
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* Gestures are by default isolated in their own groups.
|
2018-03-08 22:49:41 +00:00
|
|
|
*
|
2021-03-01 06:38:10 +00:00
|
|
|
* 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
|
|
|
|
* [method@Gtk.Gesture.set_sequence_state], on one will transfer
|
|
|
|
* the same value to the others.
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
|
|
|
* Groups also perform an "implicit grabbing" of sequences, if a
|
2021-03-01 06:38:10 +00:00
|
|
|
* `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.
|
|
|
|
*/
|
2014-04-08 18:47:38 +00:00
|
|
|
void
|
|
|
|
gtk_gesture_group (GtkGesture *gesture,
|
|
|
|
GtkGesture *group_gesture)
|
|
|
|
{
|
|
|
|
GList *link, *group_link, *next;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_GESTURE (gesture));
|
|
|
|
g_return_if_fail (GTK_IS_GESTURE (group_gesture));
|
|
|
|
g_return_if_fail (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (group_gesture)) ==
|
|
|
|
gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)));
|
|
|
|
|
|
|
|
link = _gtk_gesture_get_group_link (gesture);
|
|
|
|
|
|
|
|
if (link->prev || link->next)
|
|
|
|
{
|
|
|
|
if (gtk_gesture_is_grouped_with (gesture, group_gesture))
|
|
|
|
return;
|
|
|
|
gtk_gesture_ungroup (gesture);
|
|
|
|
}
|
|
|
|
|
|
|
|
group_link = _gtk_gesture_get_group_link (group_gesture);
|
|
|
|
next = group_link->next;
|
|
|
|
|
|
|
|
/* Rewire link so it's inserted after the group_gesture elem */
|
|
|
|
link->prev = group_link;
|
|
|
|
link->next = next;
|
|
|
|
group_link->next = link;
|
|
|
|
if (next)
|
|
|
|
next->prev = link;
|
|
|
|
}
|
|
|
|
|
2014-04-09 16:27:42 +00:00
|
|
|
/**
|
|
|
|
* gtk_gesture_ungroup:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2014-04-10 11:43:15 +00:00
|
|
|
* Separates @gesture into an isolated group.
|
2021-03-01 06:38:10 +00:00
|
|
|
*/
|
2014-04-08 18:47:38 +00:00
|
|
|
void
|
|
|
|
gtk_gesture_ungroup (GtkGesture *gesture)
|
|
|
|
{
|
|
|
|
GList *link, *prev, *next;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_GESTURE (gesture));
|
|
|
|
|
|
|
|
link = _gtk_gesture_get_group_link (gesture);
|
|
|
|
prev = link->prev;
|
|
|
|
next = link->next;
|
|
|
|
|
|
|
|
/* Detach link from the group chain */
|
|
|
|
if (prev)
|
|
|
|
prev->next = next;
|
|
|
|
if (next)
|
|
|
|
next->prev = prev;
|
|
|
|
|
|
|
|
link->next = link->prev = NULL;
|
|
|
|
}
|
|
|
|
|
2014-04-09 16:27:42 +00:00
|
|
|
/**
|
|
|
|
* gtk_gesture_get_group:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
|
|
|
* Returns all gestures in the group of @gesture
|
|
|
|
*
|
|
|
|
* Returns: (element-type GtkGesture) (transfer container): The list
|
2021-03-01 06:38:10 +00:00
|
|
|
* of `GtkGesture`s, free with g_list_free()
|
|
|
|
*/
|
2014-04-08 18:47:38 +00:00
|
|
|
GList *
|
|
|
|
gtk_gesture_get_group (GtkGesture *gesture)
|
|
|
|
{
|
|
|
|
GList *link;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), NULL);
|
|
|
|
|
|
|
|
link = _gtk_gesture_get_group_link (gesture);
|
|
|
|
|
|
|
|
return g_list_copy (g_list_first (link));
|
|
|
|
}
|
|
|
|
|
2014-04-09 16:27:42 +00:00
|
|
|
/**
|
|
|
|
* gtk_gesture_is_grouped_with:
|
2021-03-01 06:38:10 +00:00
|
|
|
* @gesture: a `GtkGesture`
|
|
|
|
* @other: another `GtkGesture`
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
2014-05-20 02:16:03 +00:00
|
|
|
* Returns %TRUE if both gestures pertain to the same group.
|
2014-04-09 16:27:42 +00:00
|
|
|
*
|
|
|
|
* Returns: whether the gestures are grouped
|
2021-03-01 06:38:10 +00:00
|
|
|
*/
|
2014-04-08 18:47:38 +00:00
|
|
|
gboolean
|
|
|
|
gtk_gesture_is_grouped_with (GtkGesture *gesture,
|
|
|
|
GtkGesture *other)
|
|
|
|
{
|
|
|
|
GList *link;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), FALSE);
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (other), FALSE);
|
|
|
|
|
|
|
|
link = _gtk_gesture_get_group_link (gesture);
|
|
|
|
link = g_list_first (link);
|
|
|
|
|
|
|
|
return g_list_find (link, other) != NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-03 19:46:10 +00:00
|
|
|
gboolean
|
|
|
|
_gtk_gesture_handled_sequence_press (GtkGesture *gesture,
|
|
|
|
GdkEventSequence *sequence)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
PointData *data;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), FALSE);
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
data = g_hash_table_lookup (priv->points, sequence);
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return data->press_handled;
|
|
|
|
}
|
2014-03-26 09:25:09 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
_gtk_gesture_get_pointer_emulating_sequence (GtkGesture *gesture,
|
|
|
|
GdkEventSequence **sequence)
|
|
|
|
{
|
|
|
|
GtkGesturePrivate *priv;
|
|
|
|
GdkEventSequence *seq;
|
|
|
|
GHashTableIter iter;
|
|
|
|
PointData *data;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_GESTURE (gesture), FALSE);
|
|
|
|
|
|
|
|
priv = gtk_gesture_get_instance_private (gesture);
|
|
|
|
g_hash_table_iter_init (&iter, priv->points);
|
|
|
|
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer*) &seq, (gpointer*) &data))
|
|
|
|
{
|
2017-10-06 19:19:42 +00:00
|
|
|
switch ((guint) gdk_event_get_event_type (data->event))
|
2014-03-26 09:25:09 +00:00
|
|
|
{
|
|
|
|
case GDK_TOUCH_BEGIN:
|
|
|
|
case GDK_TOUCH_UPDATE:
|
|
|
|
case GDK_TOUCH_END:
|
2020-02-18 03:11:56 +00:00
|
|
|
if (!gdk_touch_event_get_emulating_pointer (data->event))
|
2014-03-26 09:25:09 +00:00
|
|
|
continue;
|
2020-03-12 07:32:03 +00:00
|
|
|
G_GNUC_FALLTHROUGH;
|
2014-03-26 09:25:09 +00:00
|
|
|
case GDK_BUTTON_PRESS:
|
|
|
|
case GDK_BUTTON_RELEASE:
|
|
|
|
case GDK_MOTION_NOTIFY:
|
|
|
|
*sequence = seq;
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|