[libhandy/swipe-tracker-public: 10/16] swipeable: Add start coordinates to start_swipe()
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy/swipe-tracker-public: 10/16] swipeable: Add start coordinates to start_swipe()
- Date: Sun, 14 Jun 2020 20:45:24 +0000 (UTC)
commit f1ca508df9831ed75139d4fa9ffb39fbe7ea9c93
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Mon Jun 15 00:45:07 2020 +0500
swipeable: Add start coordinates to start_swipe()
They were present in the initial implementation of HdySwipeTracker, but
were removed prior to introducing HdySwipeGroup because I wasn't sure how
to deal with them for indirect swipes. However, they may be necessary in
future, for example for https://gitlab.gnome.org/GNOME/libhandy/-/issues/167
or transient sidebars or bottom sheets. So let's add it back, and translate
the coordinates for the indirect swipes. Better than having to change the
API when it's public.
Signed-off-by: Alexander Mikhaylenko <alexm gnome org>
src/hdy-carousel.c | 4 +++-
src/hdy-deck.c | 6 ++++--
src/hdy-leaflet.c | 6 ++++--
src/hdy-stackable-box-private.h | 4 +++-
src/hdy-stackable-box.c | 4 +++-
src/hdy-swipe-group.c | 13 +++++++++++--
src/hdy-swipe-tracker.c | 24 ++++++++++++++++++++++--
src/hdy-swipeable-private.h | 4 +++-
src/hdy-swipeable.c | 22 +++++++++++++++++-----
src/hdy-swipeable.h | 4 +++-
10 files changed, 73 insertions(+), 18 deletions(-)
---
diff --git a/src/hdy-carousel.c b/src/hdy-carousel.c
index 4fe57a7a..7fa6d8b1 100644
--- a/src/hdy-carousel.c
+++ b/src/hdy-carousel.c
@@ -182,7 +182,9 @@ hdy_carousel_switch_child (HdySwipeable *swipeable,
static void
hdy_carousel_start_swipe (HdySwipeable *swipeable,
HdyNavigationDirection direction,
- gboolean direct)
+ gboolean direct,
+ gint start_x,
+ gint start_y)
{
HdyCarousel *self = HDY_CAROUSEL (swipeable);
diff --git a/src/hdy-deck.c b/src/hdy-deck.c
index 9dc62445..a1acb927 100644
--- a/src/hdy-deck.c
+++ b/src/hdy-deck.c
@@ -780,9 +780,11 @@ hdy_deck_switch_child (HdySwipeable *swipeable,
static void
hdy_deck_start_swipe (HdySwipeable *swipeable,
HdyNavigationDirection direction,
- gboolean direct)
+ gboolean direct,
+ gint start_x,
+ gint start_y)
{
- hdy_stackable_box_start_swipe (HDY_GET_HELPER (swipeable), direction, direct);
+ hdy_stackable_box_start_swipe (HDY_GET_HELPER (swipeable), direction, direct, start_x, start_y);
}
static void
diff --git a/src/hdy-leaflet.c b/src/hdy-leaflet.c
index 6041dbdf..9b35bea1 100644
--- a/src/hdy-leaflet.c
+++ b/src/hdy-leaflet.c
@@ -853,9 +853,11 @@ hdy_leaflet_switch_child (HdySwipeable *swipeable,
static void
hdy_leaflet_start_swipe (HdySwipeable *swipeable,
HdyNavigationDirection direction,
- gboolean direct)
+ gboolean direct,
+ gint start_x,
+ gint start_y)
{
- hdy_stackable_box_start_swipe (HDY_GET_HELPER (swipeable), direction, direct);
+ hdy_stackable_box_start_swipe (HDY_GET_HELPER (swipeable), direction, direct, start_x, start_y);
}
static void
diff --git a/src/hdy-stackable-box-private.h b/src/hdy-stackable-box-private.h
index 01296eb4..da2c21a8 100644
--- a/src/hdy-stackable-box-private.h
+++ b/src/hdy-stackable-box-private.h
@@ -90,7 +90,9 @@ void hdy_stackable_box_switch_child (HdyStackableBox *self,
gint64 duration);
void hdy_stackable_box_start_swipe (HdyStackableBox *self,
HdyNavigationDirection direction,
- gboolean direct);
+ gboolean direct,
+ gint start_x,
+ gint start_y);
void hdy_stackable_box_update_swipe (HdyStackableBox *self,
gdouble value);
void hdy_stackable_box_end_swipe (HdyStackableBox *self,
diff --git a/src/hdy-stackable-box.c b/src/hdy-stackable-box.c
index a1c7b679..a83461db 100644
--- a/src/hdy-stackable-box.c
+++ b/src/hdy-stackable-box.c
@@ -3192,7 +3192,9 @@ hdy_stackable_box_switch_child (HdyStackableBox *self,
void
hdy_stackable_box_start_swipe (HdyStackableBox *self,
HdyNavigationDirection direction,
- gboolean direct)
+ gboolean direct,
+ gint start_x,
+ gint start_y)
{
self->child_transition.is_direct_swipe = direct;
self->child_transition.swipe_direction = direction;
diff --git a/src/hdy-swipe-group.c b/src/hdy-swipe-group.c
index add9bd58..2badae8e 100644
--- a/src/hdy-swipe-group.c
+++ b/src/hdy-swipe-group.c
@@ -120,6 +120,8 @@ child_switched_cb (HdySwipeGroup *self,
static void
swipe_started_cb (HdySwipeGroup *self,
HdyNavigationDirection direction,
+ gint start_x,
+ gint start_y,
HdySwipeable *swipeable)
{
GSList *swipeables;
@@ -130,8 +132,15 @@ swipe_started_cb (HdySwipeGroup *self,
self->current = swipeable;
for (swipeables = self->swipeables; swipeables != NULL; swipeables = swipeables->next)
- if (swipeables->data != swipeable)
- hdy_swipeable_start_swipe (swipeables->data, direction, FALSE);
+ if (swipeables->data != swipeable) {
+ gint x, y;
+
+ gtk_widget_translate_coordinates (GTK_WIDGET (swipeable),
+ GTK_WIDGET (swipeables->data),
+ start_x, start_y,
+ &x, &y);
+ hdy_swipeable_start_swipe (swipeables->data, direction, FALSE, x, y);
+ }
}
static void
diff --git a/src/hdy-swipe-tracker.c b/src/hdy-swipe-tracker.c
index 8ce7c447..4c3a73d3 100644
--- a/src/hdy-swipe-tracker.c
+++ b/src/hdy-swipe-tracker.c
@@ -79,6 +79,9 @@ struct _HdySwipeTracker
gboolean allow_mouse_drag;
GtkOrientation orientation;
+ int start_x;
+ int start_y;
+
guint32 prev_time;
gdouble velocity;
@@ -116,6 +119,9 @@ reset (HdySwipeTracker *self)
{
self->state = HDY_SWIPE_TRACKER_STATE_NONE;
+ self->start_x = 0;
+ self->start_y = 0;
+
self->prev_offset = 0;
self->initial_progress = 0;
@@ -137,7 +143,7 @@ gesture_prepare (HdySwipeTracker *self,
if (self->state != HDY_SWIPE_TRACKER_STATE_NONE)
return;
- hdy_swipeable_start_swipe (self->swipeable, direction, TRUE);
+ hdy_swipeable_start_swipe (self->swipeable, direction, TRUE, self->start_x, self->start_y);
self->initial_progress = hdy_swipeable_get_progress (self->swipeable);
self->progress = self->initial_progress;
@@ -290,6 +296,9 @@ drag_begin_cb (HdySwipeTracker *self,
{
if (self->state != HDY_SWIPE_TRACKER_STATE_NONE)
gtk_gesture_set_state (self->touch_gesture, GTK_EVENT_SEQUENCE_DENIED);
+
+ self->start_x = start_x;
+ self->start_y = start_y;
}
static void
@@ -424,8 +433,19 @@ handle_scroll_event (HdySwipeTracker *self,
return GDK_EVENT_PROPAGATE;
if (is_vertical == is_delta_vertical) {
- if (!capture)
+ if (!capture) {
+ GtkWidget *widget;
+ gdouble event_x, event_y;
+
+ widget = gtk_get_event_widget (event);
+
+ gdk_event_get_coords (event, &event_x, &event_y);
+ gtk_widget_translate_coordinates (widget, GTK_WIDGET (self->swipeable),
+ event_x, event_y,
+ &self->start_x, &self->start_y);
+
gesture_prepare (self, delta > 0 ? HDY_NAVIGATION_DIRECTION_FORWARD : HDY_NAVIGATION_DIRECTION_BACK);
+ }
} else {
self->is_scrolling = TRUE;
return GDK_EVENT_PROPAGATE;
diff --git a/src/hdy-swipeable-private.h b/src/hdy-swipeable-private.h
index bdfb223d..9a4f984f 100644
--- a/src/hdy-swipeable-private.h
+++ b/src/hdy-swipeable-private.h
@@ -16,7 +16,9 @@ void hdy_swipeable_switch_child (HdySwipeable *self,
gint64 duration);
void hdy_swipeable_start_swipe (HdySwipeable *self,
HdyNavigationDirection direction,
- gboolean direct);
+ gboolean direct,
+ gint start_x,
+ gint start_y);
void hdy_swipeable_update_swipe (HdySwipeable *self,
gdouble value);
void hdy_swipeable_end_swipe (HdySwipeable *self,
diff --git a/src/hdy-swipeable.c b/src/hdy-swipeable.c
index 218adc11..29cbbe13 100644
--- a/src/hdy-swipeable.c
+++ b/src/hdy-swipeable.c
@@ -63,6 +63,8 @@ hdy_swipeable_default_init (HdySwipeableInterface *iface)
* HdySwipeable::swipe-started:
* @self: The #HdySwipeable instance
* @direction: The direction of the swipe, can be 1 or -1
+ * @start_x: The X coordinate relative to the widget
+ * @start_y: The Y coordinate relative to the widget
*
* This signal is emitted when a possible swipe is detected. This is used by
* #HdySwipeGroup, applications should not connect to it.
@@ -78,8 +80,9 @@ hdy_swipeable_default_init (HdySwipeableInterface *iface)
0,
NULL, NULL, NULL,
G_TYPE_NONE,
- 1,
- HDY_TYPE_NAVIGATION_DIRECTION);
+ 3,
+ HDY_TYPE_NAVIGATION_DIRECTION,
+ G_TYPE_INT, G_TYPE_INT);
/**
* HdySwipeable::swipe-updated:
@@ -154,6 +157,8 @@ hdy_swipeable_switch_child (HdySwipeable *self,
* @direction: The direction of the swipe
* @direct: %TRUE if the swipe is directly triggered by a gesture,
* %FALSE if it's triggered via a #HdySwipeGroup
+ * @start_x: The X coordinate relative to the widget
+ * @start_y: The Y coordinate relative to the widget
*
* This function is called by #HdySwipeTracker when a possible swipe is detected.
* The implementation should check whether a swipe is possible, and if it is,
@@ -165,12 +170,18 @@ hdy_swipeable_switch_child (HdySwipeable *self,
* can still animate in sync with other widgets in a #HdySwipeGroup by only
* applying restrictions if @direct is %TRUE.
*
+ * If the swipe was initiated by #HdySwipeGroup, @start_x and/or @start_y may
+ * be out of the widget bounds depending on how the widgets are placed relative
+ * to each other.
+ *
* Since: 0.0.12
*/
void
hdy_swipeable_start_swipe (HdySwipeable *self,
HdyNavigationDirection direction,
- gboolean direct)
+ gboolean direct,
+ gint start_x,
+ gint start_y)
{
HdySwipeableInterface *iface;
@@ -179,9 +190,10 @@ hdy_swipeable_start_swipe (HdySwipeable *self,
iface = HDY_SWIPEABLE_GET_IFACE (self);
g_return_if_fail (iface->start_swipe != NULL);
- (* iface->start_swipe) (self, direction, direct);
+ (* iface->start_swipe) (self, direction, direct, start_x, start_y);
+ g_print ("Started! %s %d %d\n", G_OBJECT_TYPE_NAME (self), start_x, start_y);
- g_signal_emit (self, signals[SIGNAL_SWIPE_STARTED], 0, direction);
+ g_signal_emit (self, signals[SIGNAL_SWIPE_STARTED], 0, direction, start_x, start_y);
}
/**
diff --git a/src/hdy-swipeable.h b/src/hdy-swipeable.h
index 866b5bc9..11f6c9b5 100644
--- a/src/hdy-swipeable.h
+++ b/src/hdy-swipeable.h
@@ -45,7 +45,9 @@ struct _HdySwipeableInterface
gint64 duration);
void (*start_swipe) (HdySwipeable *self,
HdyNavigationDirection direction,
- gboolean direct);
+ gboolean direct,
+ gint start_x,
+ gint start_y);
void (*update_swipe) (HdySwipeable *self,
gdouble value);
void (*end_swipe) (HdySwipeable *self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]