2017-05-26 16:55:30 +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): Carlos Garnacho <carlosg@gnome.org>
|
|
|
|
*/
|
|
|
|
|
2019-02-24 20:29:08 +00:00
|
|
|
/**
|
2021-03-01 06:36:34 +00:00
|
|
|
* GtkEventControllerLegacy:
|
2019-02-24 20:29:08 +00:00
|
|
|
*
|
2021-03-01 06:36:34 +00:00
|
|
|
* `GtkEventControllerLegacy` is an event controller that provides raw
|
|
|
|
* access to the event stream.
|
|
|
|
*
|
|
|
|
* It should only be used as a last resort if none of the other event
|
|
|
|
* controllers or gestures do the job.
|
|
|
|
*/
|
2019-02-24 20:29:08 +00:00
|
|
|
|
2017-05-26 16:55:30 +00:00
|
|
|
#include "config.h"
|
2019-02-24 20:29:08 +00:00
|
|
|
|
2018-10-12 15:30:59 +00:00
|
|
|
#include "gtkeventcontrollerlegacy.h"
|
|
|
|
#include "gtkeventcontrollerprivate.h"
|
|
|
|
#include "gtkmarshalers.h"
|
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtkprivate.h"
|
|
|
|
|
|
|
|
struct _GtkEventControllerLegacy
|
|
|
|
{
|
|
|
|
GtkEventController parent_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkEventControllerLegacyClass
|
|
|
|
{
|
|
|
|
GtkEventControllerClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
EVENT,
|
|
|
|
N_SIGNALS
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[N_SIGNALS] = { 0, };
|
2017-05-26 16:55:30 +00:00
|
|
|
|
2018-03-08 22:24:30 +00:00
|
|
|
G_DEFINE_TYPE (GtkEventControllerLegacy, gtk_event_controller_legacy,
|
2017-05-26 16:55:30 +00:00
|
|
|
GTK_TYPE_EVENT_CONTROLLER)
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_event_controller_legacy_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)
|
2017-05-26 16:55:30 +00:00
|
|
|
{
|
2018-10-12 15:30:59 +00:00
|
|
|
gboolean handled;
|
2017-05-26 16:55:30 +00:00
|
|
|
|
2018-10-12 15:30:59 +00:00
|
|
|
g_signal_emit (controller, signals[EVENT], 0, event, &handled);
|
|
|
|
|
|
|
|
return handled;
|
2017-05-26 16:55:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-03-08 22:24:30 +00:00
|
|
|
gtk_event_controller_legacy_class_init (GtkEventControllerLegacyClass *klass)
|
2017-05-26 16:55:30 +00:00
|
|
|
{
|
|
|
|
GtkEventControllerClass *controller_class = GTK_EVENT_CONTROLLER_CLASS (klass);
|
|
|
|
|
|
|
|
controller_class->handle_event = gtk_event_controller_legacy_handle_event;
|
2018-10-12 15:30:59 +00:00
|
|
|
|
|
|
|
/**
|
2018-11-08 04:19:30 +00:00
|
|
|
* GtkEventControllerLegacy::event:
|
2021-03-01 06:36:34 +00:00
|
|
|
* @controller: the object which received the signal
|
|
|
|
* @event: the `GdkEvent` which triggered this signal
|
2018-10-12 15:30:59 +00:00
|
|
|
*
|
2019-02-24 20:29:08 +00:00
|
|
|
* Emitted for each GDK event delivered to @controller.
|
2018-10-12 15:30:59 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE to stop other handlers from being invoked for the event
|
2021-03-01 06:36:34 +00:00
|
|
|
* and the emission of this signal. %FALSE to propagate the event further.
|
2018-10-12 15:30:59 +00:00
|
|
|
*/
|
|
|
|
signals[EVENT] =
|
|
|
|
g_signal_new (I_("event"),
|
2018-11-08 04:19:30 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0, _gtk_boolean_handled_accumulator, NULL,
|
Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.
The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.
The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 16:23:36 +00:00
|
|
|
_gtk_marshal_BOOLEAN__POINTER,
|
2018-11-08 04:19:30 +00:00
|
|
|
G_TYPE_BOOLEAN, 1,
|
|
|
|
GDK_TYPE_EVENT);
|
|
|
|
|
2018-10-12 15:30:59 +00:00
|
|
|
g_signal_set_va_marshaller (signals[EVENT], G_TYPE_FROM_CLASS (klass),
|
Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.
The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.
The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 16:23:36 +00:00
|
|
|
_gtk_marshal_BOOLEAN__POINTERv);
|
2017-05-26 16:55:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-03-08 22:24:30 +00:00
|
|
|
gtk_event_controller_legacy_init (GtkEventControllerLegacy *controller)
|
2017-05-26 16:55:30 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-02-24 20:29:08 +00:00
|
|
|
/**
|
|
|
|
* gtk_event_controller_legacy_new:
|
|
|
|
*
|
|
|
|
* Creates a new legacy event controller.
|
|
|
|
*
|
|
|
|
* Returns: the newly created event controller.
|
|
|
|
*/
|
2017-05-26 16:55:30 +00:00
|
|
|
GtkEventController *
|
2018-03-08 22:24:30 +00:00
|
|
|
gtk_event_controller_legacy_new (void)
|
2017-05-26 16:55:30 +00:00
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_EVENT_CONTROLLER_LEGACY,
|
|
|
|
NULL);
|
|
|
|
}
|