[Xfce4-commits] <xfce4-cpufreq-plugin:master> Add min, avg and max frequencies options.

Harald Judt noreply at xfce.org
Sun Aug 18 11:32:30 CEST 2013


Updating branch refs/heads/master
         to 41af8d0c4fc3a83d0578b337f73d8d1a7db77ab1 (commit)
       from 3db6c5ebd7161bc71354522f5703607902b9b2fd (commit)

commit 41af8d0c4fc3a83d0578b337f73d8d1a7db77ab1
Author: Harald Judt <h.judt at gmx.at>
Date:   Sun Aug 18 01:03:28 2013 +0200

    Add min, avg and max frequencies options.
    
    The CPU combo box now allows to select three options besides the real CPUs.
    These are calculated values over the current frequencies of the CPUs.
    
    According to the i7z tool, the max frequency is supposed to be the real
    current frequency when using the intel pstate driver.

 panel-plugin/xfce4-cpufreq-configure.c |    3 ++
 panel-plugin/xfce4-cpufreq-plugin.c    |   80 ++++++++++++++++++++++++++++++--
 panel-plugin/xfce4-cpufreq-plugin.h    |    9 ++++
 3 files changed, 88 insertions(+), 4 deletions(-)

diff --git a/panel-plugin/xfce4-cpufreq-configure.c b/panel-plugin/xfce4-cpufreq-configure.c
index cd8e3f7..f7172d0 100644
--- a/panel-plugin/xfce4-cpufreq-configure.c
+++ b/panel-plugin/xfce4-cpufreq-configure.c
@@ -281,6 +281,9 @@ cpufreq_configure (XfcePanelPlugin *plugin)
 		gtk_combo_box_append_text (GTK_COMBO_BOX (combo), cpu_name);
 		g_free (cpu_name);
 	}
+	gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("min"));
+	gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("avg"));
+	gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("max"));
 
 	gtk_combo_box_set_active (GTK_COMBO_BOX (combo), cpuFreq->options->show_cpu);
 	g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (combo_changed), configure);
diff --git a/panel-plugin/xfce4-cpufreq-plugin.c b/panel-plugin/xfce4-cpufreq-plugin.c
index 32abdc2..0474f74 100644
--- a/panel-plugin/xfce4-cpufreq-plugin.c
+++ b/panel-plugin/xfce4-cpufreq-plugin.c
@@ -40,6 +40,63 @@
 #include "xfce4-cpufreq-overview.h"
 #include "xfce4-cpufreq-utils.h"
 
+
+CpuInfo *
+cpufreq_cpus_calc_min (void)
+{
+	guint freq = 0;
+	gint i;
+
+	for (i = 0; i < cpuFreq->cpus->len; i++) {
+		CpuInfo *cpu = g_ptr_array_index (cpuFreq->cpus, i);
+		if (freq > cpu->cur_freq || i == 0)
+			freq = cpu->cur_freq;
+	}
+
+	cpuinfo_free (cpuFreq->cpu_min);
+	cpuFreq->cpu_min = g_new0 (CpuInfo, 1);
+	cpuFreq->cpu_min->cur_freq = freq;
+	cpuFreq->cpu_min->cur_governor = g_strdup (_("current min"));
+	return cpuFreq->cpu_min;
+}
+
+CpuInfo *
+cpufreq_cpus_calc_avg (void)
+{
+	guint freq = 0;
+	gint i;
+
+	for (i = 0; i < cpuFreq->cpus->len; i++) {
+		CpuInfo *cpu = g_ptr_array_index (cpuFreq->cpus, i);
+		freq += cpu->cur_freq;
+	}
+
+	freq /= cpuFreq->cpus->len;
+	cpuinfo_free (cpuFreq->cpu_avg);
+	cpuFreq->cpu_avg = g_new0 (CpuInfo, 1);
+	cpuFreq->cpu_avg->cur_freq = freq;
+	cpuFreq->cpu_avg->cur_governor = g_strdup (_("current avg"));
+	return cpuFreq->cpu_avg;
+}
+
+CpuInfo *
+cpufreq_cpus_calc_max (void)
+{
+	guint freq = 0;
+	gint i;
+
+	for (i = 0; i < cpuFreq->cpus->len; i++) {
+		CpuInfo *cpu = g_ptr_array_index (cpuFreq->cpus, i);
+		if (freq < cpu->cur_freq)
+			freq = cpu->cur_freq;
+	}
+	cpuinfo_free (cpuFreq->cpu_max);
+	cpuFreq->cpu_max = g_new0 (CpuInfo, 1);
+	cpuFreq->cpu_max->cur_freq = freq;
+	cpuFreq->cpu_max->cur_governor = g_strdup (_("current max"));
+	return cpuFreq->cpu_max;
+}
+
 void
 cpufreq_label_set_font (void)
 {
@@ -238,15 +295,28 @@ cpufreq_widgets_layout (void)
 	cpuFreq->layout_changed = FALSE;
 }
 
+CpuInfo *
+cpufreq_current_cpu ()
+{
+	CpuInfo *cpu = NULL;
+	if (cpuFreq->options->show_cpu < cpuFreq->cpus->len)
+		cpu = g_ptr_array_index (cpuFreq->cpus, cpuFreq->options->show_cpu);
+	else if (cpuFreq->options->show_cpu == CPU_MIN)
+		cpu = cpufreq_cpus_calc_min ();
+	else if (cpuFreq->options->show_cpu == CPU_AVG)
+		cpu = cpufreq_cpus_calc_avg ();
+	else if (cpuFreq->options->show_cpu == CPU_MAX)
+		cpu = cpufreq_cpus_calc_max ();
+	return cpu;
+}
+
 gboolean
 cpufreq_update_plugin (void)
 {
 	CpuInfo *cpu;
 	gboolean ret;
 
-	g_return_val_if_fail (cpuFreq->options->show_cpu < cpuFreq->cpus->len, FALSE);
-
-	cpu = g_ptr_array_index (cpuFreq->cpus, cpuFreq->options->show_cpu);
+	cpu = cpufreq_current_cpu ();
 	ret = cpufreq_update_label (cpu);
 
 	if (cpuFreq->layout_changed) {
@@ -344,7 +414,7 @@ cpufreq_widgets (void)
 					  G_CALLBACK (cpufreq_overview), cpuFreq);
 
 	/* activate panel widget tooltip */
-	cpu = g_ptr_array_index (cpuFreq->cpus, cpuFreq->options->show_cpu);
+	cpu = cpufreq_current_cpu ();
 	g_object_set (G_OBJECT (cpuFreq->button), "has-tooltip", TRUE, NULL);
 	g_signal_connect (G_OBJECT (cpuFreq->button), "query-tooltip",
 					  G_CALLBACK (cpufreq_update_tooltip), cpu);
@@ -423,6 +493,8 @@ cpufreq_write_config (XfcePanelPlugin *plugin)
 void
 cpuinfo_free (CpuInfo *cpu)
 {
+	if (G_UNLIKELY(cpu == NULL))
+		return;
 	g_free (cpu->cur_governor);
 	g_free (cpu->scaling_driver);
 	g_list_free (cpu->available_freqs);
diff --git a/panel-plugin/xfce4-cpufreq-plugin.h b/panel-plugin/xfce4-cpufreq-plugin.h
index 995a391..9daa546 100644
--- a/panel-plugin/xfce4-cpufreq-plugin.h
+++ b/panel-plugin/xfce4-cpufreq-plugin.h
@@ -24,6 +24,10 @@
 #include <gtk/gtk.h>
 #include <libxfce4panel/xfce-panel-plugin.h>
 
+#define CPU_MIN (cpuFreq->cpus->len + 0)
+#define CPU_AVG (cpuFreq->cpus->len + 1)
+#define CPU_MAX (cpuFreq->cpus->len + 2)
+
 typedef struct
 {
 	guint  cur_freq;
@@ -63,6 +67,11 @@ typedef struct
 	/* Array with all CPUs */
 	GPtrArray *cpus;
 
+	/* Calculated values */
+	CpuInfo *cpu_min;
+	CpuInfo *cpu_avg;
+	CpuInfo *cpu_max;
+
 	/* Intel P-State parameters */
 	IntelPState *intel_pstate;
 


More information about the Xfce4-commits mailing list