]> Pileus Git - grits/commitdiff
Queue mouse events and process them during expose
authorAndy Spencer <andy753421@gmail.com>
Thu, 13 Dec 2012 17:10:14 +0000 (17:10 +0000)
committerAndy Spencer <andy753421@gmail.com>
Thu, 13 Dec 2012 17:10:14 +0000 (17:10 +0000)
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
src/grits-opengl.h

index a6eb92ca7f34126f681c6be4bd9b4f27cf513d70..b2dca5eebab5922e832625d7dc6e85a45cd3369c 100644 (file)
@@ -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));
 
index 3e95b00c82b51b4ff291d1a07c4b6c935721f8d3..4fb48bcad3fdbad7545c53bdeb0241da8c720cb7 100644 (file)
@@ -44,6 +44,7 @@ struct _GritsOpenGL {
        GMutex      sphere_lock;
        guint       sm_source[2];
        guint       ue_source;
+       GdkEventMotion mouse_queue;
 
        /* for testing */
        gboolean    wireframe;