[Xfce4-commits] [panel-plugins/xfce4-cpufreq-plugin] 03/03: Refactor label resize code.

noreply at xfce.org noreply at xfce.org
Mon Dec 22 18:51:20 CET 2014


This is an automated email from the git hooks/post-receive script.

hjudt pushed a commit to branch master
in repository panel-plugins/xfce4-cpufreq-plugin.

commit 2bbda87299fec4a10869de0f0a78d65756c02542
Author: Harald Judt <h.judt at gmx.at>
Date:   Mon Dec 22 17:13:14 2014 +0100

    Refactor label resize code.
---
 panel-plugin/xfce4-cpufreq-configure.c |   12 ++++-------
 panel-plugin/xfce4-cpufreq-linux.c     |    2 +-
 panel-plugin/xfce4-cpufreq-plugin.c    |   35 +++++++++++++++++++-------------
 panel-plugin/xfce4-cpufreq-plugin.h    |    2 +-
 4 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/panel-plugin/xfce4-cpufreq-configure.c b/panel-plugin/xfce4-cpufreq-configure.c
index 125bec0..895166f 100644
--- a/panel-plugin/xfce4-cpufreq-configure.c
+++ b/panel-plugin/xfce4-cpufreq-configure.c
@@ -66,8 +66,7 @@ check_button_changed (GtkWidget *button, CpuFreqPluginConfigure *configure)
 		gtk_widget_set_sensitive (configure->display_icon, TRUE);
 
 	cpufreq_update_icon (cpuFreq);
-	cpuFreq->layout_changed = TRUE;
-	cpufreq_update_plugin ();
+	cpufreq_update_plugin (TRUE);
 }
 
 static void
@@ -83,11 +82,8 @@ button_fontname_update(GtkWidget *button,
 		gtk_widget_set_tooltip_text
 			(button, _("Right-click to revert to the default font."));
 	}
-	if (update_plugin) {
-		cpufreq_label_set_font ();
-		cpuFreq->layout_changed = TRUE;
-		cpufreq_update_plugin ();
-	}
+	if (update_plugin)
+		cpufreq_update_plugin (TRUE);
 }
 
 static gboolean
@@ -146,7 +142,7 @@ combo_changed (GtkWidget *combo, CpuFreqPluginConfigure *configure)
 	if (GTK_WIDGET (combo) == configure->combo_cpu)
 	{
 		cpuFreq->options->show_cpu = selected;
-		cpufreq_update_plugin ();
+		cpufreq_update_plugin (TRUE);
 	}
 }
 
diff --git a/panel-plugin/xfce4-cpufreq-linux.c b/panel-plugin/xfce4-cpufreq-linux.c
index 23fbcef..e1a40bf 100644
--- a/panel-plugin/xfce4-cpufreq-linux.c
+++ b/panel-plugin/xfce4-cpufreq-linux.c
@@ -449,7 +449,7 @@ cpufreq_update_cpus (gpointer data)
 		return FALSE;
 	}
 
-	return cpufreq_update_plugin ();
+	return cpufreq_update_plugin (FALSE);
 }
 
 gboolean
diff --git a/panel-plugin/xfce4-cpufreq-plugin.c b/panel-plugin/xfce4-cpufreq-plugin.c
index ae36c90..b31218e 100644
--- a/panel-plugin/xfce4-cpufreq-plugin.c
+++ b/panel-plugin/xfce4-cpufreq-plugin.c
@@ -156,14 +156,20 @@ cpufreq_update_label (CpuInfo *cpu)
 			if (label_size.height < cpuFreq->label_max_width)
 				gtk_widget_set_size_request (GTK_WIDGET (cpuFreq->label),
 											 -1, cpuFreq->label_max_width);
-			else
+			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
-				cpuFreq->label_max_width = label_size.width;
+			else {
+				if (label_size.width > cpuFreq->label_max_width)
+					cpuFreq->label_max_width = label_size.width;
+				cpuFreq->layout_changed = TRUE;
+			}
 	}
 	else
 	{
@@ -186,10 +192,6 @@ cpufreq_widgets_layout (void)
 						   !cpuFreq->options->show_label_governor);
 	gint pos = 1, lw = 0, lh = 0, iw = 0, ih = 0;
 
-	/* reset label max width on layout changes */
-	cpuFreq->label_max_width = -1;
-	gtk_widget_set_size_request (GTK_WIDGET (cpuFreq->label), -1, -1);
-
 	/* keep plugin small if label is hidden or user requested compact size */
 	small = (hide_label ? TRUE : cpuFreq->options->keep_compact);
 
@@ -301,12 +303,19 @@ cpufreq_current_cpu ()
 }
 
 gboolean
-cpufreq_update_plugin (void)
+cpufreq_update_plugin (gboolean reset_label_size)
 {
 	CpuInfo *cpu;
 	gboolean ret;
 
 	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;
+	}
+
 	ret = cpufreq_update_label (cpu);
 
 	if (cpuFreq->layout_changed) {
@@ -382,8 +391,7 @@ cpufreq_mode_changed (XfcePanelPlugin *plugin, XfcePanelPluginMode mode, CpuFreq
 {
 	cpuFreq->panel_mode = mode;
 	cpuFreq->panel_rows = xfce_panel_plugin_get_nrows (plugin);
-	cpuFreq->layout_changed = TRUE;
-	cpufreq_update_plugin ();
+	cpufreq_update_plugin (TRUE);
 }
 
 void
@@ -461,7 +469,7 @@ cpufreq_widgets (void)
 	gtk_widget_show (cpuFreq->box);
 	gtk_widget_show (cpuFreq->button);
 
-	cpufreq_update_plugin ();
+	cpufreq_update_plugin (TRUE);
 }
 
 static void
@@ -570,10 +578,9 @@ cpufreq_set_size (XfcePanelPlugin *plugin, gint size, CpuFreqPlugin *cpufreq)
 {
 	cpuFreq->panel_size = size;
 	cpuFreq->panel_rows = xfce_panel_plugin_get_nrows (plugin);
-	cpuFreq->label_max_width = -1;
-	cpuFreq->layout_changed = TRUE;
+
 	cpufreq_update_icon (cpufreq);
-	cpufreq_update_plugin ();
+	cpufreq_update_plugin (TRUE);
 
 	return TRUE;
 }
diff --git a/panel-plugin/xfce4-cpufreq-plugin.h b/panel-plugin/xfce4-cpufreq-plugin.h
index d69a37a..e610f53 100644
--- a/panel-plugin/xfce4-cpufreq-plugin.h
+++ b/panel-plugin/xfce4-cpufreq-plugin.h
@@ -101,7 +101,7 @@ void
 cpufreq_label_set_font (void);
 
 gboolean
-cpufreq_update_plugin (void);
+cpufreq_update_plugin (gboolean reset_label_size);
 
 void
 cpufreq_restart_timeout (void);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list