added support of cpu usage monitoring
[psensor.git] / src / graph.c
index 3b70d3e..988ea4a 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2010-2011 wpitchoune@gmail.com
+    Copyright (C) 2010-2011 jeanfi@gmail.com
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -165,9 +165,9 @@ static void draw_sensor_curve(struct psensor *s,
                double v;
 
                t = s->measures[i].time.tv_sec;
-               v = s->measures[i].value;
+               v = s->measures[i].value.d_num;
 
-               if (v == UNKNOWN_VALUE || !t || (t - bt) < 0)
+               if (v == UNKNOWN_DBL_VALUE || !t || (t - bt) < 0)
                        continue;
 
                x = (t - bt) * g_width / (et - bt) + g_xoff;
@@ -201,29 +201,31 @@ graph_update(struct psensor **sensors,
        double maxt = get_max_temp(sensors);
        char *strmax = psensor_value_to_string(SENSOR_TYPE_TEMP, maxt);
 
-       int width = w_graph->allocation.width;
-       int height = w_graph->allocation.height;
-
-       int g_width, g_height;
+       int width, height, g_width, g_height;
 
        /* horizontal and vertical offset of the graph */
        int g_xoff, g_yoff;
 
-       cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
-                                                         width,
-                                                         height);
-       cairo_t *cr = cairo_create(cst);
-       cairo_t *cr_pixmap;
+       cairo_surface_t *cst;
+       cairo_t *cr, *cr_pixmap;
 
        char *str_btime = time_to_str(get_graph_begin_time_s(config));
-       cairo_text_extents_t te_btime;
-
        char *str_etime = time_to_str(get_graph_end_time_s());
-       cairo_text_extents_t te_etime;
 
-       cairo_text_extents_t te_max, te_min;
+       cairo_text_extents_t te_btime, te_etime, te_max, te_min;
 
        struct psensor **sensor_cur;
+       GtkAllocation galloc;
+
+       if (!gtk_widget_is_drawable(w_graph))
+               return ;
+
+       gtk_widget_get_allocation(w_graph, &galloc);
+       width = galloc.width;
+       height = galloc.height;
+
+       cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
+       cr = cairo_create(cst);
 
        draw_graph_background(cr, width, height, config);
 
@@ -298,6 +300,11 @@ graph_update(struct psensor **sensors,
                                if (is_fan_type(s->type)) {
                                        min = min_rpm;
                                        max = max_rpm;
+                               } else if (s->type & SENSOR_TYPE_CPU_USAGE) {
+                                       min = 0;
+                                       max = get_max_value
+                                               (sensors,
+                                                SENSOR_TYPE_CPU_USAGE);
                                } else {
                                        min = mint;
                                        max = maxt;
@@ -314,7 +321,7 @@ graph_update(struct psensor **sensors,
                }
        }
 
-       cr_pixmap = gdk_cairo_create(w_graph->window);
+       cr_pixmap = gdk_cairo_create(gtk_widget_get_window(w_graph));
 
        if (cr_pixmap) {