diff options
Diffstat (limited to 'multiload/load-graph.c')
-rw-r--r-- | multiload/load-graph.c | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/multiload/load-graph.c b/multiload/load-graph.c index a17d604a..ec14156e 100644 --- a/multiload/load-graph.c +++ b/multiload/load-graph.c @@ -50,18 +50,33 @@ load_graph_draw (LoadGraph *g) { GtkStyle *style; guint i, j; +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_t *cr; +#endif /* we might get called before the configure event so that * g->disp->allocation may not have the correct size * (after the user resized the applet in the prop dialog). */ +#if GTK_CHECK_VERSION (3, 0, 0) + if (!g->surface) + g->surface = gdk_window_create_similar_surface (gtk_widget_get_window (g->disp), + CAIRO_CONTENT_COLOR, + g->draw_width, g->draw_height); +#else if (!g->pixmap) g->pixmap = gdk_pixmap_new (gtk_widget_get_window (g->disp), g->draw_width, g->draw_height, gtk_widget_get_visual (g->disp)->depth); - +#endif + style = gtk_widget_get_style (g->disp); +#if GTK_CHECK_VERSION (3, 0, 0) + cr = cairo_create (g->surface); + cairo_set_line_width (cr, 1.0); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); +#else /* Create GC if necessary. */ if (!g->gc) { @@ -89,27 +104,43 @@ load_graph_draw (LoadGraph *g) TRUE, 0, 0, g->draw_width, g->draw_height); +#endif for (i = 0; i < g->draw_width; i++) g->pos [i] = g->draw_height - 1; for (j = 0; j < g->n; j++) { +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_color (cr, &(g->colors [j])); +#else gdk_gc_set_foreground (g->gc, &(g->colors [j])); +#endif for (i = 0; i < g->draw_width; i++) { if (g->data [i][j] != 0) { +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_move_to (cr, g->draw_width - i - 0.5, g->pos[i] + 0.5); + cairo_line_to (cr, g->draw_width - i - 0.5, g->pos[i] - (g->data [i][j] - 0.5)); +#else gdk_draw_line (g->pixmap, g->gc, g->draw_width - i - 1, g->pos[i], g->draw_width - i - 1, g->pos[i] - (g->data [i][j] - 1)); +#endif g->pos [i] -= g->data [i][j]; } } +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_stroke (cr); +#endif } - + +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_queue_draw (g->disp); +#else gdk_draw_drawable (gtk_widget_get_window (g->disp), style->fg_gc [gtk_widget_get_state (g->disp)], g->pixmap, @@ -117,6 +148,7 @@ load_graph_draw (LoadGraph *g) 0, 0, g->draw_width, g->draw_height); +#endif } /* Updates the load graph when the timeout expires */ @@ -159,6 +191,12 @@ load_graph_unalloc (LoadGraph *g) g->size = g_settings_get_int(g->multiload->settings, "size"); g->size = MAX (g->size, 10); +#if GTK_CHECK_VERSION (3, 0, 0) + if (g->surface) { + cairo_surface_destroy (g->surface); + g->surface = NULL; + } +#else if (g->pixmap) { g_object_unref (g->pixmap); g->pixmap = NULL; @@ -168,6 +206,7 @@ load_graph_unalloc (LoadGraph *g) g_object_unref (g->gc); g->gc = NULL; } +#endif g->allocated = FALSE; } @@ -209,7 +248,14 @@ load_graph_configure (GtkWidget *widget, GdkEventConfigure *event, c->draw_height = MAX (c->draw_height, 1); load_graph_alloc (c); - + +#if GTK_CHECK_VERSION (3, 0, 0) + if (!c->surface) + c->surface = gdk_window_create_similar_surface (gtk_widget_get_window (c->disp), + CAIRO_CONTENT_COLOR, + c->draw_width, c->draw_height); + gtk_widget_queue_draw (widget); +#else if (!c->pixmap) c->pixmap = gdk_pixmap_new (gtk_widget_get_window (c->disp), c->draw_width, @@ -228,22 +274,33 @@ load_graph_configure (GtkWidget *widget, GdkEventConfigure *event, 0, 0, c->draw_width, c->draw_height); +#endif return TRUE; } static gint -load_graph_expose (GtkWidget *widget, GdkEventExpose *event, +load_graph_expose (GtkWidget *widget, +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_t *cr, +#else + GdkEventExpose *event, +#endif gpointer data_ptr) { LoadGraph *g = (LoadGraph *) data_ptr; +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_set_source_surface (cr, g->surface, 0, 0); + cairo_paint (cr); +#else gdk_draw_drawable (gtk_widget_get_window (widget), (gtk_widget_get_style (widget))->fg_gc [gtk_widget_get_state (widget)], g->pixmap, event->area.x, event->area.y, event->area.x, event->area.y, event->area.width, event->area.height); +#endif return FALSE; } @@ -387,7 +444,11 @@ load_graph_new (MultiloadApplet *ma, guint n, const gchar *label, GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK); +#if GTK_CHECK_VERSION (3, 0, 0) + g_signal_connect (G_OBJECT (g->disp), "draw", +#else g_signal_connect (G_OBJECT (g->disp), "expose_event", +#endif G_CALLBACK (load_graph_expose), g); g_signal_connect (G_OBJECT(g->disp), "configure_event", G_CALLBACK (load_graph_configure), g); |