2013-01-17 19:55:24 +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-08 19:01:13 +00:00
|
|
|
|
|
|
|
/**
|
2021-03-01 06:33:51 +00:00
|
|
|
* GtkEventController:
|
|
|
|
*
|
|
|
|
* `GtkEventController` is the base class for event controllers.
|
|
|
|
*
|
|
|
|
* These are ancillary objects associated to widgets, which react
|
|
|
|
* to `GdkEvents`, and possibly trigger actions as a consequence.
|
|
|
|
*
|
|
|
|
* Event controllers are added to a widget with
|
|
|
|
* [method@Gtk.Widget.add_controller]. It is rarely necessary to
|
|
|
|
* explicitly remove a controller with [method@Gtk.Widget.remove_controller].
|
|
|
|
*
|
2021-05-22 18:27:25 +00:00
|
|
|
* See the chapter on [input handling](input-handling.html) for
|
2021-03-01 06:33:51 +00:00
|
|
|
* an overview of the basic concepts, such as the capture and bubble
|
|
|
|
* phases of even propagation.
|
2014-04-08 19:01:13 +00:00
|
|
|
*/
|
|
|
|
|
2013-01-17 19:55:24 +00:00
|
|
|
#include "config.h"
|
2014-05-06 02:40:18 +00:00
|
|
|
#include "gtkeventcontroller.h"
|
|
|
|
#include "gtkeventcontrollerprivate.h"
|
2019-04-29 02:19:44 +00:00
|
|
|
|
2014-05-26 12:02:30 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2014-04-08 18:25:53 +00:00
|
|
|
#include "gtktypebuiltins.h"
|
2013-01-17 19:55:24 +00:00
|
|
|
#include "gtkmarshalers.h"
|
|
|
|
#include "gtkprivate.h"
|
|
|
|
#include "gtkintl.h"
|
2019-04-29 02:19:44 +00:00
|
|
|
#include "gtknative.h"
|
2013-01-17 19:55:24 +00:00
|
|
|
|
|
|
|
typedef struct _GtkEventControllerPrivate GtkEventControllerPrivate;
|
|
|
|
|
|
|
|
enum {
|
2014-05-26 12:02:30 +00:00
|
|
|
PROP_WIDGET = 1,
|
2015-09-06 14:46:15 +00:00
|
|
|
PROP_PROPAGATION_PHASE,
|
2019-04-29 02:19:44 +00:00
|
|
|
PROP_PROPAGATION_LIMIT,
|
2019-06-19 11:09:38 +00:00
|
|
|
PROP_NAME,
|
2015-09-06 14:46:15 +00:00
|
|
|
LAST_PROP
|
2013-01-17 19:55:24 +00:00
|
|
|
};
|
|
|
|
|
2015-09-06 14:46:15 +00:00
|
|
|
static GParamSpec *properties[LAST_PROP] = { NULL, };
|
|
|
|
|
2013-01-17 19:55:24 +00:00
|
|
|
struct _GtkEventControllerPrivate
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2014-05-26 12:02:30 +00:00
|
|
|
GtkPropagationPhase phase;
|
2019-04-29 02:19:44 +00:00
|
|
|
GtkPropagationLimit limit;
|
2019-06-19 11:09:38 +00:00
|
|
|
char *name;
|
2020-02-16 07:46:05 +00:00
|
|
|
GtkWidget *target;
|
2020-04-11 16:40:21 +00:00
|
|
|
GdkEvent *event;
|
2013-01-17 19:55:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GtkEventController, gtk_event_controller, G_TYPE_OBJECT)
|
|
|
|
|
2018-03-08 02:30:44 +00:00
|
|
|
static void
|
|
|
|
gtk_event_controller_set_widget (GtkEventController *self,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (self);
|
|
|
|
|
|
|
|
priv->widget = widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_event_controller_unset_widget (GtkEventController *self)
|
|
|
|
{
|
|
|
|
GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (self);
|
|
|
|
|
|
|
|
priv->widget = NULL;
|
|
|
|
}
|
|
|
|
|
2019-05-02 19:11:30 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_event_controller_filter_event_default (GtkEventController *self,
|
2020-02-16 16:09:02 +00:00
|
|
|
GdkEvent *event)
|
2019-05-02 19:11:30 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-01-17 19:55:24 +00:00
|
|
|
static gboolean
|
2018-03-08 02:30:44 +00:00
|
|
|
gtk_event_controller_handle_event_default (GtkEventController *self,
|
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:55:24 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-02-13 01:26:29 +00:00
|
|
|
static void
|
|
|
|
gtk_event_controller_handle_crossing_default (GtkEventController *self,
|
|
|
|
const GtkCrossingData *crossing,
|
|
|
|
double x,
|
|
|
|
double y)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-17 19:55:24 +00:00
|
|
|
static void
|
|
|
|
gtk_event_controller_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2018-03-07 00:56:32 +00:00
|
|
|
GtkEventController *self = GTK_EVENT_CONTROLLER (object);
|
2019-06-19 11:09:38 +00:00
|
|
|
GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (self);
|
2013-01-17 19:55:24 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2014-05-26 12:02:30 +00:00
|
|
|
case PROP_PROPAGATION_PHASE:
|
2018-03-07 00:56:32 +00:00
|
|
|
gtk_event_controller_set_propagation_phase (self,
|
2014-05-26 12:02:30 +00:00
|
|
|
g_value_get_enum (value));
|
|
|
|
break;
|
2019-04-29 02:19:44 +00:00
|
|
|
case PROP_PROPAGATION_LIMIT:
|
|
|
|
gtk_event_controller_set_propagation_limit (self,
|
|
|
|
g_value_get_enum (value));
|
|
|
|
break;
|
2019-06-19 11:09:38 +00:00
|
|
|
case PROP_NAME:
|
|
|
|
g_free (priv->name);
|
|
|
|
priv->name = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
|
2013-01-17 19:55:24 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_event_controller_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2018-03-07 00:56:32 +00:00
|
|
|
GtkEventController *self = GTK_EVENT_CONTROLLER (object);
|
|
|
|
GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (self);
|
2013-01-17 19:55:24 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_WIDGET:
|
|
|
|
g_value_set_object (value, priv->widget);
|
|
|
|
break;
|
2014-05-26 12:02:30 +00:00
|
|
|
case PROP_PROPAGATION_PHASE:
|
|
|
|
g_value_set_enum (value, priv->phase);
|
|
|
|
break;
|
2019-04-29 02:19:44 +00:00
|
|
|
case PROP_PROPAGATION_LIMIT:
|
|
|
|
g_value_set_enum (value, priv->limit);
|
|
|
|
break;
|
2019-06-19 11:09:38 +00:00
|
|
|
case PROP_NAME:
|
|
|
|
g_value_set_string (value, priv->name);
|
|
|
|
break;
|
2013-01-17 19:55:24 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-19 11:09:38 +00:00
|
|
|
static void
|
|
|
|
gtk_event_controller_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkEventController *self = GTK_EVENT_CONTROLLER (object);
|
|
|
|
GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (self);
|
|
|
|
|
|
|
|
g_free (priv->name);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_event_controller_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2013-01-17 19:55:24 +00:00
|
|
|
static void
|
|
|
|
gtk_event_controller_class_init (GtkEventControllerClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2018-03-08 02:30:44 +00:00
|
|
|
klass->set_widget = gtk_event_controller_set_widget;
|
|
|
|
klass->unset_widget = gtk_event_controller_unset_widget;
|
2019-05-02 19:11:30 +00:00
|
|
|
klass->filter_event = gtk_event_controller_filter_event_default;
|
2013-01-17 19:55:24 +00:00
|
|
|
klass->handle_event = gtk_event_controller_handle_event_default;
|
2020-02-13 01:26:29 +00:00
|
|
|
klass->handle_crossing = gtk_event_controller_handle_crossing_default;
|
2013-01-17 19:55:24 +00:00
|
|
|
|
2019-06-19 11:09:38 +00:00
|
|
|
object_class->finalize = gtk_event_controller_finalize;
|
2013-01-17 19:55:24 +00:00
|
|
|
object_class->set_property = gtk_event_controller_set_property;
|
|
|
|
object_class->get_property = gtk_event_controller_get_property;
|
|
|
|
|
2014-04-09 16:27:31 +00:00
|
|
|
/**
|
2021-03-01 06:33:51 +00:00
|
|
|
* GtkEventController:widget: (attributes org.gtk.Property.get=gtk_event_controller_get_widget)
|
2014-04-09 16:27:31 +00:00
|
|
|
*
|
2021-03-01 06:33:51 +00:00
|
|
|
* The widget receiving the `GdkEvents` that the controller will handle.
|
2014-04-09 16:27:31 +00:00
|
|
|
*/
|
2015-09-06 14:46:15 +00:00
|
|
|
properties[PROP_WIDGET] =
|
|
|
|
g_param_spec_object ("widget",
|
|
|
|
P_("Widget"),
|
|
|
|
P_("Widget the gesture relates to"),
|
|
|
|
GTK_TYPE_WIDGET,
|
2018-03-10 19:02:28 +00:00
|
|
|
GTK_PARAM_READABLE);
|
2019-04-29 02:19:44 +00:00
|
|
|
|
2014-05-26 12:02:30 +00:00
|
|
|
/**
|
2021-03-01 06:33:51 +00:00
|
|
|
* GtkEventController:propagation-phase: (attributes org.gtk.Property.get=gtk_event_controller_get_propagation_phase org.gtk.Property.set=gtk_event_controller_set_propagation_phase)
|
2014-05-26 12:02:30 +00:00
|
|
|
*
|
|
|
|
* The propagation phase at which this controller will handle events.
|
|
|
|
*/
|
2015-09-06 14:46:15 +00:00
|
|
|
properties[PROP_PROPAGATION_PHASE] =
|
|
|
|
g_param_spec_enum ("propagation-phase",
|
|
|
|
P_("Propagation phase"),
|
|
|
|
P_("Propagation phase at which this controller is run"),
|
|
|
|
GTK_TYPE_PROPAGATION_PHASE,
|
|
|
|
GTK_PHASE_BUBBLE,
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
2019-04-29 02:19:44 +00:00
|
|
|
/**
|
2021-03-01 06:33:51 +00:00
|
|
|
* GtkEventController:propagation-limit: (attributes org.gtk.Property.get=gtk_event_controller_get_propagation_limit org.gtk.Property.set=gtk_event_controller_set_propagation_limit)
|
2019-04-29 02:19:44 +00:00
|
|
|
*
|
|
|
|
* The limit for which events this controller will handle.
|
|
|
|
*/
|
|
|
|
properties[PROP_PROPAGATION_LIMIT] =
|
|
|
|
g_param_spec_enum ("propagation-limit",
|
|
|
|
P_("Propagation limit"),
|
|
|
|
P_("Propagation limit for events handled by this controller"),
|
|
|
|
GTK_TYPE_PROPAGATION_LIMIT,
|
|
|
|
GTK_LIMIT_SAME_NATIVE,
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
2020-12-15 15:55:15 +00:00
|
|
|
/**
|
2021-03-01 06:33:51 +00:00
|
|
|
* GtkEventController:name: (attributes org.gtk.Property.get=gtk_event_controller_get_name org.gtk.Property.set=gtk_event_controller_set_name)
|
2020-12-15 15:55:15 +00:00
|
|
|
*
|
|
|
|
* The name for this controller, typically used for debugging purposes.
|
|
|
|
*/
|
2019-06-19 11:09:38 +00:00
|
|
|
properties[PROP_NAME] =
|
|
|
|
g_param_spec_string ("name",
|
|
|
|
P_("Name"),
|
|
|
|
P_("Name for this controller"),
|
|
|
|
NULL,
|
|
|
|
GTK_PARAM_READWRITE);
|
|
|
|
|
2015-09-06 14:46:15 +00:00
|
|
|
g_object_class_install_properties (object_class, LAST_PROP, properties);
|
2013-01-17 19:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_event_controller_init (GtkEventController *controller)
|
|
|
|
{
|
2014-08-11 18:38:51 +00:00
|
|
|
GtkEventControllerPrivate *priv;
|
|
|
|
|
|
|
|
priv = gtk_event_controller_get_instance_private (controller);
|
|
|
|
priv->phase = GTK_PHASE_BUBBLE;
|
2019-04-29 02:19:44 +00:00
|
|
|
priv->limit = GTK_LIMIT_SAME_NATIVE;
|
2013-01-17 19:55:24 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 07:20:34 +00:00
|
|
|
static gboolean
|
|
|
|
same_native (GtkWidget *widget,
|
|
|
|
GtkWidget *target)
|
|
|
|
{
|
2020-04-29 06:11:07 +00:00
|
|
|
GtkNative *native;
|
|
|
|
GtkNative *native2;
|
2020-02-16 07:20:34 +00:00
|
|
|
|
|
|
|
if (!widget || !target)
|
|
|
|
return TRUE;
|
|
|
|
|
2020-04-29 06:11:07 +00:00
|
|
|
native = gtk_widget_get_native (widget);
|
|
|
|
native2 = gtk_widget_get_native (target);
|
2020-02-16 07:20:34 +00:00
|
|
|
|
|
|
|
return native == native2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_event_controller_filter_event (GtkEventController *controller,
|
2020-02-16 16:09:02 +00:00
|
|
|
GdkEvent *event,
|
2020-02-16 07:20:34 +00:00
|
|
|
GtkWidget *target)
|
|
|
|
{
|
|
|
|
GtkEventControllerPrivate *priv;
|
|
|
|
GtkEventControllerClass *controller_class;
|
|
|
|
|
|
|
|
priv = gtk_event_controller_get_instance_private (controller);
|
|
|
|
|
|
|
|
if (priv->widget && !gtk_widget_is_sensitive (priv->widget))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (priv->limit == GTK_LIMIT_SAME_NATIVE &&
|
|
|
|
!same_native (priv->widget, target))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
controller_class = GTK_EVENT_CONTROLLER_GET_CLASS (controller);
|
|
|
|
|
|
|
|
return controller_class->filter_event (controller, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_event_controller_filter_crossing (GtkEventController *controller,
|
|
|
|
const GtkCrossingData *data)
|
|
|
|
{
|
|
|
|
GtkEventControllerPrivate *priv;
|
2020-05-29 23:39:15 +00:00
|
|
|
GtkWidget *old_target, *new_target;
|
2020-02-16 07:20:34 +00:00
|
|
|
|
|
|
|
priv = gtk_event_controller_get_instance_private (controller);
|
|
|
|
|
|
|
|
if (priv->widget && !gtk_widget_is_sensitive (priv->widget))
|
|
|
|
return TRUE;
|
|
|
|
|
2020-05-29 23:39:15 +00:00
|
|
|
old_target = data->old_target;
|
|
|
|
new_target = data->new_target;
|
|
|
|
|
|
|
|
if (priv->limit == GTK_LIMIT_SAME_NATIVE)
|
|
|
|
{
|
|
|
|
/* treat out-of-scope targets like NULL */
|
|
|
|
|
|
|
|
if (!same_native (priv->widget, old_target))
|
|
|
|
old_target = NULL;
|
|
|
|
|
|
|
|
if (!same_native (priv->widget, new_target))
|
|
|
|
new_target = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_target == NULL && new_target == NULL)
|
2020-02-16 07:20:34 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-03-01 06:33:51 +00:00
|
|
|
/*< private >
|
2013-01-17 19:55:24 +00:00
|
|
|
* gtk_event_controller_handle_event:
|
2021-03-01 06:33:51 +00:00
|
|
|
* @controller: a `GtkEventController`
|
|
|
|
* @event: a `GdkEvent`
|
2020-02-16 07:20:34 +00:00
|
|
|
* @target: the target widget
|
2020-02-13 05:08:49 +00:00
|
|
|
* @x: event position in widget coordinates, or 0 if not a pointer event
|
|
|
|
* @y: event position in widget coordinates, or 0 if not a pointer event
|
2013-01-17 19:55:24 +00:00
|
|
|
*
|
2019-06-24 18:42:40 +00:00
|
|
|
* Feeds an event into @controller, so it can be interpreted
|
2013-01-17 19:55:24 +00:00
|
|
|
* and the controller actions triggered.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the event was potentially useful to trigger the
|
2021-03-01 06:33:51 +00:00
|
|
|
* controller action
|
|
|
|
*/
|
2013-01-17 19:55:24 +00:00
|
|
|
gboolean
|
|
|
|
gtk_event_controller_handle_event (GtkEventController *controller,
|
2020-02-16 16:09:02 +00:00
|
|
|
GdkEvent *event,
|
2020-02-16 07:20:34 +00:00
|
|
|
GtkWidget *target,
|
2020-02-13 05:08:49 +00:00
|
|
|
double x,
|
|
|
|
double y)
|
2013-01-17 19:55:24 +00:00
|
|
|
{
|
2014-05-27 10:41:30 +00:00
|
|
|
GtkEventControllerClass *controller_class;
|
2020-02-16 07:46:05 +00:00
|
|
|
GtkEventControllerPrivate *priv;
|
2013-01-17 19:55:24 +00:00
|
|
|
gboolean retval = FALSE;
|
|
|
|
|
2020-02-16 07:46:05 +00:00
|
|
|
priv = gtk_event_controller_get_instance_private (controller);
|
|
|
|
|
2013-01-17 19:55:24 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER (controller), FALSE);
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
|
|
|
|
2020-02-16 07:20:34 +00:00
|
|
|
if (gtk_event_controller_filter_event (controller, event, target))
|
2015-07-09 16:55:32 +00:00
|
|
|
return retval;
|
|
|
|
|
2020-02-16 07:20:34 +00:00
|
|
|
controller_class = GTK_EVENT_CONTROLLER_GET_CLASS (controller);
|
|
|
|
|
2020-04-11 16:40:21 +00:00
|
|
|
priv->target = g_object_ref (target);
|
|
|
|
priv->event = gdk_event_ref (event);
|
2020-02-16 07:46:05 +00:00
|
|
|
|
2020-02-16 07:20:34 +00:00
|
|
|
g_object_ref (controller);
|
|
|
|
retval = controller_class->handle_event (controller, event, x, y);
|
|
|
|
g_object_unref (controller);
|
2013-01-17 19:55:24 +00:00
|
|
|
|
2020-04-11 16:40:21 +00:00
|
|
|
g_clear_object (&priv->target);
|
|
|
|
g_clear_pointer (&priv->event, gdk_event_unref);
|
2020-02-16 07:46:05 +00:00
|
|
|
|
2013-01-17 19:55:24 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2020-12-15 15:55:15 +00:00
|
|
|
/*< private >
|
2020-02-13 01:26:29 +00:00
|
|
|
* gtk_event_controller_handle_crossing:
|
2021-05-20 13:17:04 +00:00
|
|
|
* @controller: a `GtkEventController`
|
|
|
|
* @crossing: a `GtkCrossingData`
|
2020-02-16 01:47:23 +00:00
|
|
|
* @x: translated event coordinates
|
|
|
|
* @y: translated event coordinates
|
2020-02-13 01:26:29 +00:00
|
|
|
*
|
|
|
|
* Feeds a crossing event into @controller, so it can be interpreted
|
|
|
|
* and the controller actions triggered.
|
2020-12-15 15:55:15 +00:00
|
|
|
*/
|
2020-02-13 01:26:29 +00:00
|
|
|
void
|
|
|
|
gtk_event_controller_handle_crossing (GtkEventController *controller,
|
|
|
|
const GtkCrossingData *crossing,
|
|
|
|
double x,
|
|
|
|
double y)
|
|
|
|
{
|
|
|
|
GtkEventControllerClass *controller_class;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_EVENT_CONTROLLER (controller));
|
|
|
|
g_return_if_fail (crossing != NULL);
|
|
|
|
|
2020-02-16 07:20:34 +00:00
|
|
|
if (gtk_event_controller_filter_crossing (controller, crossing))
|
2020-02-16 06:48:50 +00:00
|
|
|
return;
|
|
|
|
|
2020-02-16 07:20:34 +00:00
|
|
|
controller_class = GTK_EVENT_CONTROLLER_GET_CLASS (controller);
|
|
|
|
|
2020-02-13 01:26:29 +00:00
|
|
|
g_object_ref (controller);
|
|
|
|
controller_class->handle_crossing (controller, crossing, x, y);
|
|
|
|
g_object_unref (controller);
|
|
|
|
}
|
|
|
|
|
2013-01-17 19:55:24 +00:00
|
|
|
/**
|
2021-03-01 06:33:51 +00:00
|
|
|
* gtk_event_controller_get_widget: (attributes org.gtk.Method.get_property=widget)
|
|
|
|
* @controller: a `GtkEventController`
|
2013-01-17 19:55:24 +00:00
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* Returns the `GtkWidget` this controller relates to.
|
2013-01-17 19:55:24 +00:00
|
|
|
*
|
2021-03-01 06:33:51 +00:00
|
|
|
* Returns: (transfer none): a `GtkWidget`
|
2013-01-17 19:55:24 +00:00
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_event_controller_get_widget (GtkEventController *controller)
|
|
|
|
{
|
|
|
|
GtkEventControllerPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER (controller), 0);
|
|
|
|
|
|
|
|
priv = gtk_event_controller_get_instance_private (controller);
|
|
|
|
|
|
|
|
return priv->widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_event_controller_reset:
|
2021-03-01 06:33:51 +00:00
|
|
|
* @controller: a `GtkEventController`
|
2013-01-17 19:55:24 +00:00
|
|
|
*
|
2021-03-01 06:33:51 +00:00
|
|
|
* Resets the @controller to a clean state.
|
|
|
|
*/
|
2013-01-17 19:55:24 +00:00
|
|
|
void
|
|
|
|
gtk_event_controller_reset (GtkEventController *controller)
|
|
|
|
{
|
2014-05-27 10:41:30 +00:00
|
|
|
GtkEventControllerClass *controller_class;
|
|
|
|
|
2013-01-17 19:55:24 +00:00
|
|
|
g_return_if_fail (GTK_IS_EVENT_CONTROLLER (controller));
|
|
|
|
|
2014-05-27 10:41:30 +00:00
|
|
|
controller_class = GTK_EVENT_CONTROLLER_GET_CLASS (controller);
|
|
|
|
|
|
|
|
if (controller_class->reset)
|
|
|
|
controller_class->reset (controller);
|
2013-01-17 19:55:24 +00:00
|
|
|
}
|
2014-05-26 12:02:30 +00:00
|
|
|
|
|
|
|
/**
|
2021-03-01 06:33:51 +00:00
|
|
|
* gtk_event_controller_get_propagation_phase: (attributes org.gtk.Method.get_property=propagation-phase)
|
|
|
|
* @controller: a `GtkEventController`
|
2014-05-26 12:02:30 +00:00
|
|
|
*
|
|
|
|
* Gets the propagation phase at which @controller handles events.
|
|
|
|
*
|
|
|
|
* Returns: the propagation phase
|
2021-03-01 06:33:51 +00:00
|
|
|
*/
|
2014-05-26 12:02:30 +00:00
|
|
|
GtkPropagationPhase
|
|
|
|
gtk_event_controller_get_propagation_phase (GtkEventController *controller)
|
|
|
|
{
|
|
|
|
GtkEventControllerPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER (controller), GTK_PHASE_NONE);
|
|
|
|
|
|
|
|
priv = gtk_event_controller_get_instance_private (controller);
|
|
|
|
|
|
|
|
return priv->phase;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-01 06:33:51 +00:00
|
|
|
* gtk_event_controller_set_propagation_phase: (attributes org.gtk.Method.set_property=propagation-phase)
|
|
|
|
* @controller: a `GtkEventController`
|
2014-05-26 12:02:30 +00:00
|
|
|
* @phase: a propagation phase
|
|
|
|
*
|
|
|
|
* Sets the propagation phase at which a controller handles events.
|
|
|
|
*
|
|
|
|
* If @phase is %GTK_PHASE_NONE, no automatic event handling will be
|
2021-03-01 06:33:51 +00:00
|
|
|
* performed, but other additional gesture maintenance will.
|
|
|
|
*/
|
2014-05-26 12:02:30 +00:00
|
|
|
void
|
|
|
|
gtk_event_controller_set_propagation_phase (GtkEventController *controller,
|
|
|
|
GtkPropagationPhase phase)
|
|
|
|
{
|
|
|
|
GtkEventControllerPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_EVENT_CONTROLLER (controller));
|
|
|
|
g_return_if_fail (phase >= GTK_PHASE_NONE && phase <= GTK_PHASE_TARGET);
|
|
|
|
|
|
|
|
priv = gtk_event_controller_get_instance_private (controller);
|
|
|
|
|
|
|
|
if (priv->phase == phase)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->phase = phase;
|
|
|
|
|
|
|
|
if (phase == GTK_PHASE_NONE)
|
|
|
|
gtk_event_controller_reset (controller);
|
|
|
|
|
2015-09-06 14:46:15 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (controller), properties[PROP_PROPAGATION_PHASE]);
|
2014-05-26 12:02:30 +00:00
|
|
|
}
|
2019-04-29 02:19:44 +00:00
|
|
|
|
2020-04-20 02:50:35 +00:00
|
|
|
/**
|
2021-03-01 06:33:51 +00:00
|
|
|
* gtk_event_controller_get_propagation_limit: (attributes org.gtk.Method.get_property=propagation-limit)
|
|
|
|
* @controller: a `GtkEventController`
|
2020-04-20 02:50:35 +00:00
|
|
|
*
|
|
|
|
* Gets the propagation limit of the event controller.
|
|
|
|
*
|
|
|
|
* Returns: the propagation limit
|
|
|
|
*/
|
2019-04-29 02:19:44 +00:00
|
|
|
GtkPropagationLimit
|
|
|
|
gtk_event_controller_get_propagation_limit (GtkEventController *controller)
|
|
|
|
{
|
|
|
|
GtkEventControllerPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER (controller), GTK_LIMIT_SAME_NATIVE);
|
|
|
|
|
|
|
|
priv = gtk_event_controller_get_instance_private (controller);
|
|
|
|
|
|
|
|
return priv->limit;
|
|
|
|
}
|
2020-04-20 02:50:35 +00:00
|
|
|
|
|
|
|
/**
|
2021-03-01 06:33:51 +00:00
|
|
|
* gtk_event_controller_set_propagation_limit: (attributes org.gtk.Method.set_property=propagation-limit)
|
|
|
|
* @controller: a `GtkEventController`
|
2020-04-20 02:50:35 +00:00
|
|
|
* @limit: the propagation limit
|
|
|
|
*
|
|
|
|
* Sets the event propagation limit on the event controller.
|
|
|
|
*
|
2020-11-07 17:46:26 +00:00
|
|
|
* If the limit is set to %GTK_LIMIT_SAME_NATIVE, the controller
|
2020-04-20 02:50:35 +00:00
|
|
|
* won't handle events that are targeted at widgets on a different
|
|
|
|
* surface, such as popovers.
|
|
|
|
*/
|
2019-04-29 02:19:44 +00:00
|
|
|
void
|
|
|
|
gtk_event_controller_set_propagation_limit (GtkEventController *controller,
|
|
|
|
GtkPropagationLimit limit)
|
|
|
|
{
|
|
|
|
GtkEventControllerPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_EVENT_CONTROLLER (controller));
|
|
|
|
|
|
|
|
priv = gtk_event_controller_get_instance_private (controller);
|
|
|
|
|
|
|
|
if (priv->limit == limit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->limit = limit;
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (controller), properties[PROP_PROPAGATION_LIMIT]);
|
|
|
|
}
|
2019-06-19 11:09:38 +00:00
|
|
|
|
2020-04-20 02:50:35 +00:00
|
|
|
/**
|
2021-03-01 06:33:51 +00:00
|
|
|
* gtk_event_controller_get_name: (attributes org.gtk.Method.get_property=name)
|
|
|
|
* @controller: a `GtkEventController`
|
2020-04-20 02:50:35 +00:00
|
|
|
*
|
|
|
|
* Gets the name of @controller.
|
|
|
|
*/
|
2019-06-19 11:09:38 +00:00
|
|
|
const char *
|
|
|
|
gtk_event_controller_get_name (GtkEventController *controller)
|
|
|
|
{
|
|
|
|
GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (controller);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER (controller), NULL);
|
|
|
|
|
|
|
|
return priv->name;
|
|
|
|
}
|
|
|
|
|
2020-04-20 02:50:35 +00:00
|
|
|
/**
|
2021-03-01 06:33:51 +00:00
|
|
|
* gtk_event_controller_set_name: (attributes org.gtk.Method.set_property=name)
|
|
|
|
* @controller: a `GtkEventController`
|
2020-04-20 02:50:35 +00:00
|
|
|
* @name: a name for @controller
|
|
|
|
*
|
2021-03-01 06:33:51 +00:00
|
|
|
* Sets a name on the controller that can be used for debugging.
|
2020-04-20 02:50:35 +00:00
|
|
|
*/
|
2019-06-19 11:09:38 +00:00
|
|
|
void
|
|
|
|
gtk_event_controller_set_name (GtkEventController *controller,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (controller);
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_EVENT_CONTROLLER (controller));
|
|
|
|
|
|
|
|
g_free (priv->name);
|
2019-12-25 00:39:10 +00:00
|
|
|
priv->name = g_strdup (name);
|
2019-06-19 11:09:38 +00:00
|
|
|
}
|
2020-02-13 01:26:29 +00:00
|
|
|
|
2020-02-16 07:46:05 +00:00
|
|
|
GtkWidget *
|
|
|
|
gtk_event_controller_get_target (GtkEventController *controller)
|
|
|
|
{
|
|
|
|
GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (controller);
|
|
|
|
|
|
|
|
return priv->target;
|
|
|
|
}
|
|
|
|
|
2020-04-11 16:40:21 +00:00
|
|
|
/**
|
|
|
|
* gtk_event_controller_get_current_event:
|
2021-03-01 06:33:51 +00:00
|
|
|
* @controller: a `GtkEventController`
|
2020-04-11 16:40:21 +00:00
|
|
|
*
|
2021-05-22 18:27:25 +00:00
|
|
|
* Returns the event that is currently being handled by the controller.
|
|
|
|
*
|
|
|
|
* At other times, %NULL is returned.
|
2020-04-11 16:40:21 +00:00
|
|
|
*
|
2021-03-01 06:33:51 +00:00
|
|
|
* Returns: (nullable) (transfer none): the event that is currently
|
|
|
|
* handled by @controller
|
2020-04-11 16:40:21 +00:00
|
|
|
*/
|
|
|
|
GdkEvent *
|
|
|
|
gtk_event_controller_get_current_event (GtkEventController *controller)
|
|
|
|
{
|
|
|
|
GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (controller);
|
|
|
|
|
|
|
|
return priv->event;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_event_controller_get_current_event_time:
|
2021-03-01 06:33:51 +00:00
|
|
|
* @controller: a `GtkEventController`
|
2020-04-11 16:40:21 +00:00
|
|
|
*
|
|
|
|
* Returns the timestamp of the event that is currently being
|
2021-05-22 18:27:25 +00:00
|
|
|
* handled by the controller.
|
|
|
|
*
|
|
|
|
* At other times, 0 is returned.
|
2020-04-11 16:40:21 +00:00
|
|
|
*
|
2021-03-01 06:33:51 +00:00
|
|
|
* Returns: timestamp of the event is currently handled by @controller
|
2020-04-11 16:40:21 +00:00
|
|
|
*/
|
|
|
|
guint32
|
|
|
|
gtk_event_controller_get_current_event_time (GtkEventController *controller)
|
|
|
|
{
|
|
|
|
GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (controller);
|
|
|
|
|
|
|
|
if (priv->event)
|
|
|
|
return gdk_event_get_time (priv->event);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_event_controller_get_current_event_device:
|
2021-03-01 06:33:51 +00:00
|
|
|
* @controller: a `GtkEventController`
|
2020-04-11 16:40:21 +00:00
|
|
|
*
|
|
|
|
* Returns the device of the event that is currently being
|
2021-05-22 18:27:25 +00:00
|
|
|
* handled by the controller.
|
|
|
|
*
|
|
|
|
* At other times, %NULL is returned.
|
2020-04-11 16:40:21 +00:00
|
|
|
*
|
2021-03-01 06:33:51 +00:00
|
|
|
* Returns: (nullable) (transfer none): device of the event is
|
|
|
|
* currently handled by @controller
|
2020-04-11 16:40:21 +00:00
|
|
|
*/
|
|
|
|
GdkDevice *
|
|
|
|
gtk_event_controller_get_current_event_device (GtkEventController *controller)
|
|
|
|
{
|
|
|
|
GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (controller);
|
|
|
|
|
|
|
|
if (priv->event)
|
|
|
|
return gdk_event_get_device (priv->event);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-04-16 18:07:02 +00:00
|
|
|
* gtk_event_controller_get_current_event_state:
|
2021-03-01 06:33:51 +00:00
|
|
|
* @controller: a `GtkEventController`
|
2020-04-11 16:40:21 +00:00
|
|
|
*
|
|
|
|
* Returns the modifier state of the event that is currently being
|
2021-05-22 18:27:25 +00:00
|
|
|
* handled by the controller.
|
|
|
|
*
|
|
|
|
* At other times, 0 is returned.
|
2020-04-11 16:40:21 +00:00
|
|
|
*
|
2021-03-01 06:33:51 +00:00
|
|
|
* Returns: modifier state of the event is currently handled by @controller
|
2020-04-11 16:40:21 +00:00
|
|
|
*/
|
|
|
|
GdkModifierType
|
|
|
|
gtk_event_controller_get_current_event_state (GtkEventController *controller)
|
|
|
|
{
|
|
|
|
GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (controller);
|
|
|
|
|
|
|
|
if (priv->event)
|
|
|
|
return gdk_event_get_modifier_state (priv->event);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|