[libhandy] carousel: Add the allow-scroll-wheel prop
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy] carousel: Add the allow-scroll-wheel prop
- Date: Thu, 29 Apr 2021 09:43:25 +0000 (UTC)
commit 47bad070c5e441819b9f3bfb2631ba399e2105d4
Author: Adrien Plazas <kekun plazas laposte net>
Date: Wed Apr 28 16:12:12 2021 +0200
carousel: Add the allow-scroll-wheel prop
Fixes https://gitlab.gnome.org/GNOME/libhandy/-/issues/434
debian/libhandy-1-0.symbols | 2 ++
src/hdy-carousel.c | 75 +++++++++++++++++++++++++++++++++++++++++++++
src/hdy-carousel.h | 6 ++++
3 files changed, 83 insertions(+)
---
diff --git a/debian/libhandy-1-0.symbols b/debian/libhandy-1-0.symbols
index c2af72f8..8bbe291b 100644
--- a/debian/libhandy-1-0.symbols
+++ b/debian/libhandy-1-0.symbols
@@ -36,6 +36,7 @@ libhandy-1.so.0 libhandy-1-0 #MINVER#
hdy_avatar_set_loadable_icon@LIBHANDY_1_0 1.2.0
hdy_carousel_get_allow_long_swipes@LIBHANDY_1_0 1.2.0
hdy_carousel_get_allow_mouse_drag@LIBHANDY_1_0 0.80.0
+ hdy_carousel_get_allow_scroll_wheel@LIBHANDY_1_0 1.2.0
hdy_carousel_get_animation_duration@LIBHANDY_1_0 0.80.0
hdy_carousel_get_interactive@LIBHANDY_1_0 0.80.0
hdy_carousel_get_n_pages@LIBHANDY_1_0 0.80.0
@@ -59,6 +60,7 @@ libhandy-1.so.0 libhandy-1-0 #MINVER#
hdy_carousel_scroll_to_full@LIBHANDY_1_0 0.80.0
hdy_carousel_set_allow_long_swipes@LIBHANDY_1_0 1.2.0
hdy_carousel_set_allow_mouse_drag@LIBHANDY_1_0 0.80.0
+ hdy_carousel_set_allow_scroll_wheel@LIBHANDY_1_0 1.2.0
hdy_carousel_set_animation_duration@LIBHANDY_1_0 0.80.0
hdy_carousel_set_interactive@LIBHANDY_1_0 0.80.0
hdy_carousel_set_reveal_duration@LIBHANDY_1_0 0.81.0
diff --git a/src/hdy-carousel.c b/src/hdy-carousel.c
index 612d7566..62ec0585 100644
--- a/src/hdy-carousel.c
+++ b/src/hdy-carousel.c
@@ -43,6 +43,8 @@ struct _HdyCarousel
HdySwipeTracker *tracker;
+ gboolean allow_scroll_wheel;
+
GtkOrientation orientation;
guint animation_duration;
@@ -64,6 +66,7 @@ enum {
PROP_SPACING,
PROP_ANIMATION_DURATION,
PROP_ALLOW_MOUSE_DRAG,
+ PROP_ALLOW_SCROLL_WHEEL,
PROP_ALLOW_LONG_SWIPES,
PROP_REVEAL_DURATION,
@@ -281,6 +284,9 @@ scroll_event_cb (HdyCarousel *self,
GtkOrientation orientation;
guint duration;
+ if (!self->allow_scroll_wheel)
+ return GDK_EVENT_PROPAGATE;
+
if (!self->can_scroll)
return GDK_EVENT_PROPAGATE;
@@ -474,6 +480,10 @@ hdy_carousel_get_property (GObject *object,
g_value_set_boolean (value, hdy_carousel_get_allow_mouse_drag (self));
break;
+ case PROP_ALLOW_SCROLL_WHEEL:
+ g_value_set_boolean (value, hdy_carousel_get_allow_scroll_wheel (self));
+ break;
+
case PROP_ALLOW_LONG_SWIPES:
g_value_set_boolean (value, hdy_carousel_get_allow_long_swipes (self));
break;
@@ -524,6 +534,10 @@ hdy_carousel_set_property (GObject *object,
hdy_carousel_set_allow_mouse_drag (self, g_value_get_boolean (value));
break;
+ case PROP_ALLOW_SCROLL_WHEEL:
+ hdy_carousel_set_allow_scroll_wheel (self, g_value_get_boolean (value));
+ break;
+
case PROP_ALLOW_LONG_SWIPES:
hdy_carousel_set_allow_long_swipes (self, g_value_get_boolean (value));
break;
@@ -665,6 +679,21 @@ hdy_carousel_class_init (HdyCarouselClass *klass)
TRUE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+ /**
+ * HdyCarousel:allow-scroll-wheel:
+ *
+ * Whether the widget will respond to scroll wheel events. If the value is
+ * %FALSE, wheel events will be ignored.
+ *
+ * Since: 1.4
+ */
+ props[PROP_ALLOW_SCROLL_WHEEL] =
+ g_param_spec_boolean ("allow-scroll-wheel",
+ _("Allow scroll wheel"),
+ _("Whether the widget will respond to scroll wheel events"),
+ TRUE,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
/**
* HdyCarousel:allow-long-swipes:
*
@@ -740,6 +769,8 @@ hdy_carousel_class_init (HdyCarouselClass *klass)
static void
hdy_carousel_init (HdyCarousel *self)
{
+ self->allow_scroll_wheel = TRUE;
+
g_type_ensure (HDY_TYPE_CAROUSEL_BOX);
gtk_widget_init_template (GTK_WIDGET (self));
@@ -1084,6 +1115,50 @@ hdy_carousel_set_allow_mouse_drag (HdyCarousel *self,
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ALLOW_MOUSE_DRAG]);
}
+/**
+ * hdy_carousel_get_allow_scroll_wheel:
+ * @self: a #HdyCarousel
+ *
+ * Gets whether @self will respond to scroll wheel events.
+ *
+ * Returns: %TRUE if @self will respond to scroll wheel events
+ *
+ * Since: 1.4
+ */
+gboolean
+hdy_carousel_get_allow_scroll_wheel (HdyCarousel *self)
+{
+ g_return_val_if_fail (HDY_IS_CAROUSEL (self), FALSE);
+
+ return self->allow_scroll_wheel;
+}
+
+/**
+ * hdy_carousel_set_allow_scroll_wheel:
+ * @self: a #HdyCarousel
+ * @allow_scroll_wheel: whether @self will respond to scroll wheel events.
+ *
+ * Sets whether @self will respond to scroll wheel events. If the value is
+ * %FALSE, wheel events will be ignored.
+ *
+ * Since: 1.4
+ */
+void
+hdy_carousel_set_allow_scroll_wheel (HdyCarousel *self,
+ gboolean allow_scroll_wheel)
+{
+ g_return_if_fail (HDY_IS_CAROUSEL (self));
+
+ allow_scroll_wheel = !!allow_scroll_wheel;
+
+ if (self->allow_scroll_wheel == allow_scroll_wheel)
+ return;
+
+ self->allow_scroll_wheel = allow_scroll_wheel;
+
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ALLOW_SCROLL_WHEEL]);
+}
+
/**
* hdy_carousel_get_allow_long_swipes:
* @self: a #HdyCarousel
diff --git a/src/hdy-carousel.h b/src/hdy-carousel.h
index 1b11bc45..fcc497d7 100644
--- a/src/hdy-carousel.h
+++ b/src/hdy-carousel.h
@@ -73,6 +73,12 @@ HDY_AVAILABLE_IN_ALL
void hdy_carousel_set_allow_mouse_drag (HdyCarousel *self,
gboolean allow_mouse_drag);
+HDY_AVAILABLE_IN_1_4
+gboolean hdy_carousel_get_allow_scroll_wheel (HdyCarousel *self);
+HDY_AVAILABLE_IN_1_4
+void hdy_carousel_set_allow_scroll_wheel (HdyCarousel *self,
+ gboolean allow_scroll_wheel);
+
HDY_AVAILABLE_IN_1_2
gboolean hdy_carousel_get_allow_long_swipes (HdyCarousel *self);
HDY_AVAILABLE_IN_1_2
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]