forked from AuroraMiddleware/gtk
Merge branch 'wip/carlosg/fix-accumulated-velocity' into 'main'
kinetic scroll fixes See merge request GNOME/gtk!4572
This commit is contained in:
commit
4a0ddac307
@ -181,8 +181,6 @@ gtk_kinetic_scrolling_tick (GtkKineticScrolling *data,
|
|||||||
{
|
{
|
||||||
case GTK_KINETIC_SCROLLING_PHASE_DECELERATING:
|
case GTK_KINETIC_SCROLLING_PHASE_DECELERATING:
|
||||||
{
|
{
|
||||||
double last_position = data->position;
|
|
||||||
double last_time = data->t;
|
|
||||||
double exp_part;
|
double exp_part;
|
||||||
|
|
||||||
data->t += time_delta;
|
data->t += time_delta;
|
||||||
@ -199,8 +197,7 @@ gtk_kinetic_scrolling_tick (GtkKineticScrolling *data,
|
|||||||
{
|
{
|
||||||
gtk_kinetic_scrolling_init_overshoot(data, data->upper, data->position, data->velocity);
|
gtk_kinetic_scrolling_init_overshoot(data, data->upper, data->position, data->velocity);
|
||||||
}
|
}
|
||||||
else if (fabs(data->velocity) < 1 ||
|
else if (fabs(data->velocity) < 0.1)
|
||||||
(last_time != 0.0 && fabs(data->position - last_position) < 1))
|
|
||||||
{
|
{
|
||||||
gtk_kinetic_scrolling_stop (data);
|
gtk_kinetic_scrolling_stop (data);
|
||||||
}
|
}
|
||||||
@ -254,6 +251,5 @@ gtk_kinetic_scrolling_stop (GtkKineticScrolling *data)
|
|||||||
{
|
{
|
||||||
data->phase = GTK_KINETIC_SCROLLING_PHASE_FINISHED;
|
data->phase = GTK_KINETIC_SCROLLING_PHASE_FINISHED;
|
||||||
data->position = round (data->position);
|
data->position = round (data->position);
|
||||||
data->velocity = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1056,6 +1056,11 @@ gtk_scrolled_window_decelerate (GtkScrolledWindow *scrolled_window,
|
|||||||
gtk_scrolled_window_start_deceleration (scrolled_window);
|
gtk_scrolled_window_start_deceleration (scrolled_window);
|
||||||
priv->x_velocity = priv->y_velocity = 0;
|
priv->x_velocity = priv->y_velocity = 0;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_clear_pointer (&priv->hscrolling, gtk_kinetic_scrolling_free);
|
||||||
|
g_clear_pointer (&priv->vscrolling, gtk_kinetic_scrolling_free);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -3268,6 +3273,7 @@ scrolled_window_deceleration_cb (GtkWidget *widget,
|
|||||||
GtkAdjustment *hadjustment, *vadjustment;
|
GtkAdjustment *hadjustment, *vadjustment;
|
||||||
gint64 current_time;
|
gint64 current_time;
|
||||||
double position, elapsed;
|
double position, elapsed;
|
||||||
|
gboolean retval = G_SOURCE_REMOVE;
|
||||||
|
|
||||||
current_time = gdk_frame_clock_get_frame_time (frame_clock);
|
current_time = gdk_frame_clock_get_frame_time (frame_clock);
|
||||||
elapsed = (current_time - priv->last_deceleration_time) / (double)G_TIME_SPAN_SECOND;
|
elapsed = (current_time - priv->last_deceleration_time) / (double)G_TIME_SPAN_SECOND;
|
||||||
@ -3283,28 +3289,23 @@ scrolled_window_deceleration_cb (GtkWidget *widget,
|
|||||||
{
|
{
|
||||||
priv->unclamped_hadj_value = position;
|
priv->unclamped_hadj_value = position;
|
||||||
gtk_adjustment_set_value (hadjustment, position);
|
gtk_adjustment_set_value (hadjustment, position);
|
||||||
|
retval = G_SOURCE_CONTINUE;
|
||||||
}
|
}
|
||||||
else if (priv->hscrolling)
|
|
||||||
g_clear_pointer (&priv->hscrolling, gtk_kinetic_scrolling_free);
|
|
||||||
|
|
||||||
if (priv->vscrolling &&
|
if (priv->vscrolling &&
|
||||||
gtk_kinetic_scrolling_tick (priv->vscrolling, elapsed, &position, NULL))
|
gtk_kinetic_scrolling_tick (priv->vscrolling, elapsed, &position, NULL))
|
||||||
{
|
{
|
||||||
priv->unclamped_vadj_value = position;
|
priv->unclamped_vadj_value = position;
|
||||||
gtk_adjustment_set_value (vadjustment, position);
|
gtk_adjustment_set_value (vadjustment, position);
|
||||||
|
retval = G_SOURCE_CONTINUE;
|
||||||
}
|
}
|
||||||
else if (priv->vscrolling)
|
|
||||||
g_clear_pointer (&priv->vscrolling, gtk_kinetic_scrolling_free);
|
|
||||||
|
|
||||||
if (!priv->hscrolling && !priv->vscrolling)
|
if (retval == G_SOURCE_REMOVE)
|
||||||
{
|
|
||||||
gtk_scrolled_window_cancel_deceleration (scrolled_window);
|
gtk_scrolled_window_cancel_deceleration (scrolled_window);
|
||||||
return G_SOURCE_REMOVE;
|
else
|
||||||
}
|
|
||||||
|
|
||||||
gtk_scrolled_window_invalidate_overshoot (scrolled_window);
|
gtk_scrolled_window_invalidate_overshoot (scrolled_window);
|
||||||
|
|
||||||
return G_SOURCE_CONTINUE;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -3368,7 +3369,10 @@ gtk_scrolled_window_start_deceleration (GtkScrolledWindow *scrolled_window)
|
|||||||
GtkAdjustment *hadjustment;
|
GtkAdjustment *hadjustment;
|
||||||
|
|
||||||
gtk_scrolled_window_accumulate_velocity (&priv->hscrolling, elapsed, &priv->x_velocity);
|
gtk_scrolled_window_accumulate_velocity (&priv->hscrolling, elapsed, &priv->x_velocity);
|
||||||
|
g_clear_pointer (&priv->hscrolling, gtk_kinetic_scrolling_free);
|
||||||
|
|
||||||
|
if (priv->x_velocity != 0)
|
||||||
|
{
|
||||||
hadjustment = gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (priv->hscrollbar));
|
hadjustment = gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (priv->hscrollbar));
|
||||||
lower = gtk_adjustment_get_lower (hadjustment);
|
lower = gtk_adjustment_get_lower (hadjustment);
|
||||||
upper = gtk_adjustment_get_upper (hadjustment);
|
upper = gtk_adjustment_get_upper (hadjustment);
|
||||||
@ -3382,6 +3386,7 @@ gtk_scrolled_window_start_deceleration (GtkScrolledWindow *scrolled_window)
|
|||||||
priv->unclamped_hadj_value,
|
priv->unclamped_hadj_value,
|
||||||
priv->x_velocity);
|
priv->x_velocity);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
g_clear_pointer (&priv->hscrolling, gtk_kinetic_scrolling_free);
|
g_clear_pointer (&priv->hscrolling, gtk_kinetic_scrolling_free);
|
||||||
|
|
||||||
@ -3391,7 +3396,10 @@ gtk_scrolled_window_start_deceleration (GtkScrolledWindow *scrolled_window)
|
|||||||
GtkAdjustment *vadjustment;
|
GtkAdjustment *vadjustment;
|
||||||
|
|
||||||
gtk_scrolled_window_accumulate_velocity (&priv->vscrolling, elapsed, &priv->y_velocity);
|
gtk_scrolled_window_accumulate_velocity (&priv->vscrolling, elapsed, &priv->y_velocity);
|
||||||
|
g_clear_pointer (&priv->vscrolling, gtk_kinetic_scrolling_free);
|
||||||
|
|
||||||
|
if (priv->y_velocity != 0)
|
||||||
|
{
|
||||||
vadjustment = gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (priv->vscrollbar));
|
vadjustment = gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (priv->vscrollbar));
|
||||||
lower = gtk_adjustment_get_lower(vadjustment);
|
lower = gtk_adjustment_get_lower(vadjustment);
|
||||||
upper = gtk_adjustment_get_upper(vadjustment);
|
upper = gtk_adjustment_get_upper(vadjustment);
|
||||||
@ -3405,6 +3413,7 @@ gtk_scrolled_window_start_deceleration (GtkScrolledWindow *scrolled_window)
|
|||||||
priv->unclamped_vadj_value,
|
priv->unclamped_vadj_value,
|
||||||
priv->y_velocity);
|
priv->y_velocity);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
g_clear_pointer (&priv->vscrolling, gtk_kinetic_scrolling_free);
|
g_clear_pointer (&priv->vscrolling, gtk_kinetic_scrolling_free);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user