2017-12-11 23:29:33 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2017, 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): Matthias Clasen <mclasen@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-03-01 06:36:51 +00:00
|
|
|
* GtkEventControllerMotion:
|
2017-12-11 23:29:33 +00:00
|
|
|
*
|
2021-03-01 06:36:51 +00:00
|
|
|
* `GtkEventControllerMotion` is an event controller tracking the pointer
|
|
|
|
* position.
|
|
|
|
*
|
|
|
|
* The event controller offers [signal@Gtk.EventControllerMotion::enter]
|
|
|
|
* and [signal@Gtk.EventControllerMotion::leave] signals, as well as
|
|
|
|
* [property@Gtk.EventControllerMotion:is-pointer] and
|
|
|
|
* [property@Gtk.EventControllerMotion:contains-pointer] properties
|
|
|
|
* which are updated to reflect changes in the pointer position as it
|
|
|
|
* moves over the widget.
|
|
|
|
*/
|
2017-12-11 23:29:33 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkintl.h"
|
2019-03-17 03:44:55 +00:00
|
|
|
#include "gtkprivate.h"
|
|
|
|
#include "gtkwidgetprivate.h"
|
2019-06-02 21:07:27 +00:00
|
|
|
#include "gtkmarshalers.h"
|
2017-12-11 23:29:33 +00:00
|
|
|
#include "gtkeventcontrollerprivate.h"
|
|
|
|
#include "gtkeventcontrollermotion.h"
|
|
|
|
#include "gtktypebuiltins.h"
|
|
|
|
#include "gtkmarshalers.h"
|
|
|
|
|
|
|
|
struct _GtkEventControllerMotion
|
|
|
|
{
|
|
|
|
GtkEventController parent_instance;
|
2019-03-17 03:29:48 +00:00
|
|
|
|
2019-12-15 19:25:42 +00:00
|
|
|
guint is_pointer : 1;
|
|
|
|
guint contains_pointer : 1;
|
2017-12-11 23:29:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkEventControllerMotionClass
|
|
|
|
{
|
|
|
|
GtkEventControllerClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2020-02-20 03:04:28 +00:00
|
|
|
ENTER,
|
|
|
|
LEAVE,
|
2017-12-11 23:29:33 +00:00
|
|
|
MOTION,
|
|
|
|
N_SIGNALS
|
|
|
|
};
|
|
|
|
|
2019-03-17 03:29:48 +00:00
|
|
|
enum {
|
2019-12-15 19:25:42 +00:00
|
|
|
PROP_IS_POINTER = 1,
|
|
|
|
PROP_CONTAINS_POINTER,
|
2019-03-17 03:29:48 +00:00
|
|
|
NUM_PROPERTIES
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *props[NUM_PROPERTIES] = { NULL, };
|
|
|
|
|
2017-12-11 23:29:33 +00:00
|
|
|
static guint signals[N_SIGNALS] = { 0 };
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkEventControllerMotion, gtk_event_controller_motion, GTK_TYPE_EVENT_CONTROLLER)
|
|
|
|
|
2020-02-16 01:47:23 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_event_controller_motion_handle_event (GtkEventController *controller,
|
2020-02-16 16:09:02 +00:00
|
|
|
GdkEvent *event,
|
2020-02-16 01:47:23 +00:00
|
|
|
double x,
|
|
|
|
double y)
|
|
|
|
{
|
|
|
|
GtkEventControllerClass *parent_class;
|
|
|
|
GdkEventType type;
|
|
|
|
|
|
|
|
type = gdk_event_get_event_type (event);
|
|
|
|
if (type == GDK_MOTION_NOTIFY)
|
|
|
|
g_signal_emit (controller, signals[MOTION], 0, x, y);
|
|
|
|
|
|
|
|
parent_class = GTK_EVENT_CONTROLLER_CLASS (gtk_event_controller_motion_parent_class);
|
|
|
|
|
|
|
|
return parent_class->handle_event (controller, event, x, y);
|
|
|
|
}
|
|
|
|
|
2019-03-17 03:29:48 +00:00
|
|
|
static void
|
2020-02-16 01:47:23 +00:00
|
|
|
update_pointer_focus (GtkEventController *controller,
|
2020-02-20 03:04:28 +00:00
|
|
|
const GtkCrossingData *crossing,
|
|
|
|
double x,
|
|
|
|
double y)
|
2019-03-17 03:29:48 +00:00
|
|
|
{
|
2020-02-16 01:47:23 +00:00
|
|
|
GtkEventControllerMotion *motion = GTK_EVENT_CONTROLLER_MOTION (controller);
|
|
|
|
GtkWidget *widget = gtk_event_controller_get_widget (controller);
|
|
|
|
gboolean is_pointer = FALSE;
|
|
|
|
gboolean contains_pointer = FALSE;
|
2020-02-20 03:04:28 +00:00
|
|
|
gboolean enter = FALSE;
|
|
|
|
gboolean leave = FALSE;
|
2019-03-17 03:29:48 +00:00
|
|
|
|
2020-02-16 01:47:23 +00:00
|
|
|
if (crossing->direction == GTK_CROSSING_IN)
|
2019-03-17 03:29:48 +00:00
|
|
|
{
|
2020-02-21 04:20:58 +00:00
|
|
|
if (crossing->new_descendent != NULL)
|
|
|
|
{
|
|
|
|
contains_pointer = TRUE;
|
|
|
|
}
|
2020-02-16 01:47:23 +00:00
|
|
|
if (crossing->new_target == widget)
|
2020-02-21 04:20:58 +00:00
|
|
|
{
|
|
|
|
contains_pointer = TRUE;
|
|
|
|
is_pointer = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (crossing->new_descendent != NULL ||
|
|
|
|
crossing->new_target == widget)
|
2020-02-16 01:47:23 +00:00
|
|
|
contains_pointer = TRUE;
|
2020-02-21 04:20:58 +00:00
|
|
|
is_pointer = FALSE;
|
2019-03-17 03:29:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-20 03:04:28 +00:00
|
|
|
if (motion->contains_pointer != contains_pointer)
|
|
|
|
{
|
2020-02-21 04:20:58 +00:00
|
|
|
enter = contains_pointer;
|
|
|
|
leave = !contains_pointer;
|
2020-02-20 03:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (leave)
|
2020-05-24 15:47:53 +00:00
|
|
|
g_signal_emit (controller, signals[LEAVE], 0);
|
2020-02-20 03:04:28 +00:00
|
|
|
|
2019-03-17 03:29:48 +00:00
|
|
|
g_object_freeze_notify (G_OBJECT (motion));
|
2019-12-15 19:25:42 +00:00
|
|
|
if (motion->is_pointer != is_pointer)
|
2019-03-17 03:29:48 +00:00
|
|
|
{
|
2019-12-15 19:25:42 +00:00
|
|
|
motion->is_pointer = is_pointer;
|
2020-11-29 08:25:46 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (motion), props[PROP_IS_POINTER]);
|
2019-03-17 03:29:48 +00:00
|
|
|
}
|
2019-12-15 19:25:42 +00:00
|
|
|
if (motion->contains_pointer != contains_pointer)
|
2019-03-17 03:29:48 +00:00
|
|
|
{
|
2019-12-15 19:25:42 +00:00
|
|
|
motion->contains_pointer = contains_pointer;
|
2020-11-29 08:25:46 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (motion), props[PROP_CONTAINS_POINTER]);
|
2019-03-17 03:29:48 +00:00
|
|
|
}
|
|
|
|
g_object_thaw_notify (G_OBJECT (motion));
|
2020-02-20 03:04:28 +00:00
|
|
|
|
|
|
|
if (enter)
|
2020-05-24 15:47:53 +00:00
|
|
|
g_signal_emit (controller, signals[ENTER], 0, x, y);
|
2019-03-17 03:29:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 01:47:23 +00:00
|
|
|
static void
|
|
|
|
gtk_event_controller_motion_handle_crossing (GtkEventController *controller,
|
|
|
|
const GtkCrossingData *crossing,
|
|
|
|
double x,
|
|
|
|
double y)
|
2017-12-11 23:29:33 +00:00
|
|
|
{
|
2020-02-21 04:20:58 +00:00
|
|
|
if (crossing->type == GTK_CROSSING_POINTER)
|
|
|
|
update_pointer_focus (controller, crossing, x, y);
|
2017-12-11 23:29:33 +00:00
|
|
|
}
|
|
|
|
|
2019-03-17 03:29:48 +00:00
|
|
|
static void
|
|
|
|
gtk_event_controller_motion_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkEventControllerMotion *controller = GTK_EVENT_CONTROLLER_MOTION (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2019-12-15 19:25:42 +00:00
|
|
|
case PROP_IS_POINTER:
|
|
|
|
g_value_set_boolean (value, controller->is_pointer);
|
2019-03-17 03:29:48 +00:00
|
|
|
break;
|
|
|
|
|
2019-12-15 19:25:42 +00:00
|
|
|
case PROP_CONTAINS_POINTER:
|
|
|
|
g_value_set_boolean (value, controller->contains_pointer);
|
2019-03-17 03:29:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-11 23:29:33 +00:00
|
|
|
static void
|
|
|
|
gtk_event_controller_motion_class_init (GtkEventControllerMotionClass *klass)
|
|
|
|
{
|
2019-03-17 03:29:48 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2017-12-11 23:29:33 +00:00
|
|
|
GtkEventControllerClass *controller_class = GTK_EVENT_CONTROLLER_CLASS (klass);
|
|
|
|
|
2019-03-17 03:29:48 +00:00
|
|
|
object_class->get_property = gtk_event_controller_motion_get_property;
|
|
|
|
|
2017-12-11 23:29:33 +00:00
|
|
|
controller_class->handle_event = gtk_event_controller_motion_handle_event;
|
2020-02-16 01:47:23 +00:00
|
|
|
controller_class->handle_crossing = gtk_event_controller_motion_handle_crossing;
|
2017-12-11 23:29:33 +00:00
|
|
|
|
2019-03-17 03:29:48 +00:00
|
|
|
/**
|
2021-03-01 06:36:51 +00:00
|
|
|
* GtkEventControllerMotion:is-pointer: (attributes org.gtk.Property.get=gtk_event_controller_motion_is_pointer)
|
2019-03-17 03:29:48 +00:00
|
|
|
*
|
|
|
|
* Whether the pointer is in the controllers widget itself,
|
2021-03-01 06:36:51 +00:00
|
|
|
* as opposed to in a descendent widget.
|
|
|
|
*
|
|
|
|
* See also [property@Gtk.EventControllerMotion:contains-pointer].
|
2019-03-17 03:29:48 +00:00
|
|
|
*
|
|
|
|
* When handling crossing events, this property is updated
|
2021-03-01 06:36:51 +00:00
|
|
|
* before [signal@Gtk.EventControllerMotion::enter], but after
|
|
|
|
* [signal@Gtk.EventControllerMotion::leave] is emitted.
|
2019-03-17 03:29:48 +00:00
|
|
|
*/
|
2019-12-15 19:25:42 +00:00
|
|
|
props[PROP_IS_POINTER] =
|
|
|
|
g_param_spec_boolean ("is-pointer",
|
|
|
|
P_("Is Pointer"),
|
2019-03-17 03:29:48 +00:00
|
|
|
P_("Whether the pointer is in the controllers widget"),
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READABLE);
|
|
|
|
|
|
|
|
/**
|
2021-03-01 06:36:51 +00:00
|
|
|
* GtkEventControllerMotion:contains-pointer: (attributes org.gtk.Property.get=gtk_event_controller_motion_contains_pointer)
|
2019-03-17 03:29:48 +00:00
|
|
|
*
|
2019-12-15 19:25:42 +00:00
|
|
|
* Whether the pointer is in the controllers widget or a descendant.
|
2021-03-01 06:36:51 +00:00
|
|
|
*
|
|
|
|
* See also [property@Gtk.EventControllerMotion:is-pointer].
|
2019-03-17 03:29:48 +00:00
|
|
|
*
|
|
|
|
* When handling crossing events, this property is updated
|
2021-03-01 06:36:51 +00:00
|
|
|
* before [signal@Gtk.EventControllerMotion::enter], but after
|
|
|
|
* [signal@Gtk.EventControllerMotion::leave] is emitted.
|
2019-03-17 03:29:48 +00:00
|
|
|
*/
|
2019-12-15 19:25:42 +00:00
|
|
|
props[PROP_CONTAINS_POINTER] =
|
|
|
|
g_param_spec_boolean ("contains-pointer",
|
|
|
|
P_("Contains Pointer"),
|
2020-07-04 08:00:25 +00:00
|
|
|
P_("Whether the pointer is in the controllers widget or a descendant"),
|
2019-03-17 03:29:48 +00:00
|
|
|
FALSE,
|
|
|
|
G_PARAM_READABLE);
|
|
|
|
|
2019-03-18 12:44:02 +00:00
|
|
|
g_object_class_install_properties (object_class, NUM_PROPERTIES, props);
|
|
|
|
|
2017-12-11 23:29:33 +00:00
|
|
|
/**
|
2020-02-20 03:04:28 +00:00
|
|
|
* GtkEventControllerMotion::enter:
|
2020-02-16 01:47:23 +00:00
|
|
|
* @controller: the object which received the signal
|
|
|
|
* @x: coordinates of pointer location
|
|
|
|
* @y: coordinates of pointer location
|
|
|
|
*
|
2020-02-20 03:04:28 +00:00
|
|
|
* Signals that the pointer has entered the widget.
|
2017-12-11 23:29:33 +00:00
|
|
|
*/
|
2020-02-20 03:04:28 +00:00
|
|
|
signals[ENTER] =
|
|
|
|
g_signal_new (I_("enter"),
|
2017-12-11 23:29:33 +00:00
|
|
|
GTK_TYPE_EVENT_CONTROLLER_MOTION,
|
2020-02-16 01:47:23 +00:00
|
|
|
G_SIGNAL_RUN_LAST,
|
2017-12-11 23:29:33 +00:00
|
|
|
0, NULL, NULL,
|
2020-02-16 01:47:23 +00:00
|
|
|
NULL,
|
2020-05-24 15:47:53 +00:00
|
|
|
G_TYPE_NONE, 2,
|
2019-03-06 19:56:46 +00:00
|
|
|
G_TYPE_DOUBLE,
|
2020-05-24 15:47:53 +00:00
|
|
|
G_TYPE_DOUBLE);
|
2017-12-11 23:29:33 +00:00
|
|
|
|
2020-02-20 03:04:28 +00:00
|
|
|
/**
|
|
|
|
* GtkEventControllerMotion::leave:
|
|
|
|
* @controller: the object which received the signal
|
|
|
|
*
|
|
|
|
* Signals that the pointer has left the widget.
|
|
|
|
*/
|
|
|
|
signals[LEAVE] =
|
|
|
|
g_signal_new (I_("leave"),
|
|
|
|
GTK_TYPE_EVENT_CONTROLLER_MOTION,
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0, NULL, NULL,
|
|
|
|
NULL,
|
2020-05-24 15:47:53 +00:00
|
|
|
G_TYPE_NONE, 0);
|
2020-02-20 03:04:28 +00:00
|
|
|
|
2017-12-11 23:29:33 +00:00
|
|
|
/**
|
|
|
|
* GtkEventControllerMotion::motion:
|
|
|
|
* @controller: The object that received the signal
|
|
|
|
* @x: the x coordinate
|
|
|
|
* @y: the y coordinate
|
|
|
|
*
|
|
|
|
* Emitted when the pointer moves inside the widget.
|
|
|
|
*/
|
|
|
|
signals[MOTION] =
|
|
|
|
g_signal_new (I_("motion"),
|
|
|
|
GTK_TYPE_EVENT_CONTROLLER_MOTION,
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
0, NULL, NULL,
|
2019-06-02 21:07:27 +00:00
|
|
|
_gtk_marshal_VOID__DOUBLE_DOUBLE,
|
2017-12-11 23:29:33 +00:00
|
|
|
G_TYPE_NONE, 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
|
2019-06-02 21:07:27 +00:00
|
|
|
g_signal_set_va_marshaller (signals[MOTION],
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
_gtk_marshal_VOID__DOUBLE_DOUBLEv);
|
2017-12-11 23:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_event_controller_motion_init (GtkEventControllerMotion *motion)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_event_controller_motion_new:
|
|
|
|
*
|
2018-03-10 17:45:23 +00:00
|
|
|
* Creates a new event controller that will handle motion events.
|
2017-12-11 23:29:33 +00:00
|
|
|
*
|
2021-03-01 06:36:51 +00:00
|
|
|
* Returns: a new `GtkEventControllerMotion`
|
2017-12-11 23:29:33 +00:00
|
|
|
**/
|
|
|
|
GtkEventController *
|
2018-03-10 17:45:23 +00:00
|
|
|
gtk_event_controller_motion_new (void)
|
2017-12-11 23:29:33 +00:00
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_EVENT_CONTROLLER_MOTION,
|
|
|
|
NULL);
|
|
|
|
}
|
2019-03-17 03:44:55 +00:00
|
|
|
|
2019-12-15 19:25:42 +00:00
|
|
|
/**
|
2021-03-01 06:36:51 +00:00
|
|
|
* gtk_event_controller_motion_contains_pointer: (attributes org.gtk.Method.get_property=contains-pointer)
|
|
|
|
* @self: a `GtkEventControllerMotion`
|
2019-12-15 19:25:42 +00:00
|
|
|
*
|
2021-03-01 06:36:51 +00:00
|
|
|
* Returns if a pointer is within @self or one of its children.
|
2019-12-15 19:25:42 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if a pointer is within @self or one of its children
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_event_controller_motion_contains_pointer (GtkEventControllerMotion *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_MOTION (self), FALSE);
|
|
|
|
|
|
|
|
return self->contains_pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-01 06:36:51 +00:00
|
|
|
* gtk_event_controller_motion_is_pointer: (attributes org.gtk.Method.get_property=is-pointer)
|
|
|
|
* @self: a `GtkEventControllerMotion`
|
2019-12-15 19:25:42 +00:00
|
|
|
*
|
2021-03-01 06:36:51 +00:00
|
|
|
* Returns if a pointer is within @self, but not one of its children.
|
2019-12-15 19:25:42 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if a pointer is within @self but not one of its children
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_event_controller_motion_is_pointer (GtkEventControllerMotion *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_MOTION (self), FALSE);
|
|
|
|
|
|
|
|
return self->is_pointer;
|
|
|
|
}
|