Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion cpufreq/data/cpufreq-preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,47 @@
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_bottom">6</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="prefs_decimal_places_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_start">18</property>
<property name="label" translatable="yes">_Decimal places:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">prefs_decimal_places</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="prefs_decimal_places">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="prefs_show_perc">
<property name="label" translatable="yes">Show CPU frequency as _percentage</property>
Expand All @@ -242,7 +283,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
<property name="position">4</property>
</packing>
</child>
</object>
Expand Down
9 changes: 8 additions & 1 deletion cpufreq/data/org.mate.panel.applet.cpufreq.gschema.xml.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<schemalist gettext-domain="@GETTEXT_PACKAGE@">
<schema id="org.mate.panel.applet.cpufreq">
<schema id="org.mate.panel.applet.cpufreq" path="/org/mate/panel/applet/cpufreq/">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change. You're forcing the applet to be non-relocatable and forces all instances of the applet to share the same settings.

<key name="cpu" type="i">
<default>0</default>
<summary>CPU to Monitor</summary>
Expand All @@ -16,5 +16,12 @@
<summary>The type of text to display (if the text is enabled).</summary>
<description>A 0 value means to show CPU frequency, 1 to show frequency and units, and 2 to show percentage instead of frequency.</description>
</key>
<key name="decimal-places" type="i">
<default>2</default>
<summary>Decimal places for frequency display</summary>
<description>
How many decimal digits to display for the CPU frequency.
</description>
</key>
</schema>
</schemalist>
21 changes: 19 additions & 2 deletions cpufreq/src/cpufreq-applet.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,15 +630,16 @@ cpufreq_applet_update (CPUFreqApplet *applet,
gint freq;
gint perc;
guint cpu;
guint decimal_places;
GtkRequisition req;
const gchar *governor;

cpu = cpufreq_monitor_get_cpu (monitor);
freq = cpufreq_monitor_get_frequency (monitor);
perc = cpufreq_monitor_get_percentage (monitor);
governor = cpufreq_monitor_get_governor (monitor);

freq_label = cpufreq_utils_get_frequency_label (freq);
decimal_places = cpufreq_monitor_get_decimal_places (monitor);
freq_label = cpufreq_utils_get_frequency_label (freq, decimal_places);
unit_label = cpufreq_utils_get_frequency_unit (freq);

if (applet->show_freq) {
Expand Down Expand Up @@ -678,6 +679,7 @@ cpufreq_applet_update (CPUFreqApplet *applet,

gov_text = g_strdup (governor);
gov_text[0] = g_ascii_toupper (gov_text[0]);
freq_label = cpufreq_utils_get_frequency_label (freq, MAX_DECIMAL_PLACES); // show max decimals in tooltip
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're overriding freq_label without freeing it first, thus leaking memory.

text_mode = g_strdup_printf ("%s\n%s %s (%d%%)",
gov_text, freq_label,
unit_label, perc);
Expand Down Expand Up @@ -780,6 +782,15 @@ cpufreq_applet_prefs_show_mode_changed (CPUFreqPrefs *prefs,
cpufreq_applet_update_visibility (applet);
}

static void
cpufreq_applet_prefs_decimal_places_changed (CPUFreqPrefs *prefs,
GParamSpec *arg1,
CPUFreqApplet *applet)
{
cpufreq_monitor_set_decimal_places (applet->monitor,
cpufreq_prefs_get_decimal_places (applet->prefs));
}

static void
cpufreq_applet_setup (CPUFreqApplet *applet)
{
Expand Down Expand Up @@ -812,10 +823,16 @@ cpufreq_applet_setup (CPUFreqApplet *applet)
G_CALLBACK (cpufreq_applet_prefs_show_mode_changed),
applet);

g_signal_connect (applet->prefs, "notify::decimal-places",
G_CALLBACK (cpufreq_applet_prefs_decimal_places_changed),
applet);

/* Monitor */
applet->monitor =
cpufreq_monitor_factory_create_monitor (cpufreq_prefs_get_cpu (applet->prefs));

cpufreq_monitor_set_decimal_places (applet->monitor,
cpufreq_prefs_get_decimal_places (applet->prefs));
cpufreq_monitor_run (applet->monitor);

g_signal_connect_swapped (applet->monitor, "changed",
Expand Down
44 changes: 43 additions & 1 deletion cpufreq/src/cpufreq-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Authors : Carlos García Campos <carlosgc@gnome.org>
*/

#include "cpufreq-utils.h"
#include "cpufreq-monitor.h"

#define CPUFREQ_MONITOR_INTERVAL 1
Expand All @@ -30,7 +31,8 @@ enum {
PROP_ONLINE,
PROP_FREQUENCY,
PROP_MAX_FREQUENCY,
PROP_GOVERNOR
PROP_GOVERNOR,
PROP_DECIMAL_PLACES
};

/* Signals */
Expand All @@ -44,6 +46,7 @@ struct _CPUFreqMonitorPrivate {
gboolean online;
gint cur_freq;
gint max_freq;
gint decimal_places;
gchar *governor;
GList *available_freqs;
GList *available_govs;
Expand Down Expand Up @@ -129,6 +132,16 @@ cpufreq_monitor_class_init (CPUFreqMonitorClass *klass)
G_MAXINT,
0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_DECIMAL_PLACES,
g_param_spec_int ("decimal-places",
"Decimal Places",
"The number of decimal places to show for the cpu frequency",
0,
MAX_DECIMAL_PLACES,
MAX_DECIMAL_PLACES,
G_PARAM_CONSTRUCT |
G_PARAM_READWRITE));
Comment on lines +135 to +144
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't belong here. Decimal places is a display concern, but this refers to the CPU frequency monitor, which is a hardware monitoring abstraction.

g_object_class_install_property (object_class,
PROP_GOVERNOR,
g_param_spec_string ("governor",
Expand Down Expand Up @@ -222,6 +235,15 @@ cpufreq_monitor_set_property (GObject *object,
}
break;
}
case PROP_DECIMAL_PLACES: {
gint decimal_places = g_value_get_int (value);

if (decimal_places != monitor->priv->decimal_places) {
monitor->priv->decimal_places = decimal_places;
monitor->priv->changed = TRUE;
}
break;
}
case PROP_GOVERNOR: {
const gchar *gov = g_value_get_string (value);

Expand Down Expand Up @@ -265,6 +287,9 @@ cpufreq_monitor_get_property (GObject *object,
case PROP_MAX_FREQUENCY:
g_value_set_int (value, monitor->priv->max_freq);
break;
case PROP_DECIMAL_PLACES:
g_value_set_int (value, monitor->priv->decimal_places);
break;
case PROP_GOVERNOR:
g_value_set_string (value, monitor->priv->governor);
break;
Expand Down Expand Up @@ -393,3 +418,20 @@ cpufreq_monitor_get_percentage (CPUFreqMonitor *monitor)

return -1;
}

gint
cpufreq_monitor_get_decimal_places (CPUFreqMonitor *monitor)
{
g_return_val_if_fail (CPUFREQ_IS_MONITOR (monitor), -1);

return monitor->priv->decimal_places;
}

void
cpufreq_monitor_set_decimal_places (CPUFreqMonitor *monitor, gint decimal_places)
{
g_return_if_fail (CPUFREQ_IS_MONITOR (monitor));

g_object_set (G_OBJECT (monitor),
"decimal-places", decimal_places, NULL);
}
2 changes: 2 additions & 0 deletions cpufreq/src/cpufreq-monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ void cpufreq_monitor_set_cpu (CPUFreqMonitor *monitor,
const gchar *cpufreq_monitor_get_governor (CPUFreqMonitor *monitor);
gint cpufreq_monitor_get_frequency (CPUFreqMonitor *monitor);
gint cpufreq_monitor_get_percentage (CPUFreqMonitor *monitor);
gint cpufreq_monitor_get_decimal_places (CPUFreqMonitor *monitor);
void cpufreq_monitor_set_decimal_places (CPUFreqMonitor *monitor, gint decimal_places);

G_END_DECLS

Expand Down
5 changes: 4 additions & 1 deletion cpufreq/src/cpufreq-popup.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,14 @@ frequencies_menu_create_actions (CPUFreqPopup *popup)
gchar *label;
gchar *unit;
gint freq;
gint decimal_places = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded value ignores the gsettings entirely.


text = (const gchar *) available_freqs->data;
freq = atoi (text);

freq_text = cpufreq_utils_get_frequency_label (freq);
// decimal_places = cpufreq_monitor_get_decimal_places (popup->priv->monitor);
// ^^^ if you want the freq selector to also use the same number of decimal places as for display
Comment on lines +281 to +282
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this? You should probably remove it.

freq_text = cpufreq_utils_get_frequency_label (freq, decimal_places);
unit = cpufreq_utils_get_frequency_unit (freq);

label = g_strdup_printf ("%s %s", freq_text, unit);
Expand Down
Loading