-
-
Notifications
You must be signed in to change notification settings - Fork 65
Allow user selection of decimal places for cpu freq #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're overriding |
||
| text_mode = g_strdup_printf ("%s\n%s %s (%d%%)", | ||
| gov_text, freq_label, | ||
| unit_label, perc); | ||
|
|
@@ -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) | ||
| { | ||
|
|
@@ -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", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -30,7 +31,8 @@ enum { | |
| PROP_ONLINE, | ||
| PROP_FREQUENCY, | ||
| PROP_MAX_FREQUENCY, | ||
| PROP_GOVERNOR | ||
| PROP_GOVERNOR, | ||
| PROP_DECIMAL_PLACES | ||
| }; | ||
|
|
||
| /* Signals */ | ||
|
|
@@ -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; | ||
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
|
@@ -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); | ||
|
|
||
|
|
@@ -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; | ||
|
|
@@ -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); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -273,11 +273,14 @@ frequencies_menu_create_actions (CPUFreqPopup *popup) | |
| gchar *label; | ||
| gchar *unit; | ||
| gint freq; | ||
| gint decimal_places = 2; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
|
||
There was a problem hiding this comment.
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.