[Xfce4-commits] [apps/xfce4-taskmanager] 03/05: Draw CPU and Mem graph in different colors

noreply at xfce.org noreply at xfce.org
Thu Dec 18 22:12:22 CET 2014


This is an automated email from the git hooks/post-receive script.

landry pushed a commit to branch master
in repository apps/xfce4-taskmanager.

commit 8b45017642d81ceacfc36da967a9cf1d6896b2d6
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Thu Dec 18 11:04:47 2014 +0100

    Draw CPU and Mem graph in different colors
---
 src/process-monitor.c      |   31 ++++++++++++++++++++++++++++---
 src/process-monitor.h      |    1 +
 src/process-window-gtk3.ui |    4 ++--
 src/process-window.c       |    6 ++++--
 src/process-window.ui      |    4 ++--
 5 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/src/process-monitor.c b/src/process-monitor.c
index 00b77e0..437dd88 100644
--- a/src/process-monitor.c
+++ b/src/process-monitor.c
@@ -21,6 +21,7 @@
 enum
 {
 	PROP_STEP_SIZE = 1,
+	PROP_TYPE,
 };
 typedef struct _XtmProcessMonitorClass XtmProcessMonitorClass;
 struct _XtmProcessMonitorClass
@@ -32,6 +33,7 @@ struct _XtmProcessMonitor
 	GtkDrawingArea		parent;
 	/*<private>*/
 	gfloat			step_size;
+	gint			type;
 	GArray *		history;
 };
 G_DEFINE_TYPE (XtmProcessMonitor, xtm_process_monitor, GTK_TYPE_DRAWING_AREA)
@@ -62,6 +64,8 @@ xtm_process_monitor_class_init (XtmProcessMonitorClass *klass)
 #endif
 	g_object_class_install_property (class, PROP_STEP_SIZE,
 		g_param_spec_float ("step-size", "StepSize", "Step size", 0.1, G_MAXFLOAT, 1, G_PARAM_CONSTRUCT|G_PARAM_READWRITE));
+	g_object_class_install_property (class, PROP_TYPE,
+		g_param_spec_int ("type", "Type", "Type of graph to render", 0, G_MAXINT, 0, G_PARAM_READWRITE));
 }
 
 static void
@@ -80,6 +84,10 @@ xtm_process_monitor_get_property (GObject *object, guint property_id, GValue *va
 		g_value_set_float (value, monitor->step_size);
 		break;
 
+		case PROP_TYPE:
+		g_value_set_int (value, monitor->type);
+		break;
+
 		default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 		break;
@@ -96,6 +104,10 @@ xtm_process_monitor_set_property (GObject *object, guint property_id, const GVal
 		monitor->step_size = g_value_get_float (value);
 		break;
 
+		case PROP_TYPE:
+		monitor->type = g_value_get_int (value);
+		break;
+
 		default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 		break;
@@ -154,8 +166,11 @@ xtm_process_monitor_graph_surface_create (XtmProcessMonitor *monitor, gint width
 	graph_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
 	cr = cairo_create (graph_surface);
 
-	/* Draw area below the line */
-	cairo_set_source_rgba (cr, 1.0, 0.43, 0.0, 0.3);
+	/* Draw area below the line, distinguish between CPU (0) and Mem (1) color-wise */
+	if (monitor->type == 0)
+		cairo_set_source_rgba (cr, 1.0, 0.43, 0.0, 0.3);
+	else
+		cairo_set_source_rgba (cr, 0.67, 0.09, 0.32, 0.3);
 	cairo_set_line_width (cr, 0.0);
 	cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT);
 
@@ -173,7 +188,10 @@ xtm_process_monitor_graph_surface_create (XtmProcessMonitor *monitor, gint width
 	/* Draw line */
 	cairo_translate (cr, step_size * i, 0);
 
-	cairo_set_source_rgba (cr, 1.0, 0.43, 0.0, 1.0);
+	if (monitor->type == 0)
+		cairo_set_source_rgba (cr, 1.0, 0.43, 0.0, 1.0);
+	else
+		cairo_set_source_rgba (cr, 0.67, 0.09, 0.32, 1.0);
 	cairo_set_line_width (cr, 0.85);
 	cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
 	cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
@@ -266,6 +284,13 @@ xtm_process_monitor_set_step_size (XtmProcessMonitor *monitor, gfloat step_size)
 }
 
 void
+xtm_process_monitor_set_type (XtmProcessMonitor *monitor, gint type)
+{
+	g_return_if_fail (XTM_IS_PROCESS_MONITOR (monitor));
+	g_object_set (monitor, "type", type, NULL);
+}
+
+void
 xtm_process_monitor_clear (XtmProcessMonitor *monitor)
 {
 	g_return_if_fail (XTM_IS_PROCESS_MONITOR (monitor));
diff --git a/src/process-monitor.h b/src/process-monitor.h
index 7d84bbd..06ccc12 100644
--- a/src/process-monitor.h
+++ b/src/process-monitor.h
@@ -29,6 +29,7 @@ GType		xtm_process_monitor_get_type			(void);
 GtkWidget *	xtm_process_monitor_new				(void);
 void		xtm_process_monitor_add_peak			(XtmProcessMonitor *monitor, gfloat peak);
 void		xtm_process_monitor_set_step_size		(XtmProcessMonitor *monitor, gfloat step_size);
+void		xtm_process_monitor_set_type			(XtmProcessMonitor *monitor, gint type);
 void		xtm_process_monitor_clear			(XtmProcessMonitor *monitor);
 
 #endif /* !PROCESS_MONITOR_H */
diff --git a/src/process-window-gtk3.ui b/src/process-window-gtk3.ui
index 36cf17a..67a8dd1 100644
--- a/src/process-window-gtk3.ui
+++ b/src/process-window-gtk3.ui
@@ -81,7 +81,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <child>
-                  <object class="GtkFrame" id="cpu-toolitem">
+                  <object class="GtkFrame" id="graph-cpu">
                     <property name="height_request">100</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
@@ -104,7 +104,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkFrame" id="mem-toolitem">
+                  <object class="GtkFrame" id="graph-mem">
                     <property name="height_request">100</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
diff --git a/src/process-window.c b/src/process-window.c
index 1df538c..91cb71e 100644
--- a/src/process-window.c
+++ b/src/process-window.c
@@ -149,15 +149,17 @@ xtm_process_window_init (XtmProcessWindow *window)
 
 		g_object_get (window->settings, "refresh-rate", &refresh_rate, NULL);
 
-		toolitem = GTK_WIDGET (gtk_builder_get_object (window->builder, "cpu-toolitem"));
+		toolitem = GTK_WIDGET (gtk_builder_get_object (window->builder, "graph-cpu"));
 		window->cpu_monitor = xtm_process_monitor_new ();
 		xtm_process_monitor_set_step_size (XTM_PROCESS_MONITOR (window->cpu_monitor), refresh_rate / 1000.0);
+		xtm_process_monitor_set_type (XTM_PROCESS_MONITOR (window->cpu_monitor), 0);
 		gtk_widget_show (window->cpu_monitor);
 		gtk_container_add (GTK_CONTAINER (toolitem), window->cpu_monitor);
 
-		toolitem = GTK_WIDGET (gtk_builder_get_object (window->builder, "mem-toolitem"));
+		toolitem = GTK_WIDGET (gtk_builder_get_object (window->builder, "graph-mem"));
 		window->mem_monitor = xtm_process_monitor_new ();
 		xtm_process_monitor_set_step_size (XTM_PROCESS_MONITOR (window->mem_monitor), refresh_rate / 1000.0);
+		xtm_process_monitor_set_type (XTM_PROCESS_MONITOR (window->mem_monitor), 1);
 		gtk_widget_show (window->mem_monitor);
 		gtk_container_add (GTK_CONTAINER (toolitem), window->mem_monitor);
 
diff --git a/src/process-window.ui b/src/process-window.ui
index 7fdacad..f19fb31 100644
--- a/src/process-window.ui
+++ b/src/process-window.ui
@@ -81,7 +81,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <child>
-                  <object class="GtkToolItem" id="cpu-toolitem">
+                  <object class="GtkToolItem" id="graph-cpu">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="border_width">2</property>
@@ -97,7 +97,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkToolItem" id="mem-toolitem">
+                  <object class="GtkToolItem" id="graph-mem">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="border_width">2</property>

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list