[libhandy] swipe-tracker: Register event capture handler implicitly
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy] swipe-tracker: Register event capture handler implicitly
- Date: Thu, 18 Jun 2020 17:46:28 +0000 (UTC)
commit 255c8bf594b5f6a79b5f9a31a54139362ea05dac
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Sun Jun 14 22:10:41 2020 +0500
swipe-tracker: Register event capture handler implicitly
The way we register the event handler is a hack, and the only reason to do
it is because GTK3 doesn't offer other ways to do it unlike GTK4. It's not
something we'd like to ever expose in a public API, so let's encapsulate it
better.
Remove the corresponding section from docs.
Signed-off-by: Alexander Mikhaylenko <alexm gnome org>
debian/libhandy-1-0.symbols | 2 --
src/hdy-carousel.c | 29 +++-------------
src/hdy-carousel.ui | 1 +
src/hdy-deck.c | 17 ----------
src/hdy-leaflet.c | 17 ----------
src/hdy-stackable-box-private.h | 2 --
src/hdy-stackable-box.c | 7 ----
src/hdy-swipe-tracker-private.h | 3 --
src/hdy-swipe-tracker.c | 74 +++++++++++++++--------------------------
9 files changed, 31 insertions(+), 121 deletions(-)
---
diff --git a/debian/libhandy-1-0.symbols b/debian/libhandy-1-0.symbols
index a714af82..22ed620c 100644
--- a/debian/libhandy-1-0.symbols
+++ b/debian/libhandy-1-0.symbols
@@ -271,7 +271,6 @@ libhandy-1.so.0 libhandy-1-0 #MINVER#
hdy_squeezer_transition_type_get_type@LIBHANDY_1_0 0.0.10
hdy_stackable_box_add@LIBHANDY_1_0 0.80.0
hdy_stackable_box_begin_swipe@LIBHANDY_1_0 0.80.0
- hdy_stackable_box_captured_event@LIBHANDY_1_0 0.80.0
hdy_stackable_box_direction_changed@LIBHANDY_1_0 0.80.0
hdy_stackable_box_draw@LIBHANDY_1_0 0.80.0
hdy_stackable_box_end_swipe@LIBHANDY_1_0 0.80.0
@@ -325,7 +324,6 @@ libhandy-1.so.0 libhandy-1-0 #MINVER#
hdy_swipe_group_get_type@LIBHANDY_1_0 0.0.12
hdy_swipe_group_new@LIBHANDY_1_0 0.0.12
hdy_swipe_group_remove_swipeable@LIBHANDY_1_0 0.0.12
- hdy_swipe_tracker_captured_event@LIBHANDY_1_0 0.0.11
hdy_swipe_tracker_confirm_swipe@LIBHANDY_1_0 0.81.0
hdy_swipe_tracker_get_allow_mouse_drag@LIBHANDY_1_0 0.0.12
hdy_swipe_tracker_get_enabled@LIBHANDY_1_0 0.0.11
diff --git a/src/hdy-carousel.c b/src/hdy-carousel.c
index 759e1827..4a72e50f 100644
--- a/src/hdy-carousel.c
+++ b/src/hdy-carousel.c
@@ -622,8 +622,8 @@ scroll_timeout_cb (HdyCarousel *self)
}
static gboolean
-handle_discrete_scroll_event (HdyCarousel *self,
- GdkEvent *event)
+scroll_event_cb (HdyCarousel *self,
+ GdkEvent *event)
{
GdkDevice *source_device;
GdkInputSource input_source;
@@ -712,16 +712,6 @@ handle_discrete_scroll_event (HdyCarousel *self,
return GDK_EVENT_STOP;
}
-static gboolean
-captured_event_cb (HdyCarousel *self,
- GdkEvent *event)
-{
- if (hdy_swipe_tracker_captured_event (self->tracker, event))
- return GDK_EVENT_STOP;
-
- return handle_discrete_scroll_event (self, event);
-}
-
static void
hdy_carousel_destroy (GtkWidget *widget)
{
@@ -798,11 +788,7 @@ hdy_carousel_dispose (GObject *object)
{
HdyCarousel *self = (HdyCarousel *)object;
- if (self->tracker) {
- g_clear_object (&self->tracker);
-
- g_object_set_data (object, "captured-event-handler", NULL);
- }
+ g_clear_object (&self->tracker);
if (self->scroll_timeout_id != 0) {
g_source_remove (self->scroll_timeout_id);
@@ -1151,6 +1137,7 @@ hdy_carousel_class_init (HdyCarouselClass *klass)
gtk_widget_class_bind_template_child (widget_class, HdyCarousel, empty_box);
gtk_widget_class_bind_template_child (widget_class, HdyCarousel, scrolling_box);
gtk_widget_class_bind_template_child (widget_class, HdyCarousel, indicators);
+ gtk_widget_class_bind_template_callback (widget_class, scroll_event_cb);
gtk_widget_class_bind_template_callback (widget_class, draw_indicators_cb);
gtk_widget_class_bind_template_callback (widget_class, notify_n_pages_cb);
gtk_widget_class_bind_template_callback (widget_class, notify_position_cb);
@@ -1175,14 +1162,6 @@ hdy_carousel_init (HdyCarousel *self)
self->tracker = hdy_swipe_tracker_new (HDY_SWIPEABLE (self));
hdy_swipe_tracker_set_allow_mouse_drag (self->tracker, TRUE);
self->can_scroll = TRUE;
-
- /*
- * HACK: GTK3 has no other way to get events on capture phase.
- * This is a reimplementation of _gtk_widget_set_captured_event_handler(),
- * which is private. In GTK4 it can be replaced with GtkEventControllerLegacy
- * with capture propagation phase
- */
- g_object_set_data (G_OBJECT (self), "captured-event-handler", captured_event_cb);
}
/**
diff --git a/src/hdy-carousel.ui b/src/hdy-carousel.ui
index d17f5d55..e0b177a4 100644
--- a/src/hdy-carousel.ui
+++ b/src/hdy-carousel.ui
@@ -4,6 +4,7 @@
<template class="HdyCarousel" parent="GtkEventBox">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
+ <signal name="scroll-event" handler="scroll_event_cb"/>
<child>
<object class="GtkBox" id="box">
<property name="visible">True</property>
diff --git a/src/hdy-deck.c b/src/hdy-deck.c
index cadf9674..d45aa12a 100644
--- a/src/hdy-deck.c
+++ b/src/hdy-deck.c
@@ -697,8 +697,6 @@ hdy_deck_finalize (GObject *object)
g_clear_object (&priv->box);
- g_object_set_data (object, "captured-event-handler", NULL);
-
G_OBJECT_CLASS (hdy_deck_parent_class)->finalize (object);
}
@@ -820,13 +818,6 @@ hdy_deck_get_cancel_progress (HdySwipeable *swipeable)
return hdy_stackable_box_get_cancel_progress (HDY_GET_HELPER (swipeable));
}
-static gboolean
-captured_event_cb (HdyDeck *self,
- GdkEvent *event)
-{
- return hdy_stackable_box_captured_event (HDY_GET_HELPER (self), event);
-}
-
static void
hdy_deck_class_init (HdyDeckClass *klass)
{
@@ -1072,14 +1063,6 @@ hdy_deck_init (HdyDeck *self)
g_signal_connect_object (priv->box, "notify::can-swipe-back", G_CALLBACK (notify_can_swipe_back_cb), self,
G_CONNECT_SWAPPED);
g_signal_connect_object (priv->box, "notify::can-swipe-forward", G_CALLBACK (notify_can_swipe_forward_cb),
self, G_CONNECT_SWAPPED);
g_signal_connect_object (priv->box, "notify::orientation", G_CALLBACK (notify_orientation_cb), self,
G_CONNECT_SWAPPED);
-
- /*
- * HACK: GTK3 has no other way to get events on capture phase.
- * This is a reimplementation of _gtk_widget_set_captured_event_handler(),
- * which is private. In GTK4 it can be replaced with GtkEventControllerLegacy
- * with capture propagation phase
- */
- g_object_set_data (G_OBJECT (self), "captured-event-handler", captured_event_cb);
}
static void
diff --git a/src/hdy-leaflet.c b/src/hdy-leaflet.c
index b70b3df9..cd098a36 100644
--- a/src/hdy-leaflet.c
+++ b/src/hdy-leaflet.c
@@ -761,8 +761,6 @@ hdy_leaflet_finalize (GObject *object)
g_clear_object (&priv->box);
- g_object_set_data (object, "captured-event-handler", NULL);
-
G_OBJECT_CLASS (hdy_leaflet_parent_class)->finalize (object);
}
@@ -893,13 +891,6 @@ hdy_leaflet_get_cancel_progress (HdySwipeable *swipeable)
return hdy_stackable_box_get_cancel_progress (HDY_GET_HELPER (swipeable));
}
-static gboolean
-captured_event_cb (HdyLeaflet *self,
- GdkEvent *event)
-{
- return hdy_stackable_box_captured_event (HDY_GET_HELPER (self), event);
-}
-
static void
hdy_leaflet_class_init (HdyLeafletClass *klass)
{
@@ -1177,14 +1168,6 @@ hdy_leaflet_init (HdyLeaflet *self)
g_signal_connect_object (priv->box, "notify::can-swipe-back", G_CALLBACK (notify_can_swipe_back_cb), self,
G_CONNECT_SWAPPED);
g_signal_connect_object (priv->box, "notify::can-swipe-forward", G_CALLBACK (notify_can_swipe_forward_cb),
self, G_CONNECT_SWAPPED);
g_signal_connect_object (priv->box, "notify::orientation", G_CALLBACK (notify_orientation_cb), self,
G_CONNECT_SWAPPED);
-
- /*
- * HACK: GTK3 has no other way to get events on capture phase.
- * This is a reimplementation of _gtk_widget_set_captured_event_handler(),
- * which is private. In GTK4 it can be replaced with GtkEventControllerLegacy
- * with capture propagation phase
- */
- g_object_set_data (G_OBJECT (self), "captured-event-handler", captured_event_cb);
}
static void
diff --git a/src/hdy-stackable-box-private.h b/src/hdy-stackable-box-private.h
index e9a19aa3..30ef1be9 100644
--- a/src/hdy-stackable-box-private.h
+++ b/src/hdy-stackable-box-private.h
@@ -84,8 +84,6 @@ void hdy_stackable_box_set_child_allow_visible (HdyStackableBox *sel
GtkWidget *widget,
gboolean allow_visible);
-gboolean hdy_stackable_box_captured_event (HdyStackableBox *self,
- GdkEvent *event);
void hdy_stackable_box_switch_child (HdyStackableBox *self,
guint index,
gint64 duration);
diff --git a/src/hdy-stackable-box.c b/src/hdy-stackable-box.c
index 05a4e21f..b07364a8 100644
--- a/src/hdy-stackable-box.c
+++ b/src/hdy-stackable-box.c
@@ -3132,13 +3132,6 @@ hdy_stackable_box_get_cancel_progress (HdyStackableBox *self)
return 0;
}
-gboolean
-hdy_stackable_box_captured_event (HdyStackableBox *self,
- GdkEvent *event)
-{
- return hdy_swipe_tracker_captured_event (self->tracker, event);
-}
-
void
hdy_stackable_box_switch_child (HdyStackableBox *self,
guint index,
diff --git a/src/hdy-swipe-tracker-private.h b/src/hdy-swipe-tracker-private.h
index 4e027d85..2f4fa541 100644
--- a/src/hdy-swipe-tracker-private.h
+++ b/src/hdy-swipe-tracker-private.h
@@ -33,9 +33,6 @@ gboolean hdy_swipe_tracker_get_allow_mouse_drag (HdySwipeTracker *self);
void hdy_swipe_tracker_set_allow_mouse_drag (HdySwipeTracker *self,
gboolean allow_mouse_drag);
-gboolean hdy_swipe_tracker_captured_event (HdySwipeTracker *self,
- GdkEvent *event);
-
void hdy_swipe_tracker_shift_position (HdySwipeTracker *self,
gdouble delta);
diff --git a/src/hdy-swipe-tracker.c b/src/hdy-swipe-tracker.c
index eb8820a5..fec43943 100644
--- a/src/hdy-swipe-tracker.c
+++ b/src/hdy-swipe-tracker.c
@@ -34,27 +34,6 @@
* gestures. It supports touch-based swipes, pointer dragging, and touchpad
* scrolling.
*
- * The events must be received as early as possible to defer the events to
- * child widgets when needed. Usually this happens naturally, but
- * GtkScrolledWindow receives events on capture phase via a private function.
- * Because of that, implementing widgets must do the same thing, i.e. receive
- * events on capture phase and call hdy_swipe_tracker_captured_event() for
- * each event. This can be done as follows:
- * |[<!-- language="C" -->
- * g_object_set_data (G_OBJECT (self), "captured-event-handler", captured_event_cb);
- * ]|
- * Where captured_event_cb() is:
- * |[<!-- language="C" -->
- * static gboolean
- * captured_event_cb (MyWidget *self, GdkEvent *event)
- * {
- * return hdy_swipe_tracker_captured_event (self->tracker, event);
- * }
- * ]|
- *
- * NOTE: In GTK4 this can be replaced by a GtkEventControllerLegacy with capture
- * propagation phase.
- *
* The widgets will probably want to expose #HdySwipeTracker:enabled property.
* If they expect to use horizontal orientation, #HdySwipeTracker:reversed
* property can be used for supporting RTL text direction.
@@ -535,6 +514,23 @@ handle_event_cb (HdySwipeTracker *self,
return retval;
}
+static gboolean
+captured_event_cb (HdySwipeable *swipeable,
+ GdkEvent *event)
+{
+ HdySwipeTracker *self = g_object_get_data (G_OBJECT (swipeable), "swipe-tracker");
+
+ g_assert (HDY_IS_SWIPE_TRACKER (self));
+
+ if (!self->enabled && self->state != HDY_SWIPE_TRACKER_STATE_SCROLLING)
+ return GDK_EVENT_PROPAGATE;
+
+ if (event->type != GDK_SCROLL)
+ return GDK_EVENT_PROPAGATE;
+
+ return handle_scroll_event (self, event, TRUE);
+}
+
static void
hdy_swipe_tracker_constructed (GObject *object)
{
@@ -564,6 +560,14 @@ hdy_swipe_tracker_constructed (GObject *object)
g_object_set_data (G_OBJECT (self->swipeable), "swipe-tracker", self);
+ /*
+ * HACK: GTK3 has no other way to get events on capture phase.
+ * This is a reimplementation of _gtk_widget_set_captured_event_handler(),
+ * which is private. In GTK4 it can be replaced with GtkEventControllerLegacy
+ * with capture propagation phase
+ */
+ g_object_set_data (G_OBJECT (self->swipeable), "captured-event-handler", captured_event_cb);
+
G_OBJECT_CLASS (hdy_swipe_tracker_parent_class)->constructed (object);
}
@@ -579,6 +583,7 @@ hdy_swipe_tracker_dispose (GObject *object)
g_signal_handlers_disconnect_by_data (self->touch_gesture, self);
g_object_set_data (G_OBJECT (self->swipeable), "swipe-tracker", NULL);
+ g_object_set_data (G_OBJECT (self->swipeable), "captured-event-handler", NULL);
g_clear_object (&self->touch_gesture);
g_clear_object (&self->swipeable);
@@ -908,33 +913,6 @@ hdy_swipe_tracker_set_allow_mouse_drag (HdySwipeTracker *self,
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ALLOW_MOUSE_DRAG]);
}
-/**
- * hdy_swipe_tracker_captured_event:
- * @self: a #HdySwipeTracker
- * @event: a captured #GdkEvent
- *
- * Handles an event. This must be called for events received at capture phase
- * only.
- *
- * Returns: %TRUE is the event was handled and must not be propagated
- *
- * Since: 0.0.11
- */
-gboolean
-hdy_swipe_tracker_captured_event (HdySwipeTracker *self,
- GdkEvent *event)
-{
- g_return_val_if_fail (HDY_IS_SWIPE_TRACKER (self), GDK_EVENT_PROPAGATE);
-
- if (!self->enabled && self->state != HDY_SWIPE_TRACKER_STATE_SCROLLING)
- return GDK_EVENT_PROPAGATE;
-
- if (event->type != GDK_SCROLL)
- return GDK_EVENT_PROPAGATE;
-
- return handle_scroll_event (self, event, TRUE);
-}
-
void
hdy_swipe_tracker_shift_position (HdySwipeTracker *self,
gdouble delta)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]