[Xfce4-commits] [panel-plugins/xfce4-cpufreq-plugin] 01/01: Add option to configure text color bug #13565

noreply at xfce.org noreply at xfce.org
Fri Jun 9 03:42:23 CEST 2017


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 3c76cd9806638eab2a7d04714eb9c93dcb9a55dd
Author: Andre Miranda <andre42m at gmail.com>
Date:   Thu Jun 8 22:41:31 2017 -0300

    Add option to configure text color bug #13565
    
    Thanks to Armando Ortega
---
 panel-plugin/xfce4-cpufreq-configure.c | 32 ++++++++++++++++++++++++++++
 panel-plugin/xfce4-cpufreq-configure.h |  1 +
 panel-plugin/xfce4-cpufreq-plugin.c    | 38 +++++++++++++++++++++++++++-------
 panel-plugin/xfce4-cpufreq-plugin.h    |  1 +
 4 files changed, 65 insertions(+), 7 deletions(-)

diff --git a/panel-plugin/xfce4-cpufreq-configure.c b/panel-plugin/xfce4-cpufreq-configure.c
index d7c1cb5..52bff99 100644
--- a/panel-plugin/xfce4-cpufreq-configure.c
+++ b/panel-plugin/xfce4-cpufreq-configure.c
@@ -138,6 +138,17 @@ button_fontname_pressed(GtkWidget *button,
 }
 
 static void
+button_fontcolor_clicked (GtkWidget *button, void *data)
+{
+	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);
+}
+
+static void
 combo_changed (GtkWidget *combo, CpuFreqPluginConfigure *configure)
 {
 	guint selected = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
@@ -179,6 +190,7 @@ cpufreq_configure (XfcePanelPlugin *plugin)
 	GtkWidget *combo, *spinner, *button;
 	GtkSizeGroup *sg0;
 	CpuFreqPluginConfigure *configure;
+	GdkRGBA *color;
 
 	configure = g_new0 (CpuFreqPluginConfigure, 1);
 
@@ -287,6 +299,26 @@ cpufreq_configure (XfcePanelPlugin *plugin)
 					  G_CALLBACK (button_fontname_pressed), configure);
 	button_fontname_update (button, FALSE);
 
+	/* font color */
+	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BORDER);
+	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, BORDER);
 	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
diff --git a/panel-plugin/xfce4-cpufreq-configure.h b/panel-plugin/xfce4-cpufreq-configure.h
index 3ea3f43..4f7608b 100644
--- a/panel-plugin/xfce4-cpufreq-configure.h
+++ b/panel-plugin/xfce4-cpufreq-configure.h
@@ -34,6 +34,7 @@ typedef struct
 	GtkWidget *keep_compact;
 	GtkWidget *one_line;
 	GtkWidget *fontname;
+	GtkWidget *fontcolor;
 } CpuFreqPluginConfigure;
 
 G_BEGIN_DECLS
diff --git a/panel-plugin/xfce4-cpufreq-plugin.c b/panel-plugin/xfce4-cpufreq-plugin.c
index 1f9e818..faca060 100644
--- a/panel-plugin/xfce4-cpufreq-plugin.c
+++ b/panel-plugin/xfce4-cpufreq-plugin.c
@@ -100,7 +100,7 @@ cpufreq_cpus_calc_max (void)
 void
 cpufreq_label_set_font (void)
 {
-	gchar *css;
+	gchar *css = NULL, *css_font = NULL, *css_color = NULL;
 	GtkCssProvider *provider;
 	PangoFontDescription *font;
 
@@ -111,23 +111,39 @@ cpufreq_label_set_font (void)
 	{
 		font = pango_font_description_from_string(cpuFreq->options->fontname);
 
-		css = g_strdup_printf("label { font-family: %s; font-size: %dpx; font-style: %s; font-weight: %s }",
+		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_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 (provider),
 			GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
-		g_free(css);
 	}
+
+	g_free (css);
+	g_free (css_font);
+	g_free (css_color);
 }
 
 gboolean
@@ -546,6 +562,12 @@ cpufreq_read_config (void)
 		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);
 }
 
@@ -573,6 +595,8 @@ cpufreq_write_config (XfcePanelPlugin *plugin)
 	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);
 }
diff --git a/panel-plugin/xfce4-cpufreq-plugin.h b/panel-plugin/xfce4-cpufreq-plugin.h
index 30308d1..f6c6c0e 100644
--- a/panel-plugin/xfce4-cpufreq-plugin.h
+++ b/panel-plugin/xfce4-cpufreq-plugin.h
@@ -61,6 +61,7 @@ typedef struct
 	gboolean keep_compact;
 	gboolean one_line;
 	gchar   *fontname;
+	gchar   *fontcolor;
 } CpuFreqPluginOptions;
 
 typedef struct

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


More information about the Xfce4-commits mailing list