[gtk+/wip/frame-synchronization: 18/33] GtkScrolledWindow: use GdkPaintClock for kinetic scrolling
- From: Owen Taylor <otaylor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/frame-synchronization: 18/33] GtkScrolledWindow: use GdkPaintClock for kinetic scrolling
- Date: Tue, 4 Dec 2012 17:59:33 +0000 (UTC)
commit b90f0de68dd97d0e21b32a8be50779f7813e551e
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Tue Oct 2 19:54:15 2012 -0400
GtkScrolledWindow: use GdkPaintClock for kinetic scrolling
Use GdkPaintClock when animating scrolling via touch, rather
than a timeout.
https://bugzilla.gnome.org/show_bug.cgi?id=685460
gtk/gtkscrolledwindow.c | 39 +++++++++++++++++++++++----------------
1 files changed, 23 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index b7cc9c1..0b63c2c 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -126,7 +126,6 @@
#define TOUCH_BYPASS_CAPTURED_THRESHOLD 30
/* Kinetic scrolling */
-#define FRAME_INTERVAL (1000 / 60)
#define MAX_OVERSHOOT_DISTANCE 50
#define FRICTION_DECELERATION 0.003
#define OVERSHOOT_INVERSE_ACCELERATION 0.003
@@ -287,6 +286,8 @@ static gboolean _gtk_scrolled_window_set_adjustment_value (GtkScrolledWindo
gboolean allow_overshooting,
gboolean snap_to_border);
+static void gtk_scrolled_window_cancel_deceleration (GtkScrolledWindow *scrolled_window);
+
static guint signals[LAST_SIGNAL] = {0};
G_DEFINE_TYPE (GtkScrolledWindow, gtk_scrolled_window, GTK_TYPE_BIN)
@@ -2391,10 +2392,10 @@ _gtk_scrolled_window_set_adjustment_value (GtkScrolledWindow *scrolled_window,
return (*prev_value != value);
}
-static gboolean
-scrolled_window_deceleration_cb (gpointer user_data)
+static void
+scrolled_window_deceleration_cb (GdkPaintClock *paint_clock,
+ KineticScrollData *data)
{
- KineticScrollData *data = user_data;
GtkScrolledWindow *scrolled_window = data->scrolled_window;
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkAdjustment *hadjustment, *vadjustment;
@@ -2409,7 +2410,7 @@ scrolled_window_deceleration_cb (gpointer user_data)
_gtk_scrolled_window_get_overshoot (scrolled_window,
&old_overshoot_x, &old_overshoot_y);
- current_time = g_get_monotonic_time ();
+ current_time = gdk_paint_clock_get_frame_time (paint_clock);
elapsed = (current_time - data->last_deceleration_time) / 1000;
data->last_deceleration_time = current_time;
@@ -2503,12 +2504,9 @@ scrolled_window_deceleration_cb (gpointer user_data)
if (overshoot_x != 0 || overshoot_y != 0 ||
data->x_velocity != 0 || data->y_velocity != 0)
- return TRUE;
+ gdk_paint_clock_request_phase (paint_clock, GDK_PAINT_CLOCK_PHASE_UPDATE);
else
- {
- priv->deceleration_id = 0;
- return FALSE;
- }
+ gtk_scrolled_window_cancel_deceleration (scrolled_window);
}
static void
@@ -2518,7 +2516,11 @@ gtk_scrolled_window_cancel_deceleration (GtkScrolledWindow *scrolled_window)
if (priv->deceleration_id)
{
- g_source_remove (priv->deceleration_id);
+ GdkPaintClock *paint_clock;
+
+ paint_clock = gtk_widget_get_paint_clock (GTK_WIDGET (scrolled_window));
+ g_signal_handler_disconnect (paint_clock,
+ priv->deceleration_id);
priv->deceleration_id = 0;
}
}
@@ -2527,12 +2529,15 @@ static void
gtk_scrolled_window_start_deceleration (GtkScrolledWindow *scrolled_window)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
+ GdkPaintClock *paint_clock;
KineticScrollData *data;
gdouble angle;
+ paint_clock = gtk_widget_get_paint_clock (GTK_WIDGET (scrolled_window));
+
data = g_new0 (KineticScrollData, 1);
data->scrolled_window = scrolled_window;
- data->last_deceleration_time = g_get_monotonic_time ();
+ data->last_deceleration_time = gdk_paint_clock_get_frame_time (paint_clock);
data->x_velocity = priv->x_velocity;
data->y_velocity = priv->y_velocity;
@@ -2544,10 +2549,12 @@ gtk_scrolled_window_start_deceleration (GtkScrolledWindow *scrolled_window)
data->vel_sine = sin (angle);
scrolled_window->priv->deceleration_id =
- gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT,
- FRAME_INTERVAL,
- scrolled_window_deceleration_cb,
- data, (GDestroyNotify) g_free);
+ g_signal_connect_data (paint_clock, "update",
+ G_CALLBACK (scrolled_window_deceleration_cb),
+ data,
+ (GClosureNotify) g_free,
+ 0);
+ gdk_paint_clock_request_phase (paint_clock, GDK_PAINT_CLOCK_PHASE_UPDATE);
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]