[Xfce4-commits] [panel-plugins/xfce4-cpufreq-plugin] 01/07: Format source
noreply at xfce.org
noreply at xfce.org
Fri Sep 21 15:21:37 CEST 2018
This is an automated email from the git hooks/post-receive script.
a n d r e p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository panel-plugins/xfce4-cpufreq-plugin.
commit 527dd8a3d37604f391865a63873b5e90ff6acd30
Author: Andre Miranda <andreldm at xfce.org>
Date: Tue Sep 18 22:48:42 2018 -0300
Format source
---
panel-plugin/xfce4-cpufreq-configure.c | 608 +++++++++--------
panel-plugin/xfce4-cpufreq-configure.h | 22 +-
panel-plugin/xfce4-cpufreq-linux.c | 767 +++++++++++----------
panel-plugin/xfce4-cpufreq-overview.c | 493 +++++++-------
panel-plugin/xfce4-cpufreq-plugin.c | 1175 +++++++++++++++++---------------
panel-plugin/xfce4-cpufreq-plugin.h | 78 +--
panel-plugin/xfce4-cpufreq-utils.c | 62 +-
7 files changed, 1677 insertions(+), 1528 deletions(-)
diff --git a/panel-plugin/xfce4-cpufreq-configure.c b/panel-plugin/xfce4-cpufreq-configure.c
index 7139ca5..25fea0d 100644
--- a/panel-plugin/xfce4-cpufreq-configure.c
+++ b/panel-plugin/xfce4-cpufreq-configure.c
@@ -32,341 +32,365 @@
# define _(String) gettext (String)
#endif
-static void
-check_button_changed (GtkWidget *button, CpuFreqPluginConfigure *configure);
+
static void
check_button_changed (GtkWidget *button, CpuFreqPluginConfigure *configure)
{
- if (button == configure->display_icon)
- cpuFreq->options->show_icon =
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
-
- else if (button == configure->display_freq)
- cpuFreq->options->show_label_freq =
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
-
- else if (button == configure->display_governor)
- cpuFreq->options->show_label_governor =
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
-
- else if (button == configure->keep_compact)
- cpuFreq->options->keep_compact =
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
-
- else if (button == configure->one_line)
- cpuFreq->options->one_line =
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
-
- if (!cpuFreq->options->show_label_freq &&
- !cpuFreq->options->show_label_governor) {
- if (!cpuFreq->options->show_icon)
- gtk_toggle_button_set_active
- (GTK_TOGGLE_BUTTON (configure->display_icon), TRUE);
- gtk_widget_set_sensitive (configure->display_icon, FALSE);
- } else
- gtk_widget_set_sensitive (configure->display_icon, TRUE);
-
- cpufreq_update_icon (cpuFreq);
- cpufreq_update_plugin (TRUE);
+ if (button == configure->display_icon)
+ cpuFreq->options->show_icon =
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+
+ else if (button == configure->display_freq)
+ cpuFreq->options->show_label_freq =
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+
+ else if (button == configure->display_governor)
+ cpuFreq->options->show_label_governor =
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+
+ else if (button == configure->keep_compact)
+ cpuFreq->options->keep_compact =
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+
+ else if (button == configure->one_line)
+ cpuFreq->options->one_line =
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+
+ if (!cpuFreq->options->show_label_freq && !cpuFreq->options->show_label_governor)
+ {
+ if (!cpuFreq->options->show_icon)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (configure->display_icon), TRUE);
+
+ gtk_widget_set_sensitive (configure->display_icon, FALSE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive (configure->display_icon, TRUE);
+ }
+
+ cpufreq_update_icon (cpuFreq);
+ cpufreq_update_plugin (TRUE);
}
+
+
static void
-button_fontname_update(GtkWidget *button,
- gboolean update_plugin)
+button_fontname_update(GtkWidget *button, gboolean update_plugin)
{
- if (cpuFreq->options->fontname == NULL) {
- gtk_button_set_label (GTK_BUTTON (button), _("Select font..."));
- gtk_widget_set_tooltip_text
- (button, _("Select font family and size to use for the labels."));
- } else {
- gtk_button_set_label (GTK_BUTTON (button), cpuFreq->options->fontname);
- gtk_widget_set_tooltip_text
- (button, _("Right-click to revert to the default font."));
- }
- if (update_plugin)
- cpufreq_update_plugin (TRUE);
+ if (cpuFreq->options->fontname == NULL)
+ {
+ gtk_button_set_label (GTK_BUTTON (button), _("Select font..."));
+ gtk_widget_set_tooltip_text (button, _("Select font family and size to use for the labels."));
+ }
+ else
+ {
+ gtk_button_set_label (GTK_BUTTON (button), cpuFreq->options->fontname);
+ gtk_widget_set_tooltip_text (button, _("Right-click to revert to the default font."));
+ }
+
+ if (update_plugin)
+ cpufreq_update_plugin (TRUE);
}
+
+
static gboolean
-button_fontname_clicked(GtkWidget *button,
- CpuFreqPluginConfigure *configure)
+button_fontname_clicked(GtkWidget *button, CpuFreqPluginConfigure *configure)
{
- GtkWidget *fc;
- gchar *fontname;
- gint result;
-
- fc = gtk_font_chooser_dialog_new (_("Select font"),
- GTK_WINDOW(gtk_widget_get_toplevel(button)));
-
- if (cpuFreq->options->fontname)
- gtk_font_chooser_set_font (GTK_FONT_CHOOSER (fc), cpuFreq->options->fontname);
-
- result = gtk_dialog_run(GTK_DIALOG(fc));
- if (result == GTK_RESPONSE_OK || result == GTK_RESPONSE_ACCEPT) {
- fontname = gtk_font_chooser_get_font (GTK_FONT_CHOOSER (fc));
- if (fontname != NULL) {
- gtk_button_set_label(GTK_BUTTON(button), fontname);
- g_free (cpuFreq->options->fontname);
- cpuFreq->options->fontname = fontname;
- }
- button_fontname_update(button, TRUE);
- }
- gtk_widget_destroy(GTK_WIDGET(fc));
- return TRUE;
+ GtkWidget *fc;
+ gchar *fontname;
+ gint result;
+
+ fc = gtk_font_chooser_dialog_new (_("Select font"),
+ GTK_WINDOW(gtk_widget_get_toplevel(button)));
+
+ if (cpuFreq->options->fontname)
+ gtk_font_chooser_set_font (GTK_FONT_CHOOSER (fc), cpuFreq->options->fontname);
+
+ result = gtk_dialog_run(GTK_DIALOG(fc));
+
+ if (result == GTK_RESPONSE_OK || result == GTK_RESPONSE_ACCEPT)
+ {
+ fontname = gtk_font_chooser_get_font (GTK_FONT_CHOOSER (fc));
+
+ if (fontname != NULL)
+ {
+ gtk_button_set_label(GTK_BUTTON(button), fontname);
+ g_free (cpuFreq->options->fontname);
+ cpuFreq->options->fontname = fontname;
+ }
+
+ button_fontname_update(button, TRUE);
+ }
+
+ gtk_widget_destroy(GTK_WIDGET(fc));
+ return TRUE;
}
+
+
static gboolean
-button_fontname_pressed(GtkWidget *button,
- GdkEventButton *event,
- CpuFreqPluginConfigure *configure)
+button_fontname_pressed(GtkWidget *button, GdkEventButton *event,
+ CpuFreqPluginConfigure *configure)
{
- if (event->type != GDK_BUTTON_PRESS)
- return FALSE;
-
- /* right mouse click clears the font name and resets the button */
- if (event->button == 3 && cpuFreq->options->fontname) {
- g_free (cpuFreq->options->fontname);
- cpuFreq->options->fontname = NULL;
- button_fontname_update(button, TRUE);
- return TRUE;
- }
-
- /* left mouse click will be handled in a different function */
- return FALSE;
+ if (event->type != GDK_BUTTON_PRESS)
+ return FALSE;
+
+ /* right mouse click clears the font name and resets the button */
+ if (event->button == 3 && cpuFreq->options->fontname)
+ {
+ g_free (cpuFreq->options->fontname);
+ cpuFreq->options->fontname = NULL;
+ button_fontname_update(button, TRUE);
+ return TRUE;
+ }
+
+ /* left mouse click will be handled in a different function */
+ return FALSE;
}
+
+
static void
button_fontcolor_clicked (GtkWidget *button, void *data)
{
- GdkRGBA *color = g_new0 (GdkRGBA, 1);
+ GdkRGBA *color = g_new0 (GdkRGBA, 1);
- gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), color);
- cpuFreq->options->fontcolor = gdk_rgba_to_string (color);
- g_free (color);
- cpufreq_update_plugin (TRUE);
+ gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), color);
+ cpuFreq->options->fontcolor = gdk_rgba_to_string (color);
+ g_free (color);
+ cpufreq_update_plugin (TRUE);
}
+
+
static void
combo_changed (GtkWidget *combo, CpuFreqPluginConfigure *configure)
{
- guint selected = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
+ guint selected = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
- if (GTK_WIDGET (combo) == configure->combo_cpu)
- {
- cpuFreq->options->show_cpu = selected;
- cpufreq_update_plugin (TRUE);
- }
+ if (GTK_WIDGET (combo) == configure->combo_cpu)
+ {
+ cpuFreq->options->show_cpu = selected;
+ cpufreq_update_plugin (TRUE);
+ }
}
+
+
static void
spinner_changed (GtkWidget *spinner, CpuFreqPluginConfigure *configure)
{
- cpuFreq->options->timeout =gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinner));
-
- cpufreq_restart_timeout ();
+ cpuFreq->options->timeout =gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinner));
+ cpufreq_restart_timeout ();
}
+
+
static void
cpufreq_configure_response (GtkWidget *dialog, int response, CpuFreqPluginConfigure *configure)
{
- g_object_set_data (G_OBJECT (cpuFreq->plugin), "configure", NULL);
- xfce_panel_plugin_unblock_menu (cpuFreq->plugin);
- gtk_widget_destroy (dialog);
+ g_object_set_data (G_OBJECT (cpuFreq->plugin), "configure", NULL);
+ xfce_panel_plugin_unblock_menu (cpuFreq->plugin);
+ gtk_widget_destroy (dialog);
- cpufreq_write_config (cpuFreq->plugin);
+ cpufreq_write_config (cpuFreq->plugin);
- g_free (configure);
+ g_free (configure);
}
+
+
void
cpufreq_configure (XfcePanelPlugin *plugin)
{
- gint i;
- gchar *cpu_name;
- GtkWidget *dialog, *dialog_vbox;
- GtkWidget *frame, *align, *label, *vbox, *hbox;
- GtkWidget *combo, *spinner, *button;
- GtkSizeGroup *sg0;
- CpuFreqPluginConfigure *configure;
- GdkRGBA *color;
-
- configure = g_new0 (CpuFreqPluginConfigure, 1);
-
- xfce_panel_plugin_block_menu (cpuFreq->plugin);
-
- dialog = xfce_titled_dialog_new_with_buttons (_("Configure CPU Frequency Monitor"),
- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- "gtk-close", GTK_RESPONSE_OK,
- NULL);
- xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (dialog), _("Configure the CPU frequency plugin"));
-
- gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
- gtk_window_set_icon_name (GTK_WINDOW (dialog), "xfce4-cpufreq-plugin");
- gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
- gtk_window_stick (GTK_WINDOW (dialog));
-
- g_object_set_data (G_OBJECT (cpuFreq->plugin), "configure", dialog);
-
- dialog_vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
- gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 12);
- gtk_box_set_spacing (GTK_BOX (dialog_vbox), 18);
-
- sg0 = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
-
- /* monitor behaviours */
- frame = gtk_frame_new (NULL);
- gtk_box_pack_start (GTK_BOX (dialog_vbox), frame, FALSE, TRUE, 0);
- gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
-
- label = gtk_label_new (_("<b>Monitor</b>"));
- gtk_frame_set_label_widget (GTK_FRAME (frame), label);
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
-
- align = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_widget_set_halign(align, GTK_ALIGN_START);
- gtk_widget_set_valign(align, GTK_ALIGN_CENTER);
- gtk_widget_set_hexpand(align, TRUE);
- gtk_widget_set_vexpand(align, TRUE);
-
- gtk_container_add (GTK_CONTAINER (frame), align);
- gtk_widget_set_margin_top (align, 6);
- gtk_widget_set_margin_start (align, 12);
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
- gtk_container_add (GTK_CONTAINER (align), hbox);
-
- label = gtk_label_new_with_mnemonic (_("_Update interval:"));
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- gtk_size_group_add_widget (sg0, label);
-
- spinner = configure->spinner_timeout =
- gtk_spin_button_new_with_range (TIMEOUT_MIN, TIMEOUT_MAX, TIMEOUT_STEP);
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinner);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinner), (gdouble)cpuFreq->options->timeout);
- gtk_box_pack_start (GTK_BOX (hbox), spinner, FALSE, FALSE, 0);
- g_signal_connect (G_OBJECT (spinner), "value-changed", G_CALLBACK (spinner_changed), configure);
-
- /* panel behaviours */
- frame = gtk_frame_new (NULL);
- gtk_box_pack_start (GTK_BOX (dialog_vbox), frame, FALSE, TRUE, 0);
- gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
-
- label = gtk_label_new (_("<b>Panel</b>"));
- gtk_frame_set_label_widget (GTK_FRAME (frame), label);
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
-
- align = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_widget_set_halign(align, GTK_ALIGN_FILL);
- gtk_widget_set_valign(align, GTK_ALIGN_CENTER);
- gtk_widget_set_hexpand(align, TRUE);
- gtk_widget_set_vexpand(align, TRUE);
-
- gtk_container_add (GTK_CONTAINER (frame), align);
- gtk_widget_set_margin_top (align, 6);
- gtk_widget_set_margin_start (align, 12);
-
- vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
- gtk_container_add (GTK_CONTAINER (align), vbox);
-
- /* font settings */
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
- gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
-
- label = gtk_label_new_with_mnemonic (_("_Font:"));
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_size_group_add_widget (sg0, label);
-
- button = configure->fontname = gtk_button_new ();
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
- gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
- g_signal_connect (G_OBJECT (button), "clicked",
- G_CALLBACK (button_fontname_clicked), configure);
- g_signal_connect (G_OBJECT (button), "button_press_event",
- G_CALLBACK (button_fontname_pressed), configure);
- button_fontname_update (button, FALSE);
-
- /* font color */
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
- gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
-
- label = gtk_label_new_with_mnemonic (_("_Font color:"));
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_size_group_add_widget (sg0, label);
-
- color = g_new0 (GdkRGBA, 1);
- gdk_rgba_parse (color, cpuFreq->options->fontcolor ? cpuFreq->options->fontcolor : "#000000");
-
- button = configure->fontcolor = gtk_color_button_new_with_rgba (color);
- gtk_color_button_set_title (GTK_COLOR_BUTTON (button), _("Select font color"));
- gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0);
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
- g_signal_connect (button, "color-set", G_CALLBACK (button_fontcolor_clicked), NULL);
- g_free (color);
-
- /* which cpu to show in panel */
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
- gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
-
- label = gtk_label_new_with_mnemonic (_("_Display CPU:"));
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_size_group_add_widget (sg0, label);
-
- combo = configure->combo_cpu = gtk_combo_box_text_new ();
- gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, TRUE, 0);
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
-
- for (i = 0; i < cpuFreq->cpus->len; ++i)
- {
- cpu_name = g_strdup_printf ("%d", i);
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), cpu_name);
- g_free (cpu_name);
- }
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("min"));
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("avg"));
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (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);
-
- /* check buttons for display widgets in panel */
- button = configure->keep_compact = gtk_check_button_new_with_mnemonic (_("_Keep compact"));
- gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), cpuFreq->options->keep_compact);
- g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (check_button_changed), configure);
-
- button = configure->one_line = gtk_check_button_new_with_mnemonic (_("Show text in a single _line"));
- gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), cpuFreq->options->one_line);
- g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (check_button_changed), configure);
-
- button = configure->display_icon = gtk_check_button_new_with_mnemonic (_("Show CPU _icon"));
- gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), cpuFreq->options->show_icon);
- g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (check_button_changed), configure);
- if (!cpuFreq->options->show_label_freq && !cpuFreq->options->show_label_governor)
- gtk_widget_set_sensitive (configure->display_icon, FALSE);
-
- button = configure->display_freq = gtk_check_button_new_with_mnemonic (_("Show CPU fre_quency"));
- gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), cpuFreq->options->show_label_freq);
- g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (check_button_changed), configure);
-
- button = configure->display_governor = gtk_check_button_new_with_mnemonic (_("Show CPU _governor"));
- gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), cpuFreq->options->show_label_governor);
- g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (check_button_changed), configure);
-
- g_signal_connect(G_OBJECT (dialog), "response", G_CALLBACK(cpufreq_configure_response), configure);
-
- g_object_unref (sg0);
- gtk_widget_show_all (dialog);
+ gint i;
+ gchar *cpu_name;
+ GtkWidget *dialog, *dialog_vbox;
+ GtkWidget *frame, *align, *label, *vbox, *hbox;
+ GtkWidget *combo, *spinner, *button;
+ GtkSizeGroup *sg0;
+ CpuFreqPluginConfigure *configure;
+ GdkRGBA *color;
+
+ configure = g_new0 (CpuFreqPluginConfigure, 1);
+
+ xfce_panel_plugin_block_menu (cpuFreq->plugin);
+
+ dialog = xfce_titled_dialog_new_with_buttons (_("Configure CPU Frequency Monitor"),
+ GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))),
+ GTK_DIALOG_DESTROY_WITH_PARENT, "gtk-close", GTK_RESPONSE_OK, NULL);
+
+ xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (dialog), _("Configure the CPU frequency plugin"));
+
+ gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
+ gtk_window_set_icon_name (GTK_WINDOW (dialog), "xfce4-cpufreq-plugin");
+ gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
+ gtk_window_stick (GTK_WINDOW (dialog));
+
+ g_object_set_data (G_OBJECT (cpuFreq->plugin), "configure", dialog);
+
+ dialog_vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+ gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 12);
+ gtk_box_set_spacing (GTK_BOX (dialog_vbox), 18);
+
+ sg0 = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
+
+ /* monitor behaviours */
+ frame = gtk_frame_new (NULL);
+ gtk_box_pack_start (GTK_BOX (dialog_vbox), frame, FALSE, TRUE, 0);
+ gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
+
+ label = gtk_label_new (_("<b>Monitor</b>"));
+ gtk_frame_set_label_widget (GTK_FRAME (frame), label);
+ gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+
+ align = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ gtk_widget_set_halign(align, GTK_ALIGN_START);
+ gtk_widget_set_valign(align, GTK_ALIGN_CENTER);
+ gtk_widget_set_hexpand(align, TRUE);
+ gtk_widget_set_vexpand(align, TRUE);
+
+ gtk_container_add (GTK_CONTAINER (frame), align);
+ gtk_widget_set_margin_top (align, 6);
+ gtk_widget_set_margin_start (align, 12);
+
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ gtk_container_add (GTK_CONTAINER (align), hbox);
+
+ label = gtk_label_new_with_mnemonic (_("_Update interval:"));
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_size_group_add_widget (sg0, label);
+
+ spinner = configure->spinner_timeout =
+ gtk_spin_button_new_with_range (TIMEOUT_MIN, TIMEOUT_MAX, TIMEOUT_STEP);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinner);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinner), (gdouble) cpuFreq->options->timeout);
+ gtk_box_pack_start (GTK_BOX (hbox), spinner, FALSE, FALSE, 0);
+ g_signal_connect (G_OBJECT (spinner), "value-changed",
+ G_CALLBACK (spinner_changed), configure);
+
+ /* panel behaviours */
+ frame = gtk_frame_new (NULL);
+ gtk_box_pack_start (GTK_BOX (dialog_vbox), frame, FALSE, TRUE, 0);
+ gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
+
+ label = gtk_label_new (_("<b>Panel</b>"));
+ gtk_frame_set_label_widget (GTK_FRAME (frame), label);
+ gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+
+ align = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ gtk_widget_set_halign(align, GTK_ALIGN_FILL);
+ gtk_widget_set_valign(align, GTK_ALIGN_CENTER);
+ gtk_widget_set_hexpand(align, TRUE);
+ gtk_widget_set_vexpand(align, TRUE);
+
+ gtk_container_add (GTK_CONTAINER (frame), align);
+ gtk_widget_set_margin_top (align, 6);
+ gtk_widget_set_margin_start (align, 12);
+
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+ gtk_container_add (GTK_CONTAINER (align), vbox);
+
+ /* font settings */
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+
+ label = gtk_label_new_with_mnemonic (_("_Font:"));
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_size_group_add_widget (sg0, label);
+
+ button = configure->fontname = gtk_button_new ();
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
+ gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
+ g_signal_connect (G_OBJECT (button), "clicked",
+ G_CALLBACK (button_fontname_clicked), configure);
+ g_signal_connect (G_OBJECT (button), "button_press_event",
+ G_CALLBACK (button_fontname_pressed), configure);
+ button_fontname_update (button, FALSE);
+
+ /* font color */
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+
+ label = gtk_label_new_with_mnemonic (_("_Font color:"));
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_size_group_add_widget (sg0, label);
+
+ color = g_new0 (GdkRGBA, 1);
+ gdk_rgba_parse (color, cpuFreq->options->fontcolor ? cpuFreq->options->fontcolor : "#000000");
+
+ button = configure->fontcolor = gtk_color_button_new_with_rgba (color);
+ gtk_color_button_set_title (GTK_COLOR_BUTTON (button), _("Select font color"));
+ gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
+ g_signal_connect (button, "color-set", G_CALLBACK (button_fontcolor_clicked), NULL);
+ g_free (color);
+
+ /* which cpu to show in panel */
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+
+ label = gtk_label_new_with_mnemonic (_("_Display CPU:"));
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_size_group_add_widget (sg0, label);
+
+ combo = configure->combo_cpu = gtk_combo_box_text_new ();
+ gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, TRUE, 0);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
+
+ for (i = 0; i < cpuFreq->cpus->len; ++i)
+ {
+ cpu_name = g_strdup_printf ("%d", i);
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), cpu_name);
+ g_free (cpu_name);
+ }
+
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("min"));
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("avg"));
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (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);
+
+ /* check buttons for display widgets in panel */
+ button = configure->keep_compact = gtk_check_button_new_with_mnemonic (_("_Keep compact"));
+ gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), cpuFreq->options->keep_compact);
+ g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (check_button_changed), configure);
+
+ button = configure->one_line = gtk_check_button_new_with_mnemonic (_("Show text in a single _line"));
+ gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), cpuFreq->options->one_line);
+ g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (check_button_changed), configure);
+
+ button = configure->display_icon = gtk_check_button_new_with_mnemonic (_("Show CPU _icon"));
+ gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), cpuFreq->options->show_icon);
+ g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (check_button_changed), configure);
+ if (!cpuFreq->options->show_label_freq && !cpuFreq->options->show_label_governor)
+ gtk_widget_set_sensitive (configure->display_icon, FALSE);
+
+ button = configure->display_freq = gtk_check_button_new_with_mnemonic (_("Show CPU fre_quency"));
+ gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), cpuFreq->options->show_label_freq);
+ g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (check_button_changed), configure);
+
+ button = configure->display_governor = gtk_check_button_new_with_mnemonic (_("Show CPU _governor"));
+ gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), cpuFreq->options->show_label_governor);
+ g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (check_button_changed), configure);
+
+ g_signal_connect(G_OBJECT (dialog), "response", G_CALLBACK(cpufreq_configure_response), configure);
+
+ g_object_unref (sg0);
+ gtk_widget_show_all (dialog);
}
diff --git a/panel-plugin/xfce4-cpufreq-configure.h b/panel-plugin/xfce4-cpufreq-configure.h
index 4f7608b..da10259 100644
--- a/panel-plugin/xfce4-cpufreq-configure.h
+++ b/panel-plugin/xfce4-cpufreq-configure.h
@@ -24,17 +24,17 @@
typedef struct
{
- GtkWidget *display_icon;
- GtkWidget *display_freq;
- GtkWidget *display_governor;
- GtkWidget *display_cpu;
- GtkWidget *monitor_timeout;
- GtkWidget *combo_cpu;
- GtkWidget *spinner_timeout;
- GtkWidget *keep_compact;
- GtkWidget *one_line;
- GtkWidget *fontname;
- GtkWidget *fontcolor;
+ GtkWidget *display_icon;
+ GtkWidget *display_freq;
+ GtkWidget *display_governor;
+ GtkWidget *display_cpu;
+ GtkWidget *monitor_timeout;
+ GtkWidget *combo_cpu;
+ GtkWidget *spinner_timeout;
+ GtkWidget *keep_compact;
+ GtkWidget *one_line;
+ GtkWidget *fontname;
+ GtkWidget *fontcolor;
} CpuFreqPluginConfigure;
G_BEGIN_DECLS
diff --git a/panel-plugin/xfce4-cpufreq-linux.c b/panel-plugin/xfce4-cpufreq-linux.c
index 1dc0dc4..31b9210 100644
--- a/panel-plugin/xfce4-cpufreq-linux.c
+++ b/panel-plugin/xfce4-cpufreq-linux.c
@@ -35,437 +35,472 @@
# define _(String) gettext (String)
#endif
-#define SYSFS_READ_STRING(file, contents, string) \
- if (contents = read_sysfs_file_contents (file)) { \
- g_free (string); \
- string = contents; \
- }
-
-#define SYSFS_READ_STRING_LIST(file, contents, list) \
- if (contents = read_sysfs_file_contents (file)) { \
- gchar **tokens = NULL; \
- gint i = 0; \
- tokens = g_strsplit (contents, " ", 0); \
- g_free (contents); \
- g_list_free_full (list, g_free); \
- while (tokens[i] != NULL) { \
- list = g_list_append (list, strdup (tokens[i])); \
- i++; \
- } \
- g_strfreev (tokens); \
- }
-
-#define SYSFS_READ_INT(file, contents, intval) \
- if (contents = read_sysfs_file_contents (file)) { \
- intval = atoi (contents); \
- g_free (contents); \
- }
-
-#define SYSFS_READ_INT_LIST(file, contents, list) \
- if (contents = read_sysfs_file_contents (file)) { \
- gchar **tokens = NULL; \
- gint i = 0; \
- tokens = g_strsplit (contents, " ", 0); \
- g_free (contents); \
- g_list_free (list); \
- while (tokens[i] != NULL) { \
- gint value = atoi (tokens[i]); \
- list = g_list_append (list, GINT_TO_POINTER (value)); \
- i++; \
- } \
- g_strfreev (tokens); \
- }
+
+
+#define SYSFS_READ_STRING(file, contents, string) \
+ if (contents = read_sysfs_file_contents (file)) { \
+ g_free (string); \
+ string = contents; \
+ }
+
+
+
+#define SYSFS_READ_STRING_LIST(file, contents, list) \
+ if (contents = read_sysfs_file_contents (file)) { \
+ gchar **tokens = NULL; \
+ gint i = 0; \
+ tokens = g_strsplit (contents, " ", 0); \
+ g_free (contents); \
+ g_list_free_full (list, g_free); \
+ while (tokens[i] != NULL) { \
+ list = g_list_append (list, strdup (tokens[i])); \
+ i++; \
+ } \
+ g_strfreev (tokens); \
+ }
+
+
+
+#define SYSFS_READ_INT(file, contents, intval) \
+ if (contents = read_sysfs_file_contents (file)) { \
+ intval = atoi (contents); \
+ g_free (contents); \
+ }
+
+
+
+#define SYSFS_READ_INT_LIST(file, contents, list) \
+ if (contents = read_sysfs_file_contents (file)) { \
+ gchar **tokens = NULL; \
+ gint i = 0; \
+ tokens = g_strsplit (contents, " ", 0); \
+ g_free (contents); \
+ g_list_free (list); \
+ while (tokens[i] != NULL) { \
+ gint value = atoi (tokens[i]); \
+ list = g_list_append (list, GINT_TO_POINTER (value)); \
+ i++; \
+ } \
+ g_strfreev (tokens); \
+ }
+
static inline gchar *
read_sysfs_file_contents (const gchar *file)
{
- GError *error = NULL;
- gchar *contents = NULL;
-
- if (!g_file_test (file, G_FILE_TEST_EXISTS))
- return NULL;
-
- if (g_file_get_contents (file, &contents, NULL, &error)) {
- g_strstrip (contents);
- return contents;
- } else {
- g_debug ("Error reading %s: %s\n", file, error->message);
- g_error_free (error);
- return NULL;
- }
+ GError *error = NULL;
+ gchar *contents = NULL;
+
+ if (!g_file_test (file, G_FILE_TEST_EXISTS))
+ return NULL;
+
+ if (g_file_get_contents (file, &contents, NULL, &error)) {
+ g_strstrip (contents);
+ return contents;
+ }
+
+ g_debug ("Error reading %s: %s\n", file, error->message);
+ g_error_free (error);
+ return NULL;
}
+
+
static void
cpufreq_cpu_parse_sysfs_init (gint cpu_number, CpuInfo *cpu)
{
- gchar *file, *contents;
- gboolean add_cpu = FALSE;
-
- if (cpu == NULL) {
- cpu = g_new0 (CpuInfo, 1);
- add_cpu = TRUE;
- }
-
- /* read available cpu freqs */
- if (cpuFreq->intel_pstate == NULL) {
- file =
- g_strdup_printf ("/sys/devices/system/cpu/cpu%i/"
- "cpufreq/scaling_available_frequencies",
- cpu_number);
- SYSFS_READ_INT_LIST (file, contents, cpu->available_freqs);
- g_free (file);
- }
-
- /* read available cpu governors */
- file = g_strdup_printf (
- "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_available_governors",
- cpu_number);
- SYSFS_READ_STRING_LIST (file, contents, cpu->available_governors);
- g_free (file);
-
- /* read cpu driver */
- file = g_strdup_printf (
- "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_driver",
- cpu_number);
- SYSFS_READ_STRING (file, contents, cpu->scaling_driver);
- g_free (file);
-
- /* read current cpu freq */
- file = g_strdup_printf ("/sys/devices/system/cpu/cpu%i/"
- "cpufreq/scaling_cur_freq",
- cpu_number);
- SYSFS_READ_INT (file, contents, cpu->cur_freq);
- g_free (file);
-
- /* read current cpu governor */
- file = g_strdup_printf (
- "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_governor",
- cpu_number);
- SYSFS_READ_STRING (file, contents, cpu->cur_governor);
- g_free (file);
-
- /* read max cpu freq */
- file = g_strdup_printf (
- "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_max_freq",
- cpu_number);
- SYSFS_READ_INT (file, contents, cpu->max_freq);
- g_free (file);
-
- /* read min cpu freq */
- file = g_strdup_printf (
- "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_min_freq",
- cpu_number);
- SYSFS_READ_INT (file, contents, cpu->min_freq);
- g_free (file);
-
- if (add_cpu)
- g_ptr_array_add (cpuFreq->cpus, cpu);
+ gchar *file, *contents;
+ gboolean add_cpu = FALSE;
+
+ if (cpu == NULL) {
+ cpu = g_new0 (CpuInfo, 1);
+ add_cpu = TRUE;
+ }
+
+ /* read available cpu freqs */
+ if (cpuFreq->intel_pstate == NULL) {
+ file = g_strdup_printf ("/sys/devices/system/cpu/cpu%i/"
+ "cpufreq/scaling_available_frequencies",
+ cpu_number);
+ SYSFS_READ_INT_LIST (file, contents, cpu->available_freqs);
+ g_free (file);
+ }
+
+ /* read available cpu governors */
+ file = g_strdup_printf ("/sys/devices/system/cpu/cpu%i/"
+ "cpufreq/scaling_available_governors",
+ cpu_number);
+ SYSFS_READ_STRING_LIST (file, contents, cpu->available_governors);
+ g_free (file);
+
+ /* read cpu driver */
+ file = g_strdup_printf ("/sys/devices/system/cpu/cpu%i/"
+ "cpufreq/scaling_driver",
+ cpu_number);
+ SYSFS_READ_STRING (file, contents, cpu->scaling_driver);
+ g_free (file);
+
+ /* read current cpu freq */
+ file = g_strdup_printf ("/sys/devices/system/cpu/cpu%i/"
+ "cpufreq/scaling_cur_freq",
+ cpu_number);
+ SYSFS_READ_INT (file, contents, cpu->cur_freq);
+ g_free (file);
+
+ /* read current cpu governor */
+ file = g_strdup_printf ("/sys/devices/system/cpu/cpu%i/"
+ "cpufreq/scaling_governor",
+ cpu_number);
+ SYSFS_READ_STRING (file, contents, cpu->cur_governor);
+ g_free (file);
+
+ /* read max cpu freq */
+ file = g_strdup_printf ("/sys/devices/system/cpu/cpu%i/"
+ "cpufreq/scaling_max_freq",
+ cpu_number);
+ SYSFS_READ_INT (file, contents, cpu->max_freq);
+ g_free (file);
+
+ /* read min cpu freq */
+ file = g_strdup_printf ("/sys/devices/system/cpu/cpu%i/"
+ "cpufreq/scaling_min_freq",
+ cpu_number);
+ SYSFS_READ_INT (file, contents, cpu->min_freq);
+ g_free (file);
+
+ if (add_cpu)
+ g_ptr_array_add (cpuFreq->cpus, cpu);
}
+
+
static void
cpufreq_cpu_read_sysfs_current (gint cpu_number)
{
- CpuInfo *cpu;
- gchar *file, *contents;
-
- cpu = g_ptr_array_index (cpuFreq->cpus, cpu_number);
-
- /* read current cpu freq */
- file = g_strdup_printf ("/sys/devices/system/cpu/cpu%i/"
- "cpufreq/scaling_cur_freq",
- cpu_number);
- SYSFS_READ_INT (file, contents, cpu->cur_freq);
- g_free (file);
-
- /* read current cpu governor */
- file = g_strdup_printf ("/sys/devices/system/cpu/cpu%i/"
- "cpufreq/scaling_governor",
- cpu_number);
- SYSFS_READ_STRING (file, contents, cpu->cur_governor);
- g_free (file);
+ CpuInfo *cpu;
+ gchar *file, *contents;
+
+ cpu = g_ptr_array_index (cpuFreq->cpus, cpu_number);
+
+ /* read current cpu freq */
+ file = g_strdup_printf ("/sys/devices/system/cpu/cpu%i/"
+ "cpufreq/scaling_cur_freq",
+ cpu_number);
+ SYSFS_READ_INT (file, contents, cpu->cur_freq);
+ g_free (file);
+
+ /* read current cpu governor */
+ file = g_strdup_printf ("/sys/devices/system/cpu/cpu%i/"
+ "cpufreq/scaling_governor",
+ cpu_number);
+ SYSFS_READ_STRING (file, contents, cpu->cur_governor);
+ g_free (file);
}
+
+
static gboolean
cpufreq_cpu_read_procfs_cpuinfo ()
{
- CpuInfo *cpu;
- FILE *file;
- gchar *freq, *filePath, *fileContent;
- gint i = 0;
- gboolean add_cpu;
-
- filePath = g_strdup ("/proc/cpuinfo");
- if (!g_file_test (filePath, G_FILE_TEST_EXISTS))
- {
- g_free (filePath);
- return FALSE;
- }
- file = fopen (filePath, "r");
- if (file)
- {
- fileContent = g_new (gchar,255);
- while (fgets (fileContent, 255, file) != NULL)
- {
- if (g_ascii_strncasecmp (fileContent, "cpu MHz", 7) == 0)
- {
- cpu = NULL;
- add_cpu = FALSE;
-
- if (cpuFreq->cpus && cpuFreq->cpus->len > i)
- {
- cpu = g_ptr_array_index (cpuFreq->cpus, i);
- }
-
- if (cpu == NULL)
- {
- cpu = g_new0 (CpuInfo, 1);
- cpu->max_freq = 0;
- cpu->min_freq = 0;
- cpu->cur_governor = NULL;
- cpu->available_freqs = NULL;
- cpu->available_governors = NULL;
- add_cpu = TRUE;
- }
-
- freq = g_strrstr (fileContent, ":");
- if (freq != NULL)
- {
- sscanf (++freq, "%d.", &cpu->cur_freq);
- cpu->cur_freq *= 1000;
- }
- else {
- if (add_cpu)
- cpuinfo_free (cpu);
- break;
- }
-
- if (add_cpu && cpu != NULL)
- g_ptr_array_add (cpuFreq->cpus, cpu);
-
- ++i;
- }
- }
- fclose (file);
- g_free (fileContent);
- }
-
- g_free (filePath);
- return TRUE;
+ CpuInfo *cpu;
+ FILE *file;
+ gchar *freq, *filePath, *fileContent;
+ gint i = 0;
+ gboolean add_cpu;
+
+ filePath = g_strdup ("/proc/cpuinfo");
+ if (!g_file_test (filePath, G_FILE_TEST_EXISTS))
+ {
+ g_free (filePath);
+ return FALSE;
+ }
+
+ file = fopen (filePath, "r");
+
+ if (file)
+ {
+ fileContent = g_new (gchar,255);
+ while (fgets (fileContent, 255, file) != NULL)
+ {
+ if (g_ascii_strncasecmp (fileContent, "cpu MHz", 7) == 0)
+ {
+ cpu = NULL;
+ add_cpu = FALSE;
+
+ if (cpuFreq->cpus && cpuFreq->cpus->len > i)
+ cpu = g_ptr_array_index (cpuFreq->cpus, i);
+
+ if (cpu == NULL)
+ {
+ cpu = g_new0 (CpuInfo, 1);
+ cpu->max_freq = 0;
+ cpu->min_freq = 0;
+ cpu->cur_governor = NULL;
+ cpu->available_freqs = NULL;
+ cpu->available_governors = NULL;
+ add_cpu = TRUE;
+ }
+
+ freq = g_strrstr (fileContent, ":");
+
+ if (freq == NULL)
+ {
+ if (add_cpu)
+ cpuinfo_free (cpu);
+ break;
+ }
+
+ sscanf (++freq, "%d.", &cpu->cur_freq);
+ cpu->cur_freq *= 1000;
+
+ if (add_cpu && cpu != NULL)
+ g_ptr_array_add (cpuFreq->cpus, cpu);
+
+ ++i;
+ }
+ }
+
+ fclose (file);
+ g_free (fileContent);
+ }
+
+ g_free (filePath);
+
+ return TRUE;
}
+
+
static gboolean
cpufreq_cpu_read_procfs ()
{
- CpuInfo *cpu;
- FILE *file;
- gint i;
- gchar *filePath, *fileContent;
-
- filePath = g_strdup ("/proc/cpufreq");
- if (!g_file_test (filePath, G_FILE_TEST_EXISTS))
- {
- g_free (filePath);
- return FALSE;
- }
- file = fopen (filePath, "r");
- if (file)
- {
- fileContent = g_new (gchar, 255);
- while (fgets (fileContent, 255, file) != NULL)
- {
- if (g_ascii_strncasecmp (fileContent, "CPU", 3) == 0)
- {
- cpu = g_new0 (CpuInfo, 1);
- cpu->max_freq = 0;
- cpu->min_freq = 0;
- cpu->cur_governor = g_new (gchar, 20);
- cpu->available_freqs = NULL;
- cpu->available_governors = NULL;
-
- sscanf (fileContent,
- "CPU %*d %d kHz (%*d %%) - %d kHz (%*d %%) - %20s",
- &cpu->min_freq,
- &cpu->max_freq,
- cpu->cur_governor);
- cpu->min_freq *= 1000;
- cpu->max_freq *= 1000;
-
- g_ptr_array_add (cpuFreq->cpus, cpu);
- }
- }
- fclose (file);
- g_free (fileContent);
- }
- g_free (filePath);
-
- for (i = 0; i < cpuFreq->cpus->len; i++)
- {
- cpu = g_ptr_array_index (cpuFreq->cpus, i);
- filePath = g_strdup_printf ("/proc/sys/cpu/%d/speed", i);
- if (!g_file_test (filePath, G_FILE_TEST_EXISTS))
- {
- g_free (filePath);
- return FALSE;
- }
- file = fopen (filePath, "r");
- if (file)
- {
- fscanf (file, "%d", &cpu->cur_freq);
- fclose (file);
- }
- g_free (filePath);
- }
- return TRUE;
+ CpuInfo *cpu;
+ FILE *file;
+ gint i;
+ gchar *filePath, *fileContent;
+
+ filePath = g_strdup ("/proc/cpufreq");
+ if (!g_file_test (filePath, G_FILE_TEST_EXISTS))
+ {
+ g_free (filePath);
+ return FALSE;
+ }
+
+ file = fopen (filePath, "r");
+
+ if (file)
+ {
+ fileContent = g_new (gchar, 255);
+ while (fgets (fileContent, 255, file) != NULL)
+ {
+ if (g_ascii_strncasecmp (fileContent, "CPU", 3) == 0)
+ {
+ cpu = g_new0 (CpuInfo, 1);
+ cpu->max_freq = 0;
+ cpu->min_freq = 0;
+ cpu->cur_governor = g_new (gchar, 20);
+ cpu->available_freqs = NULL;
+ cpu->available_governors = NULL;
+
+ sscanf (fileContent,
+ "CPU %*d %d kHz (%*d %%) - %d kHz (%*d %%) - %20s",
+ &cpu->min_freq,
+ &cpu->max_freq,
+ cpu->cur_governor);
+ cpu->min_freq *= 1000;
+ cpu->max_freq *= 1000;
+
+ g_ptr_array_add (cpuFreq->cpus, cpu);
+ }
+ }
+
+ fclose (file);
+ g_free (fileContent);
+ }
+
+ g_free (filePath);
+
+ for (i = 0; i < cpuFreq->cpus->len; i++)
+ {
+ cpu = g_ptr_array_index (cpuFreq->cpus, i);
+ filePath = g_strdup_printf ("/proc/sys/cpu/%d/speed", i);
+
+ if (!g_file_test (filePath, G_FILE_TEST_EXISTS))
+ {
+ g_free (filePath);
+ return FALSE;
+ }
+
+ file = fopen (filePath, "r");
+
+ if (file)
+ {
+ fscanf (file, "%d", &cpu->cur_freq);
+ fclose (file);
+ }
+
+ g_free (filePath);
+ }
+
+ return TRUE;
}
+
+
static inline gboolean
cpufreq_cpu_exists (gint num)
{
- const gchar *base = "/sys/devices/system/cpu";
- gchar *file;
- gboolean ret;
-
- file = g_strdup_printf ("%s/cpu%d", base, num);
- ret = g_file_test (file, G_FILE_TEST_EXISTS);
- g_free (file);
- return ret;
+ gchar *file;
+ gboolean ret;
+ const gchar *base = "/sys/devices/system/cpu";
+
+ file = g_strdup_printf ("%s/cpu%d", base, num);
+ ret = g_file_test (file, G_FILE_TEST_EXISTS);
+
+ g_free (file);
+
+ return ret;
}
+
+
static gboolean
cpufreq_cpu_read_sysfs (void)
{
- gchar *file;
- gint count = 0, i = 0;
+ gint count = 0, i = 0;
+ gchar *file;
- while (cpufreq_cpu_exists (count))
- count++;
+ while (cpufreq_cpu_exists (count))
+ count++;
- if (count == 0)
- return FALSE;
+ if (count == 0)
+ return FALSE;
- while (i < count)
- cpufreq_cpu_parse_sysfs_init (i++, NULL);
+ while (i < count)
+ cpufreq_cpu_parse_sysfs_init (i++, NULL);
- return TRUE;
+ return TRUE;
}
+
+
gboolean
cpufreq_intel_pstate_params (void)
{
- gchar *file, *contents;
- IntelPState *ips;
+ gchar *file, *contents;
+ IntelPState *ips;
- ips = g_slice_new0(IntelPState);
+ ips = g_slice_new0(IntelPState);
- if (!g_file_test ("/sys/devices/system/cpu/intel_pstate",
- G_FILE_TEST_EXISTS))
- return FALSE;
+ if (!g_file_test ("/sys/devices/system/cpu/intel_pstate", G_FILE_TEST_EXISTS))
+ return FALSE;
- file =
- g_strdup ("/sys/devices/system/cpu/intel_pstate/min_perf_pct");
- SYSFS_READ_INT (file, contents, ips->min_perf_pct);
- g_free (file);
+ file = g_strdup ("/sys/devices/system/cpu/intel_pstate/min_perf_pct");
+ SYSFS_READ_INT (file, contents, ips->min_perf_pct);
+ g_free (file);
- file =
- g_strdup ("/sys/devices/system/cpu/intel_pstate/max_perf_pct");
- SYSFS_READ_INT (file, contents, ips->max_perf_pct);
- g_free (file);
+ file = g_strdup ("/sys/devices/system/cpu/intel_pstate/max_perf_pct");
+ SYSFS_READ_INT (file, contents, ips->max_perf_pct);
+ g_free (file);
- file =
- g_strdup ("/sys/devices/system/cpu/intel_pstate/no_turbo");
- SYSFS_READ_INT (file, contents, ips->no_turbo);
- g_free (file);
+ file = g_strdup ("/sys/devices/system/cpu/intel_pstate/no_turbo");
+ SYSFS_READ_INT (file, contents, ips->no_turbo);
+ g_free (file);
- g_slice_free (IntelPState, cpuFreq->intel_pstate);
- cpuFreq->intel_pstate = ips;
- return TRUE;
+ g_slice_free (IntelPState, cpuFreq->intel_pstate);
+ cpuFreq->intel_pstate = ips;
+
+ return TRUE;
}
+
+
static gboolean
cpufreq_cpu_intel_pstate_read ()
{
- CpuInfo *cpu;
- gint i;
-
- /* gather intel pstate parameters */
- if (!cpufreq_intel_pstate_params ())
- return FALSE;
- /* now read the number of cpus and the remaining cpufreq info
- for each of them from sysfs */
- if (!cpufreq_cpu_read_sysfs ())
- {
- return FALSE;
- }
- return TRUE;
+ CpuInfo *cpu;
+ gint i;
+
+ /* gather intel pstate parameters */
+ if (!cpufreq_intel_pstate_params ())
+ return FALSE;
+
+ /* now read the number of cpus and the remaining cpufreq info
+ for each of them from sysfs */
+ if (!cpufreq_cpu_read_sysfs ())
+ return FALSE;
+
+ return TRUE;
}
gboolean
cpufreq_update_cpus (gpointer data)
{
- gint i;
+ gint i;
- if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq",
+ if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq",
G_FILE_TEST_EXISTS))
- {
- for (i = 0; i < cpuFreq->cpus->len; i++)
- cpufreq_cpu_read_sysfs_current (i);
- }
- else if (g_file_test ("/proc/cpufreq", G_FILE_TEST_EXISTS))
- {
- /* First we delete the cpus and then read the /proc/cpufreq file again */
- for (i = 0; i < cpuFreq->cpus->len; i++)
- {
- CpuInfo *cpu = g_ptr_array_index (cpuFreq->cpus, i);
- g_ptr_array_remove_fast (cpuFreq->cpus, cpu);
- cpuinfo_free (cpu);
- }
- cpufreq_cpu_read_procfs ();
- }
- else
- {
- /* We do not need to update, because no scaling available */
- return FALSE;
- }
-
- return cpufreq_update_plugin (FALSE);
+ {
+ for (i = 0; i < cpuFreq->cpus->len; i++)
+ cpufreq_cpu_read_sysfs_current (i);
+ }
+ else if (g_file_test ("/proc/cpufreq", G_FILE_TEST_EXISTS))
+ {
+ /* First we delete the cpus and then read the /proc/cpufreq file again */
+ for (i = 0; i < cpuFreq->cpus->len; i++)
+ {
+ CpuInfo *cpu = g_ptr_array_index (cpuFreq->cpus, i);
+ g_ptr_array_remove_fast (cpuFreq->cpus, cpu);
+ cpuinfo_free (cpu);
+ }
+ cpufreq_cpu_read_procfs ();
+ }
+ else
+ {
+ /* We do not need to update, because no scaling available */
+ return FALSE;
+ }
+
+ return cpufreq_update_plugin (FALSE);
}
gboolean
cpufreq_linux_init (void)
{
- if (cpuFreq->cpus == NULL)
- return FALSE;
-
- if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS))
- return cpufreq_cpu_read_sysfs ();
- else if (g_file_test ("/sys/devices/system/cpu/intel_pstate", G_FILE_TEST_EXISTS))
- {
- gboolean ret = cpufreq_cpu_intel_pstate_read ();
-
- /* Tools like i7z show the current real frequency using the
- current maximum performance. Assuming this is the proper
- way to do it, let's choose the maximum per default. Most
- CPUs nowadays have more than one core anyway, so there will
- not be much use in showing a single core's performance
- value. Besides, it's not very likely the user wants to
- follow values for 4 or 8 cores per second. */
- if (ret && cpuFreq->options->show_warning) {
- cpuFreq->options->show_cpu = CPU_MAX;
- cpuFreq->options->show_warning = FALSE;
- }
- return ret;
- }
- else if (g_file_test ("/proc/cpufreq", G_FILE_TEST_EXISTS))
- return cpufreq_cpu_read_procfs ();
- else
- {
- if (cpuFreq->options->show_warning)
- {
- xfce_dialog_show_warning (NULL, NULL, _("Your system does not support cpufreq.\nThe applet only shows the current cpu frequency"));
- cpuFreq->options->show_warning = FALSE;
- }
-
- return cpufreq_cpu_read_procfs_cpuinfo ();
- }
+ if (cpuFreq->cpus == NULL)
+ return FALSE;
+
+ if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS))
+ return cpufreq_cpu_read_sysfs ();
+
+ if (g_file_test ("/sys/devices/system/cpu/intel_pstate", G_FILE_TEST_EXISTS))
+ {
+ gboolean ret = cpufreq_cpu_intel_pstate_read ();
+
+ /* Tools like i7z show the current real frequency using the
+ current maximum performance. Assuming this is the proper
+ way to do it, let's choose the maximum per default. Most
+ CPUs nowadays have more than one core anyway, so there will
+ not be much use in showing a single core's performance
+ value. Besides, it's not very likely the user wants to
+ follow values for 4 or 8 cores per second. */
+ if (ret && cpuFreq->options->show_warning) {
+ cpuFreq->options->show_cpu = CPU_MAX;
+ cpuFreq->options->show_warning = FALSE;
+ }
+
+ return ret;
+ }
+
+ if (g_file_test ("/proc/cpufreq", G_FILE_TEST_EXISTS))
+ return cpufreq_cpu_read_procfs ();
+
+ if (cpuFreq->options->show_warning)
+ {
+ xfce_dialog_show_warning (NULL, NULL, _("Your system does not support cpufreq.\nThe applet only shows the current cpu frequency"));
+ cpuFreq->options->show_warning = FALSE;
+ }
+
+ return cpufreq_cpu_read_procfs_cpuinfo ();
}
diff --git a/panel-plugin/xfce4-cpufreq-overview.c b/panel-plugin/xfce4-cpufreq-overview.c
index 6d2cb0d..af44034 100644
--- a/panel-plugin/xfce4-cpufreq-overview.c
+++ b/panel-plugin/xfce4-cpufreq-overview.c
@@ -37,264 +37,271 @@
#include "xfce4-cpufreq-overview.h"
#include "xfce4-cpufreq-utils.h"
+
+
static void
cpufreq_overview_add (CpuInfo *cpu, guint cpu_number, GtkWidget *dialog_hbox)
{
- gint i = 0, j;
- gchar *text;
- GtkWidget *hbox, *dialog_vbox, *combo, *label, *icon;
- GtkSizeGroup *sg0, *sg1;
- GList *list;
-
- dialog_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, BORDER);
- gtk_box_pack_start (GTK_BOX (dialog_hbox), dialog_vbox, TRUE, TRUE, 0);
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BORDER);
- gtk_box_pack_start (GTK_BOX (dialog_vbox), hbox, TRUE, TRUE, 0);
-
- icon = gtk_image_new_from_icon_name ("xfce4-cpufreq-plugin", GTK_ICON_SIZE_BUTTON);
- gtk_widget_set_halign (icon, GTK_ALIGN_END);
- gtk_widget_set_valign (icon, GTK_ALIGN_CENTER);
- gtk_widget_set_margin_top (icon, 10);
- gtk_widget_set_margin_bottom (icon, 10);
- gtk_widget_set_margin_start (icon, 5);
- gtk_widget_set_margin_end (icon, 5);
-
- gtk_box_pack_start (GTK_BOX (hbox), icon, TRUE, TRUE, 0);
- text = g_strdup_printf ("<b>CPU %d</b>", cpu_number);
- label = gtk_label_new (text);
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
- g_free (text);
-
- sg0 = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
- sg1 = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
-
- /* display driver */
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BORDER);
- gtk_box_pack_start (GTK_BOX (dialog_vbox), hbox, FALSE, FALSE, 0);
-
- label = gtk_label_new (_("Scaling driver:"));
- gtk_size_group_add_widget (sg0, label);
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
-
- if (cpu->scaling_driver != NULL)
- text = g_strdup_printf ("<b>%s</b>", cpu->scaling_driver);
- else
- text = g_strdup_printf (_("No scaling driver available"));
-
- label = gtk_label_new (text);
- gtk_size_group_add_widget (sg1, label);
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_box_pack_end (GTK_BOX (hbox), label, TRUE, TRUE, 0);
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
- g_free (text);
-
- /* display list of available freqs */
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BORDER);
- gtk_box_pack_start (GTK_BOX (dialog_vbox), hbox, FALSE, FALSE, 0);
-
- label = gtk_label_new (_("Available frequencies:"));
- gtk_size_group_add_widget (sg0, label);
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
-
- if (cpu->available_freqs != NULL) /* Linux 2.6 with scaling support */
- {
- combo = gtk_combo_box_text_new ();
- gtk_size_group_add_widget (sg1, combo);
- gtk_box_pack_end (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
- list = g_list_first (cpu->available_freqs);
- j = 0;
- while (list)
- {
- text = cpufreq_get_human_readable_freq (GPOINTER_TO_INT (list->data));
- if (GPOINTER_TO_INT (list->data) == cpu->cur_freq)
- i = j;
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), text);
- g_free (text);
- list = g_list_next (list);
- j++;
- }
- gtk_combo_box_set_active (GTK_COMBO_BOX (combo), i);
- }
- else if (cpu->cur_freq && cpu->min_freq && cpu->max_freq) /* Linux 2.4 with scaling support */
- {
- combo = gtk_combo_box_text_new ();
- gtk_size_group_add_widget (sg1, combo);
- gtk_box_pack_end (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
-
- text = cpufreq_get_human_readable_freq (cpu->cur_freq);
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), text);
- g_free (text);
- text = cpufreq_get_human_readable_freq (cpu->max_freq);
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), text);
- g_free (text);
- text = cpufreq_get_human_readable_freq (cpu->min_freq);
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), text);
- g_free (text);
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
- }
- else /* If there is no scaling support only show the cpu freq */
- {
- text = cpufreq_get_human_readable_freq (cpu->cur_freq);
- text = g_strdup_printf ("<b>%s</b> (current frequency)", text);
- label = gtk_label_new (text);
- gtk_size_group_add_widget (sg1, label);
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_box_pack_end (GTK_BOX (hbox), label, TRUE, TRUE, 0);
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
- g_free (text);
- }
+ gint i = 0, j;
+ gchar *text;
+ GtkWidget *hbox, *dialog_vbox, *combo, *label, *icon;
+ GtkSizeGroup *sg0, *sg1;
+ GList *list;
+
+ dialog_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, BORDER);
+ gtk_box_pack_start (GTK_BOX (dialog_hbox), dialog_vbox, TRUE, TRUE, 0);
+
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BORDER);
+ gtk_box_pack_start (GTK_BOX (dialog_vbox), hbox, TRUE, TRUE, 0);
+
+ icon = gtk_image_new_from_icon_name ("xfce4-cpufreq-plugin", GTK_ICON_SIZE_BUTTON);
+ gtk_widget_set_halign (icon, GTK_ALIGN_END);
+ gtk_widget_set_valign (icon, GTK_ALIGN_CENTER);
+ gtk_widget_set_margin_top (icon, 10);
+ gtk_widget_set_margin_bottom (icon, 10);
+ gtk_widget_set_margin_start (icon, 5);
+ gtk_widget_set_margin_end (icon, 5);
+
+ gtk_box_pack_start (GTK_BOX (hbox), icon, TRUE, TRUE, 0);
+ text = g_strdup_printf ("<b>CPU %d</b>", cpu_number);
+ label = gtk_label_new (text);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+ gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+ g_free (text);
+
+ sg0 = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
+ sg1 = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
+
+ /* display driver */
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BORDER);
+ gtk_box_pack_start (GTK_BOX (dialog_vbox), hbox, FALSE, FALSE, 0);
+
+ label = gtk_label_new (_("Scaling driver:"));
+ gtk_size_group_add_widget (sg0, label);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+
+ if (cpu->scaling_driver != NULL)
+ text = g_strdup_printf ("<b>%s</b>", cpu->scaling_driver);
+ else
+ text = g_strdup_printf (_("No scaling driver available"));
+
+ label = gtk_label_new (text);
+ gtk_size_group_add_widget (sg1, label);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_box_pack_end (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+ gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+ g_free (text);
+
+ /* display list of available freqs */
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BORDER);
+ gtk_box_pack_start (GTK_BOX (dialog_vbox), hbox, FALSE, FALSE, 0);
+
+ label = gtk_label_new (_("Available frequencies:"));
+ gtk_size_group_add_widget (sg0, label);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+
+ if (cpu->available_freqs != NULL) /* Linux 2.6 with scaling support */
+ {
+ combo = gtk_combo_box_text_new ();
+ gtk_size_group_add_widget (sg1, combo);
+ gtk_box_pack_end (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
+ list = g_list_first (cpu->available_freqs);
+ j = 0;
+ while (list)
+ {
+ text = cpufreq_get_human_readable_freq (GPOINTER_TO_INT (list->data));
+
+ if (GPOINTER_TO_INT (list->data) == cpu->cur_freq)
+ i = j;
+
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), text);
+ g_free (text);
+ list = g_list_next (list);
+ j++;
+ }
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), i);
+ }
+ else if (cpu->cur_freq && cpu->min_freq && cpu->max_freq) /* Linux 2.4 with scaling support */
+ {
+ combo = gtk_combo_box_text_new ();
+ gtk_size_group_add_widget (sg1, combo);
+ gtk_box_pack_end (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
+
+ text = cpufreq_get_human_readable_freq (cpu->cur_freq);
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), text);
+ g_free (text);
+
+ text = cpufreq_get_human_readable_freq (cpu->max_freq);
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), text);
+ g_free (text);
+
+ text = cpufreq_get_human_readable_freq (cpu->min_freq);
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), text);
+ g_free (text);
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
+ }
+ else /* If there is no scaling support only show the cpu freq */
+ {
+ text = cpufreq_get_human_readable_freq (cpu->cur_freq);
+ text = g_strdup_printf ("<b>%s</b> (current frequency)", text);
+ label = gtk_label_new (text);
+ gtk_size_group_add_widget (sg1, label);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_box_pack_end (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+ gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+ g_free (text);
+ }
#ifdef __linux__
- /* display list of available governors */
- if (cpu->available_governors != NULL) /* Linux 2.6 and cpu scaling support */
- {
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BORDER);
- gtk_box_pack_start (GTK_BOX (dialog_vbox), hbox, FALSE, FALSE, 0);
-
- label = gtk_label_new (_("Available governors:"));
- gtk_size_group_add_widget (sg0, label);
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
-
- combo = gtk_combo_box_text_new ();
- gtk_size_group_add_widget (sg1, combo);
- gtk_box_pack_end (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
- list = g_list_first (cpu->available_governors);
- j = 0;
- while (list)
- {
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), list->data);
- if (g_ascii_strcasecmp (list->data, cpu->cur_governor) == 0)
- i = j;
- list = g_list_next (list);
- j++;
- }
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (combo), i);
- }
- else if (cpu->cur_governor != NULL) /* Linux 2.4 and cpu scaling support */
- {
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BORDER);
- gtk_box_pack_start (GTK_BOX (dialog_vbox), hbox, FALSE, FALSE, 0);
-
- label = gtk_label_new (_("Current governor:"));
- gtk_size_group_add_widget (sg0, label);
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
-
- text = g_strdup_printf ("<b>%s</b>", cpu->cur_governor);
- label = gtk_label_new (text);
- gtk_size_group_add_widget (sg1, label);
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_box_pack_end (GTK_BOX (hbox), label, TRUE, TRUE, 0);
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
- g_free (text);
- }
- /* If there is no scaling support, do not display governor combo */
+ /* display list of available governors */
+ if (cpu->available_governors != NULL) /* Linux 2.6 and cpu scaling support */
+ {
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BORDER);
+ gtk_box_pack_start (GTK_BOX (dialog_vbox), hbox, FALSE, FALSE, 0);
+
+ label = gtk_label_new (_("Available governors:"));
+ gtk_size_group_add_widget (sg0, label);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+
+ combo = gtk_combo_box_text_new ();
+ gtk_size_group_add_widget (sg1, combo);
+ gtk_box_pack_end (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
+ list = g_list_first (cpu->available_governors);
+ j = 0;
+
+ while (list)
+ {
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), list->data);
+
+ if (g_ascii_strcasecmp (list->data, cpu->cur_governor) == 0)
+ i = j;
+
+ list = g_list_next (list);
+ j++;
+ }
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), i);
+ }
+ else if (cpu->cur_governor != NULL) /* Linux 2.4 and cpu scaling support */
+ {
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BORDER);
+ gtk_box_pack_start (GTK_BOX (dialog_vbox), hbox, FALSE, FALSE, 0);
+
+ label = gtk_label_new (_("Current governor:"));
+ gtk_size_group_add_widget (sg0, label);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+
+ text = g_strdup_printf ("<b>%s</b>", cpu->cur_governor);
+ label = gtk_label_new (text);
+ gtk_size_group_add_widget (sg1, label);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_box_pack_end (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+ gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+ g_free (text);
+ }
+ /* If there is no scaling support, do not display governor combo */
#endif /* __linux__ */
- g_object_unref (sg0);
- g_object_unref (sg1);
+ g_object_unref (sg0);
+ g_object_unref (sg1);
}
+
+
static void
cpufreq_overview_response (GtkWidget *dialog, gint response, gpointer data)
{
- g_object_set_data (G_OBJECT (cpuFreq->plugin), "overview", NULL);
- gtk_widget_destroy (dialog);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cpuFreq->button), FALSE);
+ g_object_set_data (G_OBJECT (cpuFreq->plugin), "overview", NULL);
+ gtk_widget_destroy (dialog);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cpuFreq->button), FALSE);
}
+
+
gboolean
cpufreq_overview (GtkWidget *widget, GdkEventButton *ev, CpuFreqPlugin *cpuFreq)
{
- gint i, j, step;
- GtkWidget *dialog, *dialog_vbox, *window;
- GtkWidget *dialog_hbox, *separator;
-
- if (ev->button != 1)
- return FALSE;
-
- window = g_object_get_data (G_OBJECT (cpuFreq->plugin), "overview");
-
- if (window) {
- g_object_set_data (G_OBJECT (cpuFreq->plugin), "overview", NULL);
- gtk_widget_destroy (window);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cpuFreq->button),
- FALSE);
- return TRUE;
- }
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cpuFreq->button),
- TRUE);
-
- dialog = xfce_titled_dialog_new_with_buttons (_("CPU Information"),
- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (cpuFreq->plugin))),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- "gtk-close", GTK_RESPONSE_OK,
- NULL);
- xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (dialog),
- _("An overview of all the CPUs in the system"));
-
- gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
- gtk_window_set_icon_name (GTK_WINDOW (dialog), "xfce4-cpufreq-plugin");
-
- g_object_set_data (G_OBJECT (cpuFreq->plugin), "overview", dialog);
-
- dialog_vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
-
- /* choose how many columns and rows depending on cpu count */
- if (cpuFreq->cpus->len < 4)
- step = 1;
- else if (cpuFreq->cpus->len < 9)
- step = 2;
- else if (cpuFreq->cpus->len % 3)
- step = 4;
- else
- step = 3;
-
- for (i = 0; i < cpuFreq->cpus->len; i += step) {
- dialog_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BORDER * 2);
- gtk_box_pack_start (GTK_BOX (dialog_vbox), dialog_hbox,
- FALSE, FALSE, BORDER * 2);
- gtk_container_set_border_width (GTK_CONTAINER (dialog_hbox),
- BORDER * 2);
-
- for (j = i; j < cpuFreq->cpus->len && j < i + step; j++) {
- CpuInfo *cpu = g_ptr_array_index (cpuFreq->cpus, j);
- cpufreq_overview_add (cpu, j, dialog_hbox);
-
- if (j + 1 < cpuFreq->cpus->len && j + 1 == i + step) {
- separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
- gtk_box_pack_start (GTK_BOX (dialog_vbox), separator,
- FALSE, FALSE, 0);
- }
-
- if (j + 1 < cpuFreq->cpus->len && j + 1 < i + step) {
- separator = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
- gtk_box_pack_start (GTK_BOX (dialog_hbox), separator,
- FALSE, FALSE, 0);
- }
- }
- }
- g_signal_connect (G_OBJECT (dialog), "response",
- G_CALLBACK (cpufreq_overview_response), NULL);
-
- gtk_widget_show_all (dialog);
-
- return TRUE;
+ gint i, j, step;
+ GtkWidget *dialog, *dialog_vbox, *window;
+ GtkWidget *dialog_hbox, *separator;
+
+ if (ev->button != 1)
+ return FALSE;
+
+ window = g_object_get_data (G_OBJECT (cpuFreq->plugin), "overview");
+
+ if (window) {
+ g_object_set_data (G_OBJECT (cpuFreq->plugin), "overview", NULL);
+ gtk_widget_destroy (window);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cpuFreq->button), FALSE);
+ return TRUE;
+ }
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cpuFreq->button), TRUE);
+
+ dialog = xfce_titled_dialog_new_with_buttons (_("CPU Information"),
+ GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (cpuFreq->plugin))),
+ GTK_DIALOG_DESTROY_WITH_PARENT, "gtk-close", GTK_RESPONSE_OK, NULL);
+
+ xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (dialog),
+ _("An overview of all the CPUs in the system"));
+
+ gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
+ gtk_window_set_icon_name (GTK_WINDOW (dialog), "xfce4-cpufreq-plugin");
+
+ g_object_set_data (G_OBJECT (cpuFreq->plugin), "overview", dialog);
+
+ dialog_vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+
+ /* choose how many columns and rows depending on cpu count */
+ if (cpuFreq->cpus->len < 4)
+ step = 1;
+ else if (cpuFreq->cpus->len < 9)
+ step = 2;
+ else if (cpuFreq->cpus->len % 3)
+ step = 4;
+ else
+ step = 3;
+
+ for (i = 0; i < cpuFreq->cpus->len; i += step) {
+ dialog_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BORDER * 2);
+ gtk_box_pack_start (GTK_BOX (dialog_vbox), dialog_hbox, FALSE, FALSE, BORDER * 2);
+ gtk_container_set_border_width (GTK_CONTAINER (dialog_hbox), BORDER * 2);
+
+ for (j = i; j < cpuFreq->cpus->len && j < i + step; j++) {
+ CpuInfo *cpu = g_ptr_array_index (cpuFreq->cpus, j);
+ cpufreq_overview_add (cpu, j, dialog_hbox);
+
+ if (j + 1 < cpuFreq->cpus->len && j + 1 == i + step) {
+ separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_box_pack_start (GTK_BOX (dialog_vbox), separator, FALSE, FALSE, 0);
+ }
+
+ if (j + 1 < cpuFreq->cpus->len && j + 1 < i + step) {
+ separator = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
+ gtk_box_pack_start (GTK_BOX (dialog_hbox), separator, FALSE, FALSE, 0);
+ }
+ }
+ }
+
+ g_signal_connect (G_OBJECT (dialog), "response",
+ G_CALLBACK (cpufreq_overview_response), NULL);
+
+ gtk_widget_show_all (dialog);
+
+ return TRUE;
}
diff --git a/panel-plugin/xfce4-cpufreq-plugin.c b/panel-plugin/xfce4-cpufreq-plugin.c
index d225409..5a3b5bb 100644
--- a/panel-plugin/xfce4-cpufreq-plugin.c
+++ b/panel-plugin/xfce4-cpufreq-plugin.c
@@ -41,689 +41,766 @@
#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;
+ 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;
+ 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;
+ 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)
{
- gchar *css = NULL, *css_font = NULL, *css_color = NULL;
- GtkCssProvider *provider;
- PangoFontDescription *font;
-
- if (G_UNLIKELY (cpuFreq->label == NULL))
- return;
-
- if (cpuFreq->options->fontname)
- {
- font = pango_font_description_from_string(cpuFreq->options->fontname);
-
- css_font = g_strdup_printf("font-family: %s; font-size: %dpx; font-style: %s; font-weight: %s;",
- pango_font_description_get_family (font),
- pango_font_description_get_size (font) / PANGO_SCALE,
- (pango_font_description_get_style (font) == PANGO_STYLE_ITALIC ||
- pango_font_description_get_style (font) == PANGO_STYLE_OBLIQUE) ? "italic" : "normal",
- (pango_font_description_get_weight (font) >= PANGO_WEIGHT_BOLD) ? "bold" : "normal");
- pango_font_description_free (font);
- }
-
- if (cpuFreq->options->fontcolor)
- css_color = g_strdup_printf ("color: %s;", cpuFreq->options->fontcolor);
-
- if (css_font && css_color)
- css = g_strdup_printf ("label { %s %s }", css_font, css_color);
- else if (css_font)
- css = g_strdup_printf ("label { %s }", css_font);
- else if (css_color)
- css = g_strdup_printf ("label { %s }", css_color);
-
- if (css)
- {
- provider = gtk_css_provider_new ();
-
- gtk_css_provider_load_from_data (provider, css, -1, NULL);
- gtk_style_context_add_provider (
- GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (cpuFreq->label))),
- GTK_STYLE_PROVIDER (provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- }
-
- g_free (css);
- g_free (css_font);
- g_free (css_color);
+ gchar *css = NULL, *css_font = NULL, *css_color = NULL;
+ GtkCssProvider *provider;
+ PangoFontDescription *font;
+
+ if (G_UNLIKELY (cpuFreq->label == NULL))
+ return;
+
+ if (cpuFreq->options->fontname)
+ {
+ font = pango_font_description_from_string(cpuFreq->options->fontname);
+
+ css_font = g_strdup_printf("font-family: %s; font-size: %dpx; font-style: %s; font-weight: %s;",
+ pango_font_description_get_family (font),
+ pango_font_description_get_size (font) / PANGO_SCALE,
+ (pango_font_description_get_style (font) == PANGO_STYLE_ITALIC ||
+ pango_font_description_get_style (font) == PANGO_STYLE_OBLIQUE) ? "italic" : "normal",
+ (pango_font_description_get_weight (font) >= PANGO_WEIGHT_BOLD) ? "bold" : "normal");
+
+ pango_font_description_free (font);
+ }
+
+ if (cpuFreq->options->fontcolor)
+ css_color = g_strdup_printf ("color: %s;", cpuFreq->options->fontcolor);
+
+ if (css_font && css_color)
+ css = g_strdup_printf ("label { %s %s }", css_font, css_color);
+ else if (css_font)
+ css = g_strdup_printf ("label { %s }", css_font);
+ else if (css_color)
+ css = g_strdup_printf ("label { %s }", css_color);
+
+ if (css)
+ {
+ provider = gtk_css_provider_new ();
+
+ gtk_css_provider_load_from_data (provider, css, -1, NULL);
+ gtk_style_context_add_provider (
+ GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (cpuFreq->label))),
+ GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ }
+
+ g_free (css);
+ g_free (css_font);
+ g_free (css_color);
}
+
+
gboolean
cpufreq_update_label (CpuInfo *cpu)
{
- GtkRequisition label_size;
- gchar *label, *freq;
- gint both;
-
- if (!cpuFreq->options->show_label_governor &&
- !cpuFreq->options->show_label_freq) {
- if (cpuFreq->label != NULL)
- gtk_widget_hide (cpuFreq->label);
- return TRUE;
- }
-
- both = cpu->cur_governor != NULL &&
- cpuFreq->options->show_label_freq &&
- cpuFreq->options->show_label_governor;
-
- freq = cpufreq_get_human_readable_freq (cpu->cur_freq);
- label = g_strconcat
- (cpuFreq->options->show_label_freq ? freq : "",
- both ? (cpuFreq->options->one_line ? " " : "\n") : "",
- cpu->cur_governor != NULL &&
- cpuFreq->options->show_label_governor ? cpu->cur_governor : "",
- NULL);
-
- gtk_label_set_text (GTK_LABEL (cpuFreq->label), label);
-
- if (strcmp(label, ""))
- {
- if (cpuFreq->panel_mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL)
- gtk_label_set_angle (GTK_LABEL(cpuFreq->label), -90);
- else
- gtk_label_set_angle (GTK_LABEL(cpuFreq->label), 0);
- gtk_widget_show (cpuFreq->label);
-
- /* Set label width to max width if smaller to avoid panel
- resizing/jumping (see bug #10385). */
- gtk_widget_get_preferred_size (cpuFreq->label, NULL, &label_size);
- if (cpuFreq->panel_mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL)
- if (label_size.height < cpuFreq->label_max_width)
- gtk_widget_set_size_request (GTK_WIDGET (cpuFreq->label),
- -1, cpuFreq->label_max_width);
- else {
- if (label_size.height > cpuFreq->label_max_width)
- cpuFreq->layout_changed = TRUE;
- cpuFreq->label_max_width = label_size.height;
- }
- else
- if (label_size.width < cpuFreq->label_max_width)
- gtk_widget_set_size_request (GTK_WIDGET (cpuFreq->label),
- cpuFreq->label_max_width, -1);
- else {
- if (label_size.width > cpuFreq->label_max_width)
- cpuFreq->label_max_width = label_size.width;
- cpuFreq->layout_changed = TRUE;
- }
- }
- else
- {
- gtk_widget_hide (cpuFreq->label);
- }
-
- g_free (freq);
- g_free (label);
- return TRUE;
+ GtkRequisition label_size;
+ gchar *label, *freq;
+ gint both;
+
+ if (!cpuFreq->options->show_label_governor && !cpuFreq->options->show_label_freq) {
+ if (cpuFreq->label != NULL)
+ gtk_widget_hide (cpuFreq->label);
+
+ return TRUE;
+ }
+
+ both = cpu->cur_governor != NULL &&
+ cpuFreq->options->show_label_freq &&
+ cpuFreq->options->show_label_governor;
+
+ freq = cpufreq_get_human_readable_freq (cpu->cur_freq);
+ label = g_strconcat
+ (cpuFreq->options->show_label_freq ? freq : "",
+ both ? (cpuFreq->options->one_line ? " " : "\n") : "",
+ cpu->cur_governor != NULL &&
+ cpuFreq->options->show_label_governor ? cpu->cur_governor : "",
+ NULL);
+
+ gtk_label_set_text (GTK_LABEL (cpuFreq->label), label);
+
+ if (strcmp(label, ""))
+ {
+ if (cpuFreq->panel_mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL)
+ gtk_label_set_angle (GTK_LABEL(cpuFreq->label), -90);
+ else
+ gtk_label_set_angle (GTK_LABEL(cpuFreq->label), 0);
+
+ gtk_widget_show (cpuFreq->label);
+
+ /* Set label width to max width if smaller to avoid panel
+ resizing/jumping (see bug #10385). */
+ gtk_widget_get_preferred_size (cpuFreq->label, NULL, &label_size);
+ if (cpuFreq->panel_mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL)
+ {
+ if (label_size.height < cpuFreq->label_max_width)
+ {
+ gtk_widget_set_size_request (GTK_WIDGET (cpuFreq->label),
+ -1, cpuFreq->label_max_width);
+ }
+ else
+ {
+ if (label_size.height > cpuFreq->label_max_width)
+ cpuFreq->layout_changed = TRUE;
+ cpuFreq->label_max_width = label_size.height;
+ }
+ }
+ else
+ {
+ if (label_size.width < cpuFreq->label_max_width)
+ {
+ gtk_widget_set_size_request (GTK_WIDGET (cpuFreq->label),
+ cpuFreq->label_max_width, -1);
+ }
+ else
+ {
+ if (label_size.width > cpuFreq->label_max_width)
+ cpuFreq->label_max_width = label_size.width;
+ cpuFreq->layout_changed = TRUE;
+ }
+ }
+ }
+ else
+ {
+ gtk_widget_hide (cpuFreq->label);
+ }
+
+ g_free (freq);
+ g_free (label);
+
+ return TRUE;
}
+
+
static void
cpufreq_widgets_layout (void)
{
- GtkRequisition icon_size, label_size;
- GtkOrientation orientation;
- gboolean small = cpuFreq->options->keep_compact;
- gboolean resized = FALSE;
- gboolean hide_label = (!cpuFreq->options->show_label_freq &&
- !cpuFreq->options->show_label_governor);
- gint pos = 1, lw = 0, lh = 0, iw = 0, ih = 0;
-
- /* keep plugin small if label is hidden or user requested compact size */
- small = (hide_label ? TRUE : cpuFreq->options->keep_compact);
-
- switch (cpuFreq->panel_mode) {
- case XFCE_PANEL_PLUGIN_MODE_HORIZONTAL:
- orientation = small ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
- xfce_panel_plugin_set_small (cpuFreq->plugin, small);
- break;
- case XFCE_PANEL_PLUGIN_MODE_VERTICAL:
- orientation = small ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL;
- xfce_panel_plugin_set_small (cpuFreq->plugin, small);
- break;
- case XFCE_PANEL_PLUGIN_MODE_DESKBAR:
- orientation = small ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
- xfce_panel_plugin_set_small (cpuFreq->plugin, hide_label ? TRUE : FALSE);
- break;
- }
-
- /* check if the label fits below the icon, else put them side by side */
- if (GTK_IS_WIDGET(cpuFreq->label) && ! hide_label) {
- gtk_widget_get_preferred_size (cpuFreq->label, NULL, &label_size);
- lw = label_size.width;
- lh = label_size.height;
- }
- if (GTK_IS_WIDGET(cpuFreq->icon)) {
- gtk_widget_get_preferred_size (cpuFreq->icon, NULL, &icon_size);
- iw = icon_size.width;
- ih = icon_size.height;
- }
-
- if (cpuFreq->panel_mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL &&
- orientation == GTK_ORIENTATION_VERTICAL &&
- lh + ih + BORDER * 2 >= cpuFreq->panel_size) {
- orientation = GTK_ORIENTATION_HORIZONTAL;
- resized = TRUE;
- } else if (orientation == GTK_ORIENTATION_HORIZONTAL &&
- lw + iw + BORDER * 2 >= cpuFreq->panel_size &&
- (cpuFreq->panel_mode == XFCE_PANEL_PLUGIN_MODE_DESKBAR ||
- !small)) {
- orientation = GTK_ORIENTATION_VERTICAL;
- resized = TRUE;
- }
-
- gtk_orientable_set_orientation (GTK_ORIENTABLE (cpuFreq->box), orientation);
-
- if (small) {
- if (orientation == GTK_ORIENTATION_VERTICAL) {
- if (cpuFreq->icon)
- gtk_widget_set_halign (cpuFreq->icon, GTK_ALIGN_CENTER);
- if (cpuFreq->label)
- gtk_widget_set_halign (cpuFreq->label, GTK_ALIGN_CENTER);
- } else {
- if (cpuFreq->icon)
- gtk_widget_set_valign (cpuFreq->icon, GTK_ALIGN_CENTER);
- if (cpuFreq->label)
- gtk_widget_set_valign (cpuFreq->label, GTK_ALIGN_CENTER);
- }
- if (cpuFreq->label)
- gtk_label_set_justify (GTK_LABEL (cpuFreq->label),
- resized
- ? GTK_JUSTIFY_CENTER : GTK_JUSTIFY_LEFT);
-
- if (cpuFreq->icon)
- gtk_box_set_child_packing (GTK_BOX (cpuFreq->box),
- cpuFreq->icon,
- FALSE, FALSE, 0, GTK_PACK_START);
- } else {
- if (orientation == GTK_ORIENTATION_VERTICAL) {
- if (cpuFreq->icon) {
- gtk_widget_set_halign (cpuFreq->icon, GTK_ALIGN_CENTER);
- gtk_widget_set_valign (cpuFreq->icon, GTK_ALIGN_END);
- }
-
- if (cpuFreq->label)
- gtk_widget_set_halign (cpuFreq->label, GTK_ALIGN_CENTER);
- } else {
- if (cpuFreq->icon)
- gtk_widget_set_valign (cpuFreq->icon, GTK_ALIGN_CENTER);
-
- if (cpuFreq->label) {
- gtk_widget_set_halign (cpuFreq->label, GTK_ALIGN_END);
- gtk_widget_set_valign (cpuFreq->label, GTK_ALIGN_CENTER);
- }
- pos = resized ? 1 : 0;
- }
-
- if (cpuFreq->label)
- gtk_label_set_justify (GTK_LABEL (cpuFreq->label),
- resized
- ? GTK_JUSTIFY_LEFT : GTK_JUSTIFY_CENTER);
-
- if (cpuFreq->icon)
- gtk_box_set_child_packing (GTK_BOX (cpuFreq->box),
- cpuFreq->icon,
- TRUE, TRUE, 0, GTK_PACK_START);
- }
- if (cpuFreq->label)
- gtk_box_reorder_child (GTK_BOX (cpuFreq->box), cpuFreq->label, pos);
-
- cpuFreq->layout_changed = FALSE;
+ GtkRequisition icon_size, label_size;
+ GtkOrientation orientation;
+ gboolean small = cpuFreq->options->keep_compact;
+ gboolean resized = FALSE;
+ gboolean hide_label = (!cpuFreq->options->show_label_freq &&
+ !cpuFreq->options->show_label_governor);
+ gint pos = 1, lw = 0, lh = 0, iw = 0, ih = 0;
+
+ /* keep plugin small if label is hidden or user requested compact size */
+ small = (hide_label ? TRUE : cpuFreq->options->keep_compact);
+
+ switch (cpuFreq->panel_mode)
+ {
+ case XFCE_PANEL_PLUGIN_MODE_HORIZONTAL:
+ orientation = small ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
+ xfce_panel_plugin_set_small (cpuFreq->plugin, small);
+ break;
+ case XFCE_PANEL_PLUGIN_MODE_VERTICAL:
+ orientation = small ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL;
+ xfce_panel_plugin_set_small (cpuFreq->plugin, small);
+ break;
+ case XFCE_PANEL_PLUGIN_MODE_DESKBAR:
+ orientation = small ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
+ xfce_panel_plugin_set_small (cpuFreq->plugin, hide_label ? TRUE : FALSE);
+ break;
+ }
+
+ /* check if the label fits below the icon, else put them side by side */
+ if (GTK_IS_WIDGET(cpuFreq->label) && ! hide_label)
+ {
+ gtk_widget_get_preferred_size (cpuFreq->label, NULL, &label_size);
+ lw = label_size.width;
+ lh = label_size.height;
+ }
+ if (GTK_IS_WIDGET(cpuFreq->icon))
+ {
+ gtk_widget_get_preferred_size (cpuFreq->icon, NULL, &icon_size);
+ iw = icon_size.width;
+ ih = icon_size.height;
+ }
+
+ if (cpuFreq->panel_mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL &&
+ orientation == GTK_ORIENTATION_VERTICAL &&
+ lh + ih + BORDER * 2 >= cpuFreq->panel_size)
+ {
+ orientation = GTK_ORIENTATION_HORIZONTAL;
+ resized = TRUE;
+ }
+ else if (orientation == GTK_ORIENTATION_HORIZONTAL &&
+ lw + iw + BORDER * 2 >= cpuFreq->panel_size &&
+ (cpuFreq->panel_mode == XFCE_PANEL_PLUGIN_MODE_DESKBAR || !small))
+ {
+ orientation = GTK_ORIENTATION_VERTICAL;
+ resized = TRUE;
+ }
+
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (cpuFreq->box), orientation);
+
+ if (small)
+ {
+ if (orientation == GTK_ORIENTATION_VERTICAL)
+ {
+ if (cpuFreq->icon)
+ gtk_widget_set_halign (cpuFreq->icon, GTK_ALIGN_CENTER);
+ if (cpuFreq->label)
+ gtk_widget_set_halign (cpuFreq->label, GTK_ALIGN_CENTER);
+ }
+ else
+ {
+ if (cpuFreq->icon)
+ gtk_widget_set_valign (cpuFreq->icon, GTK_ALIGN_CENTER);
+ if (cpuFreq->label)
+ gtk_widget_set_valign (cpuFreq->label, GTK_ALIGN_CENTER);
+ }
+
+ if (cpuFreq->label)
+ gtk_label_set_justify (GTK_LABEL (cpuFreq->label),
+ resized ? GTK_JUSTIFY_CENTER : GTK_JUSTIFY_LEFT);
+
+ if (cpuFreq->icon)
+ gtk_box_set_child_packing (GTK_BOX (cpuFreq->box),
+ cpuFreq->icon, FALSE, FALSE, 0, GTK_PACK_START);
+ }
+ else
+ {
+ if (orientation == GTK_ORIENTATION_VERTICAL)
+ {
+ if (cpuFreq->icon)
+ {
+ gtk_widget_set_halign (cpuFreq->icon, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (cpuFreq->icon, GTK_ALIGN_END);
+ }
+
+ if (cpuFreq->label)
+ gtk_widget_set_halign (cpuFreq->label, GTK_ALIGN_CENTER);
+ }
+ else
+ {
+ if (cpuFreq->icon)
+ gtk_widget_set_valign (cpuFreq->icon, GTK_ALIGN_CENTER);
+
+ if (cpuFreq->label)
+ {
+ gtk_widget_set_halign (cpuFreq->label, GTK_ALIGN_END);
+ gtk_widget_set_valign (cpuFreq->label, GTK_ALIGN_CENTER);
+ }
+ pos = resized ? 1 : 0;
+ }
+
+ if (cpuFreq->label)
+ gtk_label_set_justify (GTK_LABEL (cpuFreq->label),
+ resized ? GTK_JUSTIFY_LEFT : GTK_JUSTIFY_CENTER);
+
+ if (cpuFreq->icon)
+ gtk_box_set_child_packing (GTK_BOX (cpuFreq->box),
+ cpuFreq->icon, TRUE, TRUE, 0, GTK_PACK_START);
+ }
+
+ if (cpuFreq->label)
+ gtk_box_reorder_child (GTK_BOX (cpuFreq->box), cpuFreq->label, pos);
+
+ 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;
+ 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 (gboolean reset_label_size)
{
- CpuInfo *cpu;
- gboolean ret;
+ CpuInfo *cpu;
+ gboolean ret;
- cpu = cpufreq_current_cpu ();
+ cpu = cpufreq_current_cpu ();
- if (reset_label_size) {
- cpuFreq->label_max_width = -1;
- gtk_widget_set_size_request (GTK_WIDGET (cpuFreq->label), -1, -1);
- cpuFreq->layout_changed = TRUE;
- }
+ if (reset_label_size)
+ {
+ cpuFreq->label_max_width = -1;
+ gtk_widget_set_size_request (GTK_WIDGET (cpuFreq->label), -1, -1);
+ cpuFreq->layout_changed = TRUE;
+ }
- ret = cpufreq_update_label (cpu);
+ ret = cpufreq_update_label (cpu);
- if (cpuFreq->layout_changed) {
- cpufreq_label_set_font ();
- cpufreq_widgets_layout ();
- }
+ if (cpuFreq->layout_changed)
+ {
+ cpufreq_label_set_font ();
+ cpufreq_widgets_layout ();
+ }
- return ret;
+ return ret;
}
static gboolean
cpufreq_update_tooltip (GtkWidget *widget,
- gint x,
- gint y,
- gboolean keyboard_mode,
- GtkTooltip *tooltip,
- CpuFreqPlugin *cpufreq)
+ gint x,
+ gint y,
+ gboolean keyboard_mode,
+ GtkTooltip *tooltip,
+ CpuFreqPlugin *cpufreq)
{
- CpuInfo *cpu;
- gchar *tooltip_msg, *freq = NULL;
-
- cpu = cpufreq_current_cpu ();
-
- if (G_UNLIKELY(cpu == NULL)) {
- tooltip_msg = g_strdup (_("No CPU information available."));
- } else {
- freq = cpufreq_get_human_readable_freq (cpu->cur_freq);
- if (cpuFreq->options->show_label_governor &&
- cpuFreq->options->show_label_freq)
- tooltip_msg =
- g_strdup_printf (ngettext ("%d cpu available",
- "%d cpus available",
- cpuFreq->cpus->len),
- cpuFreq->cpus->len);
- else
- tooltip_msg =
- g_strconcat
- (!cpuFreq->options->show_label_freq ? _("Frequency: ") : "",
- !cpuFreq->options->show_label_freq ? freq : "",
-
- cpu->cur_governor != NULL &&
- !cpuFreq->options->show_label_freq &&
- !cpuFreq->options->show_label_governor ? "\n" : "",
-
- cpu->cur_governor != NULL &&
- !cpuFreq->options->show_label_governor ? _("Governor: ") : "",
- cpu->cur_governor != NULL &&
- !cpuFreq->options->show_label_governor ? cpu->cur_governor : "",
- NULL);
- }
-
- gtk_tooltip_set_text (tooltip, tooltip_msg);
-
- g_free (freq);
- g_free (tooltip_msg);
- return TRUE;
+ CpuInfo *cpu;
+ gchar *tooltip_msg, *freq = NULL;
+
+ cpu = cpufreq_current_cpu ();
+
+ if (G_UNLIKELY(cpu == NULL))
+ {
+ tooltip_msg = g_strdup (_("No CPU information available."));
+ }
+ else
+ {
+ freq = cpufreq_get_human_readable_freq (cpu->cur_freq);
+ if (cpuFreq->options->show_label_governor && cpuFreq->options->show_label_freq)
+ tooltip_msg = g_strdup_printf (ngettext ("%d cpu available",
+ "%d cpus available", cpuFreq->cpus->len), cpuFreq->cpus->len);
+ else
+ tooltip_msg =
+ g_strconcat
+ (!cpuFreq->options->show_label_freq ? _("Frequency: ") : "",
+ !cpuFreq->options->show_label_freq ? freq : "",
+
+ cpu->cur_governor != NULL &&
+ !cpuFreq->options->show_label_freq &&
+ !cpuFreq->options->show_label_governor ? "\n" : "",
+
+ cpu->cur_governor != NULL &&
+ !cpuFreq->options->show_label_governor ? _("Governor: ") : "",
+ cpu->cur_governor != NULL &&
+ !cpuFreq->options->show_label_governor ? cpu->cur_governor : "",
+ NULL);
+ }
+
+ gtk_tooltip_set_text (tooltip, tooltip_msg);
+
+ g_free (freq);
+ g_free (tooltip_msg);
+
+ return TRUE;
}
+
+
void
cpufreq_restart_timeout (void)
{
#ifdef __linux__
- g_source_remove (cpuFreq->timeoutHandle);
- cpuFreq->timeoutHandle = g_timeout_add_seconds (
- cpuFreq->options->timeout,
- (GSourceFunc)cpufreq_update_cpus,
- NULL);
+ g_source_remove (cpuFreq->timeoutHandle);
+ cpuFreq->timeoutHandle = g_timeout_add_seconds (
+ cpuFreq->options->timeout, (GSourceFunc)cpufreq_update_cpus, NULL);
#endif
}
+
+
static void
-cpufreq_mode_changed (XfcePanelPlugin *plugin, XfcePanelPluginMode mode, CpuFreqPlugin *cpufreq)
+cpufreq_mode_changed (XfcePanelPlugin *plugin,
+ XfcePanelPluginMode mode,
+ CpuFreqPlugin *cpufreq)
{
- cpuFreq->panel_mode = mode;
- cpuFreq->panel_rows = xfce_panel_plugin_get_nrows (plugin);
- cpufreq_update_plugin (TRUE);
+ cpuFreq->panel_mode = mode;
+ cpuFreq->panel_rows = xfce_panel_plugin_get_nrows (plugin);
+ cpufreq_update_plugin (TRUE);
}
+
+
void
cpufreq_update_icon (CpuFreqPlugin *cpufreq)
{
- if (cpufreq->icon) {
- gtk_widget_destroy (cpufreq->icon);
- cpufreq->icon = NULL;
- }
-
- if (cpufreq->options->show_icon) {
- GdkPixbuf *buf, *scaled;
- gint icon_size;
-
- icon_size = cpuFreq->panel_size / cpuFreq->panel_rows;
- if (cpufreq->options->keep_compact ||
- (!cpufreq->options->show_label_freq &&
- !cpufreq->options->show_label_governor))
- icon_size -= 4;
-
- buf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
- "xfce4-cpufreq-plugin",
- icon_size, 0, NULL);
-
- if (buf) {
- scaled = gdk_pixbuf_scale_simple (buf, icon_size, icon_size, GDK_INTERP_BILINEAR);
- cpufreq->icon = gtk_image_new_from_pixbuf (scaled);
- g_object_unref (G_OBJECT (buf));
- g_object_unref (G_OBJECT (scaled));
- } else {
- cpufreq->icon = gtk_image_new_from_icon_name
- ("xfce4-cpufreq-plugin", GTK_ICON_SIZE_BUTTON);
- }
- gtk_box_pack_start (GTK_BOX (cpufreq->box), cpufreq->icon, FALSE, FALSE, 0);
- gtk_widget_show (cpufreq->icon);
- }
+ if (cpufreq->icon)
+ {
+ gtk_widget_destroy (cpufreq->icon);
+ cpufreq->icon = NULL;
+ }
+
+ if (cpufreq->options->show_icon)
+ {
+ GdkPixbuf *buf, *scaled;
+ gint icon_size;
+
+ icon_size = cpuFreq->panel_size / cpuFreq->panel_rows;
+
+ if (cpufreq->options->keep_compact ||
+ (!cpufreq->options->show_label_freq &&
+ !cpufreq->options->show_label_governor))
+ icon_size -= 4;
+
+ buf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ "xfce4-cpufreq-plugin", icon_size, 0, NULL);
+
+ if (buf)
+ {
+ scaled = gdk_pixbuf_scale_simple (buf, icon_size, icon_size, GDK_INTERP_BILINEAR);
+ cpufreq->icon = gtk_image_new_from_pixbuf (scaled);
+ g_object_unref (G_OBJECT (buf));
+ g_object_unref (G_OBJECT (scaled));
+ }
+ else
+ {
+ cpufreq->icon = gtk_image_new_from_icon_name ("xfce4-cpufreq-plugin", GTK_ICON_SIZE_BUTTON);
+ }
+
+ gtk_box_pack_start (GTK_BOX (cpufreq->box), cpufreq->icon, FALSE, FALSE, 0);
+ gtk_widget_show (cpufreq->icon);
+ }
}
+
+
void
cpufreq_prepare_label (CpuFreqPlugin *cpufreq)
{
- if (cpufreq->label)
- {
- gtk_widget_destroy (cpufreq->label);
- cpufreq->label = NULL;
- }
- if (cpuFreq->options->show_label_freq || cpuFreq->options->show_label_governor)
- {
- cpuFreq->label = gtk_label_new (NULL);
- gtk_box_pack_start (GTK_BOX (cpufreq->box), cpuFreq->label, TRUE, TRUE, 0);
- }
+ if (cpufreq->label)
+ {
+ gtk_widget_destroy (cpufreq->label);
+ cpufreq->label = NULL;
+ }
+
+ if (cpuFreq->options->show_label_freq || cpuFreq->options->show_label_governor)
+ {
+ cpuFreq->label = gtk_label_new (NULL);
+ gtk_box_pack_start (GTK_BOX (cpufreq->box), cpuFreq->label, TRUE, TRUE, 0);
+ }
}
+
+
static void
cpufreq_widgets (void)
{
- gchar *css;
- GtkCssProvider *provider;
+ gchar *css;
+ GtkCssProvider *provider;
- /* create panel toggle button which will contain all other widgets */
- cpuFreq->button = xfce_panel_create_toggle_button ();
- xfce_panel_plugin_add_action_widget (cpuFreq->plugin, cpuFreq->button);
- gtk_container_add (GTK_CONTAINER (cpuFreq->plugin), cpuFreq->button);
+ /* create panel toggle button which will contain all other widgets */
+ cpuFreq->button = xfce_panel_create_toggle_button ();
+ xfce_panel_plugin_add_action_widget (cpuFreq->plugin, cpuFreq->button);
+ gtk_container_add (GTK_CONTAINER (cpuFreq->plugin), cpuFreq->button);
- css = g_strdup_printf("button { padding: 0px; }");
+ css = g_strdup_printf("button { padding: 0px; }");
- provider = gtk_css_provider_new ();
- gtk_css_provider_load_from_data (provider, css, -1, NULL);
- gtk_style_context_add_provider (
- GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (cpuFreq->button))),
- GTK_STYLE_PROVIDER(provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- g_free(css);
+ provider = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (provider, css, -1, NULL);
+ gtk_style_context_add_provider (
+ GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (cpuFreq->button))),
+ GTK_STYLE_PROVIDER(provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ g_free(css);
- cpuFreq->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, SPACING);
- gtk_container_set_border_width (GTK_CONTAINER (cpuFreq->box), BORDER);
- gtk_container_add (GTK_CONTAINER (cpuFreq->button), cpuFreq->box);
+ cpuFreq->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, SPACING);
+ gtk_container_set_border_width (GTK_CONTAINER (cpuFreq->box), BORDER);
+ gtk_container_add (GTK_CONTAINER (cpuFreq->button), cpuFreq->box);
- cpufreq_update_icon (cpuFreq);
+ cpufreq_update_icon (cpuFreq);
- cpufreq_prepare_label (cpuFreq);
+ cpufreq_prepare_label (cpuFreq);
- g_signal_connect (cpuFreq->button, "button-press-event",
- G_CALLBACK (cpufreq_overview), cpuFreq);
+ g_signal_connect (cpuFreq->button, "button-press-event",
+ G_CALLBACK (cpufreq_overview), cpuFreq);
- /* activate panel widget tooltip */
- 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), cpuFreq);
+ /* activate panel widget tooltip */
+ 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), cpuFreq);
- gtk_widget_show_all (cpuFreq->button);
+ gtk_widget_show_all (cpuFreq->button);
- cpufreq_update_plugin (TRUE);
+ cpufreq_update_plugin (TRUE);
}
+
+
static void
cpufreq_read_config (void)
{
- XfceRc *rc;
- gchar *file;
- const gchar *value;
-
- file = xfce_panel_plugin_save_location (cpuFreq->plugin, FALSE);
-
- if (G_UNLIKELY (!file))
- return;
-
- rc = xfce_rc_simple_open (file, FALSE);
- g_free (file);
-
- cpuFreq->options->timeout = xfce_rc_read_int_entry (rc, "timeout", 1);
- if (cpuFreq->options->timeout > TIMEOUT_MAX || cpuFreq->options->timeout < TIMEOUT_MIN)
- cpuFreq->options->timeout = TIMEOUT_MIN;
- cpuFreq->options->show_cpu = xfce_rc_read_int_entry (rc, "show_cpu", 0);
- cpuFreq->options->show_icon = xfce_rc_read_bool_entry (rc, "show_icon", TRUE);
- cpuFreq->options->show_label_freq = xfce_rc_read_bool_entry (rc, "show_label_freq", TRUE);
- cpuFreq->options->show_label_governor = xfce_rc_read_bool_entry (rc, "show_label_governor", TRUE);
- cpuFreq->options->show_warning = xfce_rc_read_bool_entry (rc, "show_warning", TRUE);
- cpuFreq->options->keep_compact = xfce_rc_read_bool_entry (rc, "keep_compact", FALSE);
- cpuFreq->options->one_line = xfce_rc_read_bool_entry (rc, "one_line", FALSE);
-
- if (!cpuFreq->options->show_label_freq && !cpuFreq->options->show_label_governor)
- cpuFreq->options->show_icon = TRUE;
-
- value = xfce_rc_read_entry (rc, "fontname", NULL);
- if (value) {
- g_free (cpuFreq->options->fontname);
- cpuFreq->options->fontname = g_strdup (value);
- }
-
- value = xfce_rc_read_entry (rc, "fontcolor", NULL);
- if (value) {
- g_free (cpuFreq->options->fontcolor);
- cpuFreq->options->fontcolor = g_strdup (value);
- }
-
- xfce_rc_close (rc);
+ XfceRc *rc;
+ gchar *file;
+ const gchar *value;
+
+ file = xfce_panel_plugin_save_location (cpuFreq->plugin, FALSE);
+
+ if (G_UNLIKELY (!file))
+ return;
+
+ rc = xfce_rc_simple_open (file, FALSE);
+ g_free (file);
+
+ cpuFreq->options->timeout = xfce_rc_read_int_entry (rc, "timeout", 1);
+ if (cpuFreq->options->timeout > TIMEOUT_MAX || cpuFreq->options->timeout < TIMEOUT_MIN)
+ cpuFreq->options->timeout = TIMEOUT_MIN;
+ cpuFreq->options->show_cpu = xfce_rc_read_int_entry (rc, "show_cpu", 0);
+ cpuFreq->options->show_icon = xfce_rc_read_bool_entry (rc, "show_icon", TRUE);
+ cpuFreq->options->show_label_freq = xfce_rc_read_bool_entry (rc, "show_label_freq", TRUE);
+ cpuFreq->options->show_label_governor = xfce_rc_read_bool_entry (rc, "show_label_governor", TRUE);
+ cpuFreq->options->show_warning = xfce_rc_read_bool_entry (rc, "show_warning", TRUE);
+ cpuFreq->options->keep_compact = xfce_rc_read_bool_entry (rc, "keep_compact", FALSE);
+ cpuFreq->options->one_line = xfce_rc_read_bool_entry (rc, "one_line", FALSE);
+
+ if (!cpuFreq->options->show_label_freq && !cpuFreq->options->show_label_governor)
+ cpuFreq->options->show_icon = TRUE;
+
+ value = xfce_rc_read_entry (rc, "fontname", NULL);
+ if (value)
+ {
+ g_free (cpuFreq->options->fontname);
+ cpuFreq->options->fontname = g_strdup (value);
+ }
+
+ value = xfce_rc_read_entry (rc, "fontcolor", NULL);
+ if (value)
+ {
+ g_free (cpuFreq->options->fontcolor);
+ cpuFreq->options->fontcolor = g_strdup (value);
+ }
+
+ xfce_rc_close (rc);
}
+
+
void
cpufreq_write_config (XfcePanelPlugin *plugin)
{
- XfceRc *rc;
- gchar *file;
-
- file = xfce_panel_plugin_save_location (plugin, TRUE);
-
- if (G_UNLIKELY (!file))
- return;
-
- rc = xfce_rc_simple_open (file, FALSE);
- g_free(file);
-
- xfce_rc_write_int_entry (rc, "timeout", cpuFreq->options->timeout);
- xfce_rc_write_int_entry (rc, "show_cpu", cpuFreq->options->show_cpu);
- xfce_rc_write_bool_entry (rc, "show_icon", cpuFreq->options->show_icon);
- xfce_rc_write_bool_entry (rc, "show_label_freq", cpuFreq->options->show_label_freq);
- xfce_rc_write_bool_entry (rc, "show_label_governor", cpuFreq->options->show_label_governor);
- xfce_rc_write_bool_entry (rc, "show_warning", cpuFreq->options->show_warning);
- xfce_rc_write_bool_entry (rc, "keep_compact", cpuFreq->options->keep_compact);
- xfce_rc_write_bool_entry (rc, "one_line", cpuFreq->options->one_line);
- if (cpuFreq->options->fontname)
- xfce_rc_write_entry (rc, "fontname", cpuFreq->options->fontname);
- if (cpuFreq->options->fontcolor)
- xfce_rc_write_entry (rc, "fontcolor", cpuFreq->options->fontcolor);
-
- xfce_rc_close (rc);
+ XfceRc *rc;
+ gchar *file;
+
+ file = xfce_panel_plugin_save_location (plugin, TRUE);
+
+ if (G_UNLIKELY (!file))
+ return;
+
+ rc = xfce_rc_simple_open (file, FALSE);
+ g_free(file);
+
+ xfce_rc_write_int_entry (rc, "timeout", cpuFreq->options->timeout);
+ xfce_rc_write_int_entry (rc, "show_cpu", cpuFreq->options->show_cpu);
+ xfce_rc_write_bool_entry (rc, "show_icon", cpuFreq->options->show_icon);
+ xfce_rc_write_bool_entry (rc, "show_label_freq", cpuFreq->options->show_label_freq);
+ xfce_rc_write_bool_entry (rc, "show_label_governor", cpuFreq->options->show_label_governor);
+ xfce_rc_write_bool_entry (rc, "show_warning", cpuFreq->options->show_warning);
+ xfce_rc_write_bool_entry (rc, "keep_compact", cpuFreq->options->keep_compact);
+ xfce_rc_write_bool_entry (rc, "one_line", cpuFreq->options->one_line);
+
+ if (cpuFreq->options->fontname)
+ xfce_rc_write_entry (rc, "fontname", cpuFreq->options->fontname);
+ if (cpuFreq->options->fontcolor)
+ xfce_rc_write_entry (rc, "fontcolor", cpuFreq->options->fontcolor);
+
+ xfce_rc_close (rc);
}
+
+
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);
- g_list_free_full (cpu->available_governors, g_free);
- g_free (cpu);
+ if (G_UNLIKELY(cpu == NULL))
+ return;
+
+ g_free (cpu->cur_governor);
+ g_free (cpu->scaling_driver);
+ g_list_free (cpu->available_freqs);
+ g_list_free_full (cpu->available_governors, g_free);
+ g_free (cpu);
}
+
+
static void
cpufreq_free (XfcePanelPlugin *plugin)
{
- gint i;
+ gint i;
+
+ if (cpuFreq->timeoutHandle)
+ g_source_remove (cpuFreq->timeoutHandle);
- if (cpuFreq->timeoutHandle)
- g_source_remove (cpuFreq->timeoutHandle);
+ g_slice_free (IntelPState, cpuFreq->intel_pstate);
- g_slice_free (IntelPState, cpuFreq->intel_pstate);
+ for (i = 0; i < cpuFreq->cpus->len; i++)
+ {
+ CpuInfo *cpu = g_ptr_array_index (cpuFreq->cpus, i);
+ g_ptr_array_remove_fast (cpuFreq->cpus, cpu);
+ cpuinfo_free (cpu);
+ }
- for (i = 0; i < cpuFreq->cpus->len; i++)
- {
- CpuInfo *cpu = g_ptr_array_index (cpuFreq->cpus, i);
- g_ptr_array_remove_fast (cpuFreq->cpus, cpu);
- cpuinfo_free (cpu);
- }
- g_ptr_array_free (cpuFreq->cpus, TRUE);
+ g_ptr_array_free (cpuFreq->cpus, TRUE);
- g_free (cpuFreq->options->fontname);
- cpuFreq->plugin = NULL;
- g_free (cpuFreq);
+ g_free (cpuFreq->options->fontname);
+ cpuFreq->plugin = NULL;
+ g_free (cpuFreq);
}
+
+
static gboolean
cpufreq_set_size (XfcePanelPlugin *plugin, gint size, CpuFreqPlugin *cpufreq)
{
- cpuFreq->panel_size = size;
- cpuFreq->panel_rows = xfce_panel_plugin_get_nrows (plugin);
+ cpuFreq->panel_size = size;
+ cpuFreq->panel_rows = xfce_panel_plugin_get_nrows (plugin);
- cpufreq_update_icon (cpufreq);
- cpufreq_update_plugin (TRUE);
+ cpufreq_update_icon (cpufreq);
+ cpufreq_update_plugin (TRUE);
- return TRUE;
+ return TRUE;
}
static void
cpufreq_show_about(XfcePanelPlugin *plugin,
- CpuFreqPlugin *cpufreq)
+ CpuFreqPlugin *cpufreq)
{
- GdkPixbuf *icon;
- const gchar *auth[] = {
- "Thomas Schreck <shrek at xfce.org>",
- "Florian Rivoal <frivoal at xfce.org>",
- "Harald Judt <h.judt at gmx.at>",
- "Andre Miranda <andreldm at xfce.org>",
- NULL };
- icon = xfce_panel_pixbuf_from_source("xfce4-cpufreq-plugin", NULL, 48);
- gtk_show_about_dialog
- (NULL,
- "logo", icon,
- "license", xfce_get_license_text(XFCE_LICENSE_TEXT_GPL),
- "version", PACKAGE_VERSION,
- "program-name", PACKAGE_NAME,
- "comments", _("Show CPU frequencies and governor"),
- "website", PLUGIN_WEBSITE,
- "copyright", _("Copyright (c) 2003-2018\n"),
- "authors", auth,
- NULL);
-
- if (icon)
- g_object_unref(G_OBJECT(icon));
+ const gchar *auth[] = {
+ "Thomas Schreck <shrek at xfce.org>",
+ "Florian Rivoal <frivoal at xfce.org>",
+ "Harald Judt <h.judt at gmx.at>",
+ "Andre Miranda <andreldm at xfce.org>",
+ NULL };
+
+ GdkPixbuf *icon = xfce_panel_pixbuf_from_source ("xfce4-cpufreq-plugin", NULL, 48);
+
+ gtk_show_about_dialog
+ (NULL,
+ "logo", icon,
+ "license", xfce_get_license_text (XFCE_LICENSE_TEXT_GPL),
+ "version", PACKAGE_VERSION,
+ "program-name", PACKAGE_NAME,
+ "comments", _("Show CPU frequencies and governor"),
+ "website", PLUGIN_WEBSITE,
+ "copyright", _("Copyright (c) 2003-2018\n"),
+ "authors", auth,
+ NULL);
+
+ if (icon)
+ g_object_unref(G_OBJECT(icon));
}
static void
cpufreq_construct (XfcePanelPlugin *plugin)
{
- xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+ xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
- cpuFreq = g_new0 (CpuFreqPlugin, 1);
- cpuFreq->options = g_new0 (CpuFreqPluginOptions, 1);
- cpuFreq->plugin = plugin;
- cpuFreq->panel_mode = xfce_panel_plugin_get_mode (cpuFreq->plugin);
- cpuFreq->panel_rows = xfce_panel_plugin_get_nrows (cpuFreq->plugin);
- cpuFreq->panel_size = xfce_panel_plugin_get_size (cpuFreq->plugin);
- cpuFreq->label_max_width = -1;
- cpuFreq->cpus = g_ptr_array_new ();
+ cpuFreq = g_new0 (CpuFreqPlugin, 1);
+ cpuFreq->options = g_new0 (CpuFreqPluginOptions, 1);
+ cpuFreq->plugin = plugin;
+ cpuFreq->panel_mode = xfce_panel_plugin_get_mode (cpuFreq->plugin);
+ cpuFreq->panel_rows = xfce_panel_plugin_get_nrows (cpuFreq->plugin);
+ cpuFreq->panel_size = xfce_panel_plugin_get_size (cpuFreq->plugin);
+ cpuFreq->label_max_width = -1;
+ cpuFreq->cpus = g_ptr_array_new ();
- cpufreq_read_config ();
- cpuFreq->layout_changed = TRUE;
+ cpufreq_read_config ();
+ cpuFreq->layout_changed = TRUE;
#ifdef __linux__
- if (cpufreq_linux_init () == FALSE)
- xfce_dialog_show_error (NULL, NULL, _("Your system is not configured correctly to support CPU frequency scaling!"));
+ if (cpufreq_linux_init () == FALSE)
+ xfce_dialog_show_error (NULL, NULL,
+ _("Your system is not configured correctly to support CPU frequency scaling!"));
- gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, -1);
- cpufreq_widgets ();
+ gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, -1);
+ cpufreq_widgets ();
- cpuFreq->timeoutHandle = g_timeout_add_seconds (
- cpuFreq->options->timeout,
- (GSourceFunc) cpufreq_update_cpus,
- NULL);
+ cpuFreq->timeoutHandle = g_timeout_add_seconds (
+ cpuFreq->options->timeout, (GSourceFunc) cpufreq_update_cpus, NULL);
#else
- xfce_dialog_show_error (NULL, NULL, _("Your system is not supported yet!"));
+ xfce_dialog_show_error (NULL, NULL, _("Your system is not supported yet!"));
#endif /* __linux__ */
- g_signal_connect (plugin, "free-data", G_CALLBACK (cpufreq_free),
- NULL);
- g_signal_connect (plugin, "save", G_CALLBACK (cpufreq_write_config),
- NULL);
- g_signal_connect (plugin, "size-changed",
- G_CALLBACK (cpufreq_set_size), cpuFreq);
- g_signal_connect (plugin, "mode-changed",
- G_CALLBACK (cpufreq_mode_changed), cpuFreq);
-
- /* the configure and about menu items are hidden by default */
- xfce_panel_plugin_menu_show_configure (plugin);
- g_signal_connect (plugin, "configure-plugin",
- G_CALLBACK (cpufreq_configure), NULL);
- xfce_panel_plugin_menu_show_about(plugin);
- g_signal_connect (G_OBJECT (plugin), "about",
- G_CALLBACK (cpufreq_show_about), cpuFreq);
+ g_signal_connect (plugin, "free-data", G_CALLBACK (cpufreq_free), NULL);
+ g_signal_connect (plugin, "save", G_CALLBACK (cpufreq_write_config), NULL);
+ g_signal_connect (plugin, "size-changed", G_CALLBACK (cpufreq_set_size), cpuFreq);
+ g_signal_connect (plugin, "mode-changed", G_CALLBACK (cpufreq_mode_changed), cpuFreq);
+
+ /* the configure and about menu items are hidden by default */
+ xfce_panel_plugin_menu_show_configure (plugin);
+ g_signal_connect (plugin, "configure-plugin", G_CALLBACK (cpufreq_configure), NULL);
+ xfce_panel_plugin_menu_show_about(plugin);
+ g_signal_connect (G_OBJECT (plugin), "about", G_CALLBACK (cpufreq_show_about), cpuFreq);
}
XFCE_PANEL_PLUGIN_REGISTER (cpufreq_construct);
diff --git a/panel-plugin/xfce4-cpufreq-plugin.h b/panel-plugin/xfce4-cpufreq-plugin.h
index f6c6c0e..3ef0b86 100644
--- a/panel-plugin/xfce4-cpufreq-plugin.h
+++ b/panel-plugin/xfce4-cpufreq-plugin.h
@@ -33,62 +33,62 @@
typedef struct
{
- guint cur_freq;
- guint max_freq;
- guint min_freq;
- gchar *cur_governor;
- gchar *scaling_driver;
-
- GList* available_freqs;
- GList* available_governors;
+ guint cur_freq;
+ guint max_freq;
+ guint min_freq;
+ gchar *cur_governor;
+ gchar *scaling_driver;
+
+ GList* available_freqs;
+ GList* available_governors;
} CpuInfo;
typedef struct
{
- gint min_perf_pct;
- gint max_perf_pct;
- gint no_turbo;
+ gint min_perf_pct;
+ gint max_perf_pct;
+ gint no_turbo;
} IntelPState;
typedef struct
{
- guint timeout; /* time between refresh */
- guint show_cpu; /* cpu number in panel */
- gboolean show_icon;
- gboolean show_label_governor;
- gboolean show_label_freq;
- gboolean show_warning;
- gboolean keep_compact;
- gboolean one_line;
- gchar *fontname;
- gchar *fontcolor;
+ guint timeout; /* time between refresh */
+ guint show_cpu; /* cpu number in panel */
+ gboolean show_icon;
+ gboolean show_label_governor;
+ gboolean show_label_freq;
+ gboolean show_warning;
+ gboolean keep_compact;
+ gboolean one_line;
+ gchar *fontname;
+ gchar *fontcolor;
} CpuFreqPluginOptions;
typedef struct
{
- XfcePanelPlugin *plugin;
- XfcePanelPluginMode panel_mode;
- gint panel_size;
- guint panel_rows;
+ XfcePanelPlugin *plugin;
+ XfcePanelPluginMode panel_mode;
+ gint panel_size;
+ guint panel_rows;
- /* Array with all CPUs */
- GPtrArray *cpus;
+ /* Array with all CPUs */
+ GPtrArray *cpus;
- /* Calculated values */
- CpuInfo *cpu_min;
- CpuInfo *cpu_avg;
- CpuInfo *cpu_max;
+ /* Calculated values */
+ CpuInfo *cpu_min;
+ CpuInfo *cpu_avg;
+ CpuInfo *cpu_max;
- /* Intel P-State parameters */
- IntelPState *intel_pstate;
+ /* Intel P-State parameters */
+ IntelPState *intel_pstate;
- /* Widgets */
- GtkWidget *button, *box, *icon, *label;
- gboolean layout_changed;
- gint label_max_width;
+ /* Widgets */
+ GtkWidget *button, *box, *icon, *label;
+ gboolean layout_changed;
+ gint label_max_width;
- CpuFreqPluginOptions *options;
- gint timeoutHandle;
+ CpuFreqPluginOptions *options;
+ gint timeoutHandle;
} CpuFreqPlugin;
CpuFreqPlugin *cpuFreq;
diff --git a/panel-plugin/xfce4-cpufreq-utils.c b/panel-plugin/xfce4-cpufreq-utils.c
index 82eef1e..ab890b8 100644
--- a/panel-plugin/xfce4-cpufreq-utils.c
+++ b/panel-plugin/xfce4-cpufreq-utils.c
@@ -26,45 +26,51 @@
#include "xfce4-cpufreq-plugin.h"
#include "xfce4-cpufreq-utils.h"
+
+
gchar*
cpufreq_get_human_readable_freq (guint freq)
{
- guint div;
- gchar *readable_freq, *freq_unit;
+ guint div;
+ gchar *readable_freq, *freq_unit;
+
+ if (freq > 999999)
+ {
+ div = (1000 * 1000);
+ freq_unit = g_strdup ("GHz");
+ }
+ else
+ {
+ div = 1000;
+ freq_unit = g_strdup ("MHz");
+ }
+
+ if ((freq % div) == 0 || div == 1000)
+ readable_freq = g_strdup_printf ("%d %s", (freq/div), freq_unit);
+ else
+ readable_freq = g_strdup_printf ("%3.2f %s", ((gfloat)freq/div), freq_unit);
- if (freq > 999999)
- {
- div = (1000 * 1000);
- freq_unit = g_strdup ("GHz");
- }
- else
- {
- div = 1000;
- freq_unit = g_strdup ("MHz");
- }
-
- if ((freq % div) == 0 || div == 1000)
- readable_freq = g_strdup_printf ("%d %s", (freq/div), freq_unit);
- else
- readable_freq = g_strdup_printf ("%3.2f %s", ((gfloat)freq/div), freq_unit);
+ g_free (freq_unit);
- g_free (freq_unit);
- return readable_freq;
+ return readable_freq;
}
+
+
guint
cpufreq_get_normal_freq (const gchar *freq)
{
- guint result;
- gchar **tokens;
+ guint result;
+ gchar **tokens;
+
+ tokens = g_strsplit (freq, " ", 0);
- tokens = g_strsplit (freq, " ", 0);
+ if (g_ascii_strcasecmp (tokens[1], "GHz") == 0)
+ result = (guint) (atof (tokens[0]) * 1000 * 1000);
+ else
+ result = (guint) (atof (tokens[0]) * 1000);
- if (g_ascii_strcasecmp (tokens[1], "GHz") == 0)
- result = (guint)(atof (tokens[0]) * 1000 * 1000);
- else
- result = (guint)(atof (tokens[0]) * 1000);
+ g_strfreev (tokens);
- g_strfreev (tokens);
- return result;
+ return result;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list