st-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
This commit is contained in:
parent
ca73017100
commit
165265f4fb
@ -665,6 +665,45 @@ st_scroll_view_allocate (ClutterActor *actor,
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
adjust_with_delta (StAdjustment *adj,
|
||||
gdouble delta)
|
||||
{
|
||||
gdouble new_value, page_size, scroll_unit;
|
||||
|
||||
g_object_get (adj,
|
||||
"page-size", &page_size,
|
||||
NULL);
|
||||
scroll_unit = pow (page_size, 2.0 / 3.0);
|
||||
|
||||
new_value = st_adjustment_get_value (adj) + delta * scroll_unit;
|
||||
st_adjustment_set_value (adj, new_value);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
adjust_with_delta (adj, delta);
|
||||
}
|
||||
|
||||
static void
|
||||
st_scroll_view_style_changed (StWidget *widget)
|
||||
{
|
||||
@ -687,57 +726,29 @@ 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;
|
||||
}
|
||||
|
||||
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);
|
||||
adjust_with_delta (priv->hadjustment, delta_x);
|
||||
adjust_with_delta (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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user