]> Pileus Git - grits/commitdiff
Fix key-press in GritsTest
authorAndy Spencer <andy753421@gmail.com>
Sat, 11 Feb 2012 06:16:07 +0000 (06:16 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sun, 12 Feb 2012 07:00:20 +0000 (07:00 +0000)
Some key events are > 256 which caused an array index out of bounds.

src/plugins/test.c

index ae62a7d4b42ba9be98d5b690b70b20ad76e2f557..a83cd374a84cb0ee2d92e642dc1065e0c33d410f 100644 (file)
 
 static void on_poly_enter(GritsPoly *poly)
 {
-       g_debug("on_poly_enter");
+       g_debug("GritsPluginTest: on_poly_enter");
        poly->color[3] = 0.50;
        grits_object_queue_draw(GRITS_OBJECT(poly));
 }
 
 static void on_poly_leave(GritsPoly *poly)
 {
-       g_debug("on_poly_leave");
+       g_debug("GritsPluginTest: on_poly_leave");
        poly->color[3] = 0.2;
        grits_object_queue_draw(GRITS_OBJECT(poly));
 }
 
 static void on_poly_button(GritsPoly *poly, GdkEventButton *event)
 {
-       g_debug("on_poly_button");
+       g_debug("GritsPluginTest: on_poly_button");
        static int i = 0;
        gdouble colors[][3] = {
                {1, 0, 0}, {1, 1, 0},
@@ -60,12 +60,14 @@ static void on_poly_button(GritsPoly *poly, GdkEventButton *event)
 
 static void on_poly_key(GritsPoly *poly, GdkEventKey *event)
 {
-       g_debug("on_poly_key");
+       g_debug("GritsPluginTest: on_poly_key - %d", event->keyval);
        gdouble colors[0xff][3] = {
                [GDK_r] {1, 0, 0},
                [GDK_g] {0, 1, 0},
                [GDK_b] {0, 0, 1},
        };
+       if (event->keyval >= G_N_ELEMENTS(colors))
+               return;
        int key = event->keyval;
        memcpy(poly->color, colors[key], sizeof(gdouble)*3);
        grits_object_queue_draw(GRITS_OBJECT(poly));
@@ -73,7 +75,7 @@ static void on_poly_key(GritsPoly *poly, GdkEventKey *event)
 
 static void on_marker_enter(GritsMarker *marker, GritsViewer *viewer)
 {
-       g_debug("on_marker_enter");
+       g_debug("GritsPluginTest: on_marker_enter");
        GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(viewer));
        GdkCursor *cursor = gdk_cursor_new(GDK_HAND1);
        gdk_window_set_cursor(window, cursor);
@@ -81,14 +83,14 @@ static void on_marker_enter(GritsMarker *marker, GritsViewer *viewer)
 
 static void on_marker_leave(GritsMarker *marker, GritsViewer *viewer)
 {
-       g_debug("on_marker_leave");
+       g_debug("GritsPluginTest: on_marker_leave");
        GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(viewer));
        gdk_window_set_cursor(window, NULL);
 }
 
 static void on_marker_button(GritsMarker *marker, GdkEventButton *event)
 {
-       g_debug("on_marker_button");
+       g_debug("GritsPluginTest: on_marker_button");
        GtkWidget *dialog = gtk_dialog_new_with_buttons(
                        "St. Charles!", NULL, 0, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
        gtk_dialog_run(GTK_DIALOG(dialog));