clapper-gtk: Fix seek bar touchpad scrolling

Since we only do seek on scale drop, handle scrubbing using touchpad
the same way by marking it as "dragging" after scrubbing starts and
doing seek after it ends.
This commit is contained in:
Rafał Dzięgiel
2024-04-07 20:08:48 +02:00
parent 6e17996691
commit 1327dc23e4
2 changed files with 47 additions and 0 deletions

View File

@@ -55,6 +55,9 @@ struct _ClapperGtkSeekBar
gboolean has_hours;
gboolean has_markers;
gboolean can_scrub;
gboolean scrubbing;
gboolean dragging;
guint position_uint;
@@ -288,6 +291,38 @@ scale_css_classes_changed_cb (GtkWidget *widget,
}
}
static void
scale_scroll_begin_cb (GtkEventControllerScroll *scroll, ClapperGtkSeekBar *self)
{
self->can_scrub = TRUE;
}
static gboolean
scale_scroll_cb (GtkEventControllerScroll *scroll,
gdouble dx, gdouble dy, ClapperGtkSeekBar *self)
{
if (self->can_scrub && !self->scrubbing) {
GST_DEBUG_OBJECT (self, "Scrubbing start");
self->scrubbing = TRUE;
gtk_widget_add_css_class (self->scale, "dragging");
return TRUE;
}
return FALSE;
}
static void
scale_scroll_end_cb (GtkEventControllerScroll *scroll, ClapperGtkSeekBar *self)
{
if (self->scrubbing) {
GST_DEBUG_OBJECT (self, "Scrubbing end");
gtk_widget_remove_css_class (self->scale, "dragging");
self->scrubbing = FALSE;
}
self->can_scrub = FALSE;
}
static void
motion_cb (GtkEventControllerMotion *motion,
gdouble x, gdouble y, ClapperGtkSeekBar *self)
@@ -773,6 +808,9 @@ clapper_gtk_seek_bar_class_init (ClapperGtkSeekBarClass *klass)
gtk_widget_class_bind_template_callback (widget_class, scale_value_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, scale_css_classes_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, scale_scroll_begin_cb);
gtk_widget_class_bind_template_callback (widget_class, scale_scroll_cb);
gtk_widget_class_bind_template_callback (widget_class, scale_scroll_end_cb);
gtk_widget_class_bind_template_callback (widget_class, motion_cb);
gtk_widget_class_bind_template_callback (widget_class, motion_leave_cb);
gtk_widget_class_bind_template_callback (widget_class, touch_released_cb);

View File

@@ -29,6 +29,15 @@
<property name="adjustment">position_adjustment</property>
<signal name="value-changed" handler="scale_value_changed_cb"/>
<signal name="notify::css-classes" handler="scale_css_classes_changed_cb"/>
<child>
<object class="GtkEventControllerScroll">
<property name="propagation-phase">capture</property>
<property name="flags">both-axes</property>
<signal name="scroll-begin" handler="scale_scroll_begin_cb"/>
<signal name="scroll" handler="scale_scroll_cb"/>
<signal name="scroll-end" handler="scale_scroll_end_cb"/>
</object>
</child>
</object>
</child>
<child>