[gnome-shell] scroll-view: Add proper smooth scrolling
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] scroll-view: Add proper smooth scrolling
- Date: Thu, 20 Dec 2012 13:40:30 +0000 (UTC)
commit 06dc12e217f0c2e94c761544b113ea8d24d0f19c
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Sun Nov 4 10:10:50 2012 -0500
scroll-view: Add proper smooth scrolling
The code here before was added as dummy code to satisfy an error
in the missing switch, and wasn't ever tested due to the lack of XI2
in mutter. Use the same math as GtkRange does to calculate scroll bar
positions from raw XI2 deltas to allow for proper smooth scrolling.
https://bugzilla.gnome.org/show_bug.cgi?id=687573
src/st/st-adjustment.c | 28 +++++++++++++++++++
src/st/st-adjustment.h | 4 +++
src/st/st-scroll-view.c | 70 +++++++++++++++++++++++------------------------
3 files changed, 66 insertions(+), 36 deletions(-)
---
diff --git a/src/st/st-adjustment.c b/src/st/st-adjustment.c
index e2ef9b2..e6b3367 100644
--- a/src/st/st-adjustment.c
+++ b/src/st/st-adjustment.c
@@ -566,3 +566,31 @@ st_adjustment_get_values (StAdjustment *adjustment,
*page_size = priv->page_size;
}
+/**
+ * st_adjustment_adjust_for_scroll_event:
+ * @adjustment: An #StAdjustment
+ * @delta: A delta, retrieved directly from clutter_event_get_scroll_delta()
+ * or similar.
+ *
+ * Adjusts the adjustment using delta values from a scroll event.
+ * You should use this instead of using st_adjustment_set_value()
+ * as this method will tweak the values directly using the same
+ * math as GTK+, to ensure that scrolling is consistent across
+ * the environment.
+ */
+void
+st_adjustment_adjust_for_scroll_event (StAdjustment *adjustment,
+ gdouble delta)
+{
+ StAdjustmentPrivate *priv;
+ gdouble new_value, scroll_unit;
+
+ g_return_if_fail (ST_IS_ADJUSTMENT (adjustment));
+
+ priv = adjustment->priv;
+
+ scroll_unit = pow (priv->page_size, 2.0 / 3.0);
+
+ new_value = priv->value + delta * scroll_unit;
+ st_adjustment_set_value (adjustment, new_value);
+}
diff --git a/src/st/st-adjustment.h b/src/st/st-adjustment.h
index 7660a08..fe041cf 100644
--- a/src/st/st-adjustment.h
+++ b/src/st/st-adjustment.h
@@ -99,6 +99,10 @@ void st_adjustment_get_values (StAdjustment *adjustment,
gdouble *step_increment,
gdouble *page_increment,
gdouble *page_size);
+
+void st_adjustment_adjust_for_scroll_event (StAdjustment *adjustment,
+ gdouble delta);
+
G_END_DECLS
#endif /* __ST_ADJUSTMENT_H__ */
diff --git a/src/st/st-scroll-view.c b/src/st/st-scroll-view.c
index c8f89ce..285ba2d 100644
--- a/src/st/st-scroll-view.c
+++ b/src/st/st-scroll-view.c
@@ -666,6 +666,30 @@ st_scroll_view_allocate (ClutterActor *actor,
}
static void
+adjust_with_direction (StAdjustment *adj,
+ ClutterScrollDirection direction)
+{
+ gdouble delta;
+
+ switch (direction)
+ {
+ case CLUTTER_SCROLL_UP:
+ case CLUTTER_SCROLL_LEFT:
+ delta = -1.0;
+ break;
+ case CLUTTER_SCROLL_RIGHT:
+ case CLUTTER_SCROLL_DOWN:
+ delta = 1.0;
+ break;
+ case CLUTTER_SCROLL_SMOOTH:
+ g_assert_not_reached ();
+ break;
+ }
+
+ st_adjustment_adjust_for_scroll_event (adj, delta);
+}
+
+static void
st_scroll_view_style_changed (StWidget *widget)
{
StScrollView *self = ST_SCROLL_VIEW (widget);
@@ -687,57 +711,31 @@ st_scroll_view_scroll_event (ClutterActor *self,
ClutterScrollEvent *event)
{
StScrollViewPrivate *priv = ST_SCROLL_VIEW (self)->priv;
- gdouble value, step, hvalue, vvalue, delta_x, delta_y;
/* don't handle scroll events if requested not to */
if (!priv->mouse_scroll)
return FALSE;
- switch (event->direction)
- {
- case CLUTTER_SCROLL_SMOOTH:
- clutter_event_get_scroll_delta ((ClutterEvent *)event,
- &delta_x, &delta_y);
- g_object_get (priv->hadjustment,
- "value", &hvalue,
- NULL);
- g_object_get (priv->vadjustment,
- "value", &vvalue,
- NULL);
- break;
- case CLUTTER_SCROLL_UP:
- case CLUTTER_SCROLL_DOWN:
- g_object_get (priv->vadjustment,
- "step-increment", &step,
- "value", &value,
- NULL);
- break;
- case CLUTTER_SCROLL_LEFT:
- case CLUTTER_SCROLL_RIGHT:
- g_object_get (priv->hadjustment,
- "step-increment", &step,
- "value", &value,
- NULL);
- break;
- }
+ if (clutter_event_is_pointer_emulated ((ClutterEvent *) event))
+ return TRUE;
switch (event->direction)
{
case CLUTTER_SCROLL_SMOOTH:
- st_adjustment_set_value (priv->hadjustment, hvalue + delta_x);
- st_adjustment_set_value (priv->vadjustment, vvalue + delta_y);
+ {
+ gdouble delta_x, delta_y;
+ clutter_event_get_scroll_delta ((ClutterEvent *)event, &delta_x, &delta_y);
+ st_adjustment_adjust_for_scroll_event (priv->hadjustment, delta_x);
+ st_adjustment_adjust_for_scroll_event (priv->vadjustment, delta_y);
+ }
break;
case CLUTTER_SCROLL_UP:
- st_adjustment_set_value (priv->vadjustment, value - step);
- break;
case CLUTTER_SCROLL_DOWN:
- st_adjustment_set_value (priv->vadjustment, value + step);
+ adjust_with_direction (priv->vadjustment, event->direction);
break;
case CLUTTER_SCROLL_LEFT:
- st_adjustment_set_value (priv->hadjustment, value - step);
- break;
case CLUTTER_SCROLL_RIGHT:
- st_adjustment_set_value (priv->hadjustment, value + step);
+ adjust_with_direction (priv->hadjustment, event->direction);
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]