[grits] Queue mouse events and process them during expose



commit 536c4ae84ecb423286423bd62bce106dc4a0072d
Author: Andy Spencer <andy753421 gmail com>
Date:   Thu Dec 13 17:10:14 2012 +0000

    Queue mouse events and process them during expose
    
    Previously mouse events would get stacked up and prevent screen
    updating. This only saves the most recent event and skips the rest.
    
    It also forces a redraw after running picking which leads to a much
    more responsive display.

 src/grits-opengl.c |   18 +++++++++++++++---
 src/grits-opengl.h |    1 +
 2 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/src/grits-opengl.c b/src/grits-opengl.c
index a6eb92c..b2dca5e 100644
--- a/src/grits-opengl.c
+++ b/src/grits-opengl.c
@@ -216,7 +216,7 @@ static gint run_picking(GritsOpenGL *opengl, GdkEvent *event,
 	return hits;
 }
 
-static gboolean on_motion_notify(GritsOpenGL *opengl, GdkEventMotion *event, gpointer _)
+static gboolean run_mouse_move(GritsOpenGL *opengl, GdkEventMotion *event)
 {
 	gdouble height = GTK_WIDGET(opengl)->allocation.height;
 	gdouble gl_x   = event->x;
@@ -265,7 +265,7 @@ static gboolean on_motion_notify(GritsOpenGL *opengl, GdkEventMotion *event, gpo
 	GdkCursor *topcursor = top && top->cursor ? top->cursor : cursor;
 	gdk_window_set_cursor(window, topcursor);
 
-	g_debug("GritsOpenGL: on_motion_notify - hits=%d/%d,%d/%d ev=%.0lf,%.0lf",
+	g_debug("GritsOpenGL: run_mouse_move - hits=%d/%d,%d/%d ev=%.0lf,%.0lf",
 			world_hits, world->len, ortho_hits, ortho->len, gl_x, gl_y);
 
 	g_ptr_array_free(world, TRUE);
@@ -289,6 +289,13 @@ static gboolean on_motion_notify(GritsOpenGL *opengl, GdkEventMotion *event, gpo
 	return FALSE;
 }
 
+static gboolean on_motion_notify(GritsOpenGL *opengl, GdkEventMotion *event, gpointer _)
+{
+	opengl->mouse_queue = *event;
+	gtk_widget_queue_draw(GTK_WIDGET(opengl));
+	return FALSE;
+}
+
 static void _draw_level(gpointer _level, gpointer _opengl)
 {
 	GritsOpenGL *opengl = _opengl;
@@ -353,7 +360,12 @@ static gboolean on_expose(GritsOpenGL *opengl, GdkEventExpose *event, gpointer _
 	g_debug("GritsOpenGL: on_expose - begin");
 
 	if (opengl->pickmode)
-		return on_motion_notify(opengl, (GdkEventMotion*)event, NULL);
+		return run_mouse_move(opengl, (GdkEventMotion*)event);
+
+	if (opengl->mouse_queue.type != GDK_NOTHING) {
+		run_mouse_move(opengl, &opengl->mouse_queue);
+		opengl->mouse_queue.type = GDK_NOTHING;
+	}
 
 	gtk_gl_begin(GTK_WIDGET(opengl));
 
diff --git a/src/grits-opengl.h b/src/grits-opengl.h
index 3e95b00..4fb48bc 100644
--- a/src/grits-opengl.h
+++ b/src/grits-opengl.h
@@ -44,6 +44,7 @@ struct _GritsOpenGL {
 	GMutex      sphere_lock;
 	guint       sm_source[2];
 	guint       ue_source;
+	GdkEventMotion mouse_queue;
 
 	/* for testing */
 	gboolean    wireframe;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]