[gnome-applets] cpufreq: fix max_label_width calculation



commit 0ce81d53586f15ae73516902283600521bee0922
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Mar 12 21:22:18 2018 +0200

    cpufreq: fix max_label_width calculation
    
    cpufreq_get_available_frequencies works only with some cpufreq
    drivers whitch means that we might not be able to calculate max
    label width.
    
    Use cpufreq_get_hardware_limits to get min and max frequencies
    to get range that we can use to calculate max width.

 cpufreq/src/cpufreq-applet.c |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)
---
diff --git a/cpufreq/src/cpufreq-applet.c b/cpufreq/src/cpufreq-applet.c
index 76e7024..dd427d6 100644
--- a/cpufreq/src/cpufreq-applet.c
+++ b/cpufreq/src/cpufreq-applet.c
@@ -352,8 +352,10 @@ get_text_width (const gchar *text)
 static gint
 cpufreq_applet_get_max_label_width (CPUFreqApplet *applet)
 {
-       GList *available_freqs;
-       gint   width = 0;
+       gulong min;
+       gulong max;
+       gulong freq;
+       gint width;
        
        if (applet->max_label_width > 0)
                return applet->max_label_width;
@@ -361,21 +363,17 @@ cpufreq_applet_get_max_label_width (CPUFreqApplet *applet)
        if (!CPUFREQ_IS_MONITOR (applet->monitor))
                return 0;
 
-       available_freqs = cpufreq_monitor_get_available_frequencies (applet->monitor);
-       while (available_freqs) {
-               const gchar   *text;
-               gchar         *freq_text;
-               gint           freq;
+       if (!cpufreq_monitor_get_hardware_limits (applet->monitor, &min, &max))
+               return 0;
 
-               text = (const gchar *) available_freqs->data;
-               freq = atoi (text);
+       width = 0;
+       for (freq = min; freq <= max; freq += 10000) {
+               gchar *freq_text;
 
                freq_text = cpufreq_utils_get_frequency_label (freq);
 
                width = MAX (width, get_text_width (freq_text));
                g_free (freq_text);
-
-               available_freqs = g_list_next (available_freqs);
        }
 
        applet->max_label_width = width;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]