From 8274eada48315a4d37acf5e64b359f26b6d7c19d Mon Sep 17 00:00:00 2001 From: Armando Date: Thu, 8 Jun 2017 21:18:17 +0200 Subject: [PATCH] Add option to configure text color bug #13565 --- panel-plugin/xfce4-cpufreq-configure.c | 41 ++++++++++++++++++++++++++++++++++ panel-plugin/xfce4-cpufreq-configure.h | 1 + panel-plugin/xfce4-cpufreq-plugin.c | 24 ++++++++++++++++++-- panel-plugin/xfce4-cpufreq-plugin.h | 1 + 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/panel-plugin/xfce4-cpufreq-configure.c b/panel-plugin/xfce4-cpufreq-configure.c index d7c1cb5..4db6607 100644 --- a/panel-plugin/xfce4-cpufreq-configure.c +++ b/panel-plugin/xfce4-cpufreq-configure.c @@ -138,6 +138,22 @@ button_fontname_pressed(GtkWidget *button, } static void +button_fontcolor_clicked(GtkWidget *button, + CpuFreqPluginConfigure *configure); + +static void +button_fontcolor_clicked(GtkWidget *button, + CpuFreqPluginConfigure *configure) +{ + GdkRGBA *color=malloc(sizeof(GdkRGBA));; + + 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 +195,7 @@ cpufreq_configure (XfcePanelPlugin *plugin) GtkWidget *combo, *spinner, *button; GtkSizeGroup *sg0; CpuFreqPluginConfigure *configure; + GdkRGBA *color; configure = g_new0 (CpuFreqPluginConfigure, 1); @@ -287,6 +304,30 @@ 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 = malloc(sizeof(GdkRGBA)); + if(cpuFreq->options->fontcolor){ + gdk_rgba_parse(color, cpuFreq->options->fontcolor); + } else { + gdk_rgba_parse(color, "#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 (G_OBJECT (button), "color-set", + G_CALLBACK (button_fontcolor_clicked), configure); + 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..5449a5b 100644 --- a/panel-plugin/xfce4-cpufreq-plugin.c +++ b/panel-plugin/xfce4-cpufreq-plugin.c @@ -111,12 +111,25 @@ 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 = g_strdup_printf("label { font-family: %s; font-size: %dpx; font-style: %s; font-weight: %s; color: %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_weight(font) >= PANGO_WEIGHT_BOLD) ? "bold" : "normal", + cpuFreq->options->fontcolor); + pango_font_description_free (font); + + 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); + } else if(cpuFreq->options->fontcolor){ + css = g_strdup_printf("label { color: %s }",cpuFreq->options->fontcolor); pango_font_description_free (font); provider = gtk_css_provider_new (); @@ -545,6 +558,11 @@ cpufreq_read_config (void) 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); } @@ -573,6 +591,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 -- 2.13.0