summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2017-12-11 18:29:33 -0500
committerCarlos Garnacho <carlosg@gnome.org>2018-07-16 15:43:43 +0200
commit8b2c3a8c1a8330e64f5908557900fdd976162e5a (patch)
tree92faa4eef1014da11d721f13356a4fdf86482b4c
parente7af3410cfc80375e2aafdb26c6291779473323d (diff)
downloadgtk+-8b2c3a8c1a8330e64f5908557900fdd976162e5a.tar.gz
Add a simple motion eventcontroller
This can serve as a replacement for the legacy event signals for enter/leave/motion notify.
-rw-r--r--gtk/Makefile.am2
-rw-r--r--gtk/gtk.h1
-rw-r--r--gtk/gtkeventcontrollermotion.c160
-rw-r--r--gtk/gtkeventcontrollermotion.h50
4 files changed, 213 insertions, 0 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 37336d540f..ec81f395d7 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -192,6 +192,7 @@ gtk_public_h_sources = \
gtkenums.h \
gtkeventbox.h \
gtkeventcontroller.h \
+ gtkeventcontrollermotion.h \
gtkeventcontrollerscroll.h \
gtkexpander.h \
gtkfilechooser.h \
@@ -758,6 +759,7 @@ gtk_base_c_sources = \
gtkentrycompletion.c \
gtkeventbox.c \
gtkeventcontroller.c \
+ gtkeventcontrollermotion.c \
gtkeventcontrollerscroll.c \
gtkexpander.c \
gtkfilechooser.c \
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 1ce5e5b37e..46cfbfc063 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -94,6 +94,7 @@
#include <gtk/gtkenums.h>
#include <gtk/gtkeventbox.h>
#include <gtk/gtkeventcontroller.h>
+#include <gtk/gtkeventcontrollermotion.h>
#include <gtk/gtkeventcontrollerscroll.h>
#include <gtk/gtkexpander.h>
#include <gtk/gtkfixed.h>
diff --git a/gtk/gtkeventcontrollermotion.c b/gtk/gtkeventcontrollermotion.c
new file mode 100644
index 0000000000..6fe5f23615
--- /dev/null
+++ b/gtk/gtkeventcontrollermotion.c
@@ -0,0 +1,160 @@
+/* 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>
+ */
+
+/**
+ * SECTION:gtkeventcontrollermotion
+ * @Short_description: Event controller for motion events
+ * @Title: GtkEventControllerMotion
+ * @See_also: #GtkEventController
+ *
+ * #GtkEventControllerMotion is an event controller meant for situations
+ * where you need to track the position of the pointer.
+ *
+ * This object was added in 3.94.
+ **/
+#include "config.h"
+
+#include "gtkintl.h"
+#include "gtkwidget.h"
+#include "gtkeventcontrollerprivate.h"
+#include "gtkeventcontrollermotion.h"
+#include "gtktypebuiltins.h"
+#include "gtkmarshalers.h"
+
+struct _GtkEventControllerMotion
+{
+ GtkEventController parent_instance;
+};
+
+struct _GtkEventControllerMotionClass
+{
+ GtkEventControllerClass parent_class;
+};
+
+enum {
+ ENTER,
+ LEAVE,
+ MOTION,
+ N_SIGNALS
+};
+
+static guint signals[N_SIGNALS] = { 0 };
+
+G_DEFINE_TYPE (GtkEventControllerMotion, gtk_event_controller_motion, GTK_TYPE_EVENT_CONTROLLER)
+
+static gboolean
+gtk_event_controller_motion_handle_event (GtkEventController *controller,
+ const GdkEvent *event)
+{
+ GtkEventControllerClass *parent_class;
+ GdkEventType type;
+
+ type = gdk_event_get_event_type (event);
+ if (type == GDK_ENTER_NOTIFY)
+ g_signal_emit (controller, signals[ENTER], 0);
+ else if (type == GDK_LEAVE_NOTIFY)
+ g_signal_emit (controller, signals[LEAVE], 0);
+ else if (type == GDK_MOTION_NOTIFY)
+ {
+ double x, y;
+ gdk_event_get_coords (event, &x, &y);
+ 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);
+}
+
+static void
+gtk_event_controller_motion_class_init (GtkEventControllerMotionClass *klass)
+{
+ GtkEventControllerClass *controller_class = GTK_EVENT_CONTROLLER_CLASS (klass);
+
+ controller_class->handle_event = gtk_event_controller_motion_handle_event;
+
+ /**
+ * GtkEventControllerMotion::enter:
+ * @controller: The object that received the signal
+ *
+ * Signals that the pointer has entered the widget.
+ */
+ signals[ENTER] =
+ g_signal_new (I_("enter"),
+ GTK_TYPE_EVENT_CONTROLLER_MOTION,
+ G_SIGNAL_RUN_FIRST,
+ 0, NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 0);
+ /**
+ * GtkEventControllerMotion::leave:
+ * @controller: The object that received the signal
+ *
+ * Signals that pointer has left the widget.
+ */
+ signals[LEAVE] =
+ g_signal_new (I_("leave"),
+ GTK_TYPE_EVENT_CONTROLLER_MOTION,
+ G_SIGNAL_RUN_FIRST,
+ 0, NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 0);
+
+ /**
+ * 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,
+ NULL,
+ G_TYPE_NONE, 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
+}
+
+static void
+gtk_event_controller_motion_init (GtkEventControllerMotion *motion)
+{
+}
+
+/**
+ * gtk_event_controller_motion_new:
+ * @widget: a #GtkWidget
+ *
+ * Creates a new event controller that will handle motion events
+ * for the given @widget.
+ *
+ * Returns: a new #GtkEventControllerMotion
+ *
+ * Since: 3.94
+ **/
+GtkEventController *
+gtk_event_controller_motion_new (GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+ return g_object_new (GTK_TYPE_EVENT_CONTROLLER_MOTION,
+ "widget", widget,
+ NULL);
+}
diff --git a/gtk/gtkeventcontrollermotion.h b/gtk/gtkeventcontrollermotion.h
new file mode 100644
index 0000000000..42b6aac508
--- /dev/null
+++ b/gtk/gtkeventcontrollermotion.h
@@ -0,0 +1,50 @@
+/* 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>
+ */
+
+#ifndef __GTK_EVENT_CONTROLLER_MOTION_H__
+#define __GTK_EVENT_CONTROLLER_MOTION_H__
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gdk/gdk.h>
+#include <gtk/gtkeventcontroller.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_EVENT_CONTROLLER_MOTION (gtk_event_controller_motion_get_type ())
+#define GTK_EVENT_CONTROLLER_MOTION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_EVENT_CONTROLLER_MOTION, GtkEventControllerMotion))
+#define GTK_EVENT_CONTROLLER_MOTION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_EVENT_CONTROLLER_MOTION, GtkEventControllerMotionClass))
+#define GTK_IS_EVENT_CONTROLLER_MOTION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_EVENT_CONTROLLER_MOTION))
+#define GTK_IS_EVENT_CONTROLLER_MOTION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_EVENT_CONTROLLER_MOTION))
+#define GTK_EVENT_CONTROLLER_MOTION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_EVENT_CONTROLLER_MOTION, GtkEventControllerMotionClass))
+
+typedef struct _GtkEventControllerMotion GtkEventControllerMotion;
+typedef struct _GtkEventControllerMotionClass GtkEventControllerMotionClass;
+
+GDK_AVAILABLE_IN_3_24
+GType gtk_event_controller_motion_get_type (void) G_GNUC_CONST;
+
+GDK_AVAILABLE_IN_3_24
+GtkEventController *gtk_event_controller_motion_new (GtkWidget *widget);
+
+G_END_DECLS
+
+#endif /* __GTK_EVENT_CONTROLLER_MOTION_H__ */