summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWolfgang Ulbrich <[email protected]>2016-02-03 16:33:24 +0100
committerWolfgang Ulbrich <[email protected]>2016-02-03 16:33:24 +0100
commit63adf8889dea1f36aabe215bfcf33335ef0d057d (patch)
tree2410020ad7eb10e2a1bfdb9da0f75b8f5ae13c2f /src
parente82c6352ba8bec918114df56c459f6c06b4777c2 (diff)
downloadmate-system-monitor-63adf8889dea1f36aabe215bfcf33335ef0d057d.tar.bz2
mate-system-monitor-63adf8889dea1f36aabe215bfcf33335ef0d057d.tar.xz
load-graph.cpp: Draw the background explicitly
The gdk_window_set_background_pattern() function is a little dubious to use unless you are writing GTK+ code since the background may be overridden by gtkwidget.c whenever the style of the widget changes. Needed for gtk+-3.20
Diffstat (limited to 'src')
-rw-r--r--src/load-graph.cpp22
-rw-r--r--src/load-graph.h2
2 files changed, 13 insertions, 11 deletions
diff --git a/src/load-graph.cpp b/src/load-graph.cpp
index c7b843c..6119849 100644
--- a/src/load-graph.cpp
+++ b/src/load-graph.cpp
@@ -31,7 +31,7 @@
void LoadGraph::clear_background()
{
if (background) {
- cairo_surface_destroy (background);
+ cairo_pattern_destroy (background);
this->background = NULL;
}
}
@@ -75,6 +75,7 @@ static void draw_background(LoadGraph *graph) {
PangoLayout* layout;
PangoFontDescription* font_desc;
PangoRectangle extents;
+ cairo_surface_t *surface;
GdkRGBA fg, bg;
num_bars = graph->num_bars();
@@ -84,8 +85,8 @@ static void draw_background(LoadGraph *graph) {
graph->graph_buffer_offset = (int) (1.5 * graph->graph_delx) + FRAME_WIDTH ;
gtk_widget_get_allocation (graph->disp, &allocation);
- graph->background = gdk_window_create_similar_surface (gtk_widget_get_window (graph->disp), CAIRO_CONTENT_COLOR_ALPHA, allocation.width, allocation.height);
- cr = cairo_create (graph->background);
+ surface = gdk_window_create_similar_surface (gtk_widget_get_window (graph->disp), CAIRO_CONTENT_COLOR_ALPHA, allocation.width, allocation.height);
+ cr = cairo_create (surface);
GtkStyleContext *context = gtk_widget_get_style_context (ProcData::get_instance()->notebook);
gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
@@ -175,6 +176,8 @@ static void draw_background(LoadGraph *graph) {
g_object_unref(layout);
cairo_stroke (cr);
cairo_destroy (cr);
+ graph->background = cairo_pattern_create_for_surface (surface);
+ cairo_surface_destroy (surface);
}
/* Redraws the backing buffer for the load graph and updates the window */
@@ -216,13 +219,6 @@ static gboolean load_graph_draw (GtkWidget *widget, cairo_t *context, gpointer d
window = gtk_widget_get_window (graph->disp);
- if (graph->background == NULL) {
- draw_background(graph);
- cairo_pattern_t *pattern = cairo_pattern_create_for_surface (graph->background);
- gdk_window_set_background_pattern (window, pattern);
- cairo_pattern_destroy (pattern);
- }
-
/* Number of pixels wide for one graph point */
sample_width = (float)(graph->draw_width - graph->rmargin - graph->indent) / (float)LoadGraph::NUM_POINTS;
/* General offset */
@@ -236,6 +232,12 @@ static gboolean load_graph_draw (GtkWidget *widget, cairo_t *context, gpointer d
cr = gdk_cairo_create (window);
+ if (graph->background == NULL) {
+ draw_background(graph);
+ }
+ cairo_set_source (cr, graph->background);
+ cairo_paint (cr);
+
cairo_set_line_width (cr, 1);
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
diff --git a/src/load-graph.h b/src/load-graph.h
index 6b76cb8..35bb62b 100644
--- a/src/load-graph.h
+++ b/src/load-graph.h
@@ -66,7 +66,7 @@ struct LoadGraph {
GtkWidget *main_widget;
GtkWidget *disp;
- cairo_surface_t *background;
+ cairo_pattern_t *background;
guint timer_index;