From 32cf3bae0769015a096ae5428726e58e1b56e2d7 Mon Sep 17 00:00:00 2001 From: Landry Breuil Date: Sat, 14 May 2016 15:43:18 +0200 Subject: [PATCH] Add set_label/progressbar_csscolor helpers to deal with various Gtk versions Right now passing NULL to set_label_csscolor should reset the color to default black but that doesn't work --- panel-plugin/netload.c | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/panel-plugin/netload.c b/panel-plugin/netload.c index 5813f6c..88ad39a 100644 --- a/panel-plugin/netload.c +++ b/panel-plugin/netload.c @@ -509,6 +509,56 @@ static t_global_monitor * monitor_new(XfcePanelPlugin *plugin) return global; } +/* ---------------------------------------------------------------------------------------------- */ +static void set_label_csscolor(GtkWidget* label, GdkRGBA* color) +{ + GtkCssProvider *css_provider; + gchar * css; + if (color != NULL) + { +#if GTK_CHECK_VERSION (3, 20, 0) + css = g_strdup_printf("label { color: %s; }", +#else + css = g_strdup_printf(".label { color: %s; }", +#endif + gdk_rgba_to_string(color)); + } + else + { + css = g_strdup_printf(".label { color: black; }"); + } + css_provider = gtk_css_provider_new (); + gtk_css_provider_load_from_data (css_provider, css, strlen(css), NULL); + g_free(css); + + DBG("setting label css: %s", gtk_css_provider_to_string (css_provider)); + gtk_style_context_add_provider ( + GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (label))), + GTK_STYLE_PROVIDER (css_provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + +} + +/* ---------------------------------------------------------------------------------------------- */ +static void set_progressbar_csscolor(GtkWidget* pbar, GdkRGBA* color) +{ + GtkCssProvider *css_provider; + gchar * css; +#if GTK_CHECK_VERSION (3, 20, 0) + css = g_strdup_printf("progressbar progress { background-color: %s; background-image: none; }", +#else + css = g_strdup_printf(".progressbar { background-color: %s; background-image: none; }", +#endif + gdk_rgba_to_string(color)); + DBG("setting pbar css to %s", css); + css_provider = gtk_css_provider_new (); + gtk_css_provider_load_from_data (css_provider, css, strlen(css), NULL); + g_free(css); + gtk_style_context_add_provider ( + GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (pbar))), + GTK_STYLE_PROVIDER (css_provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); +} /* ---------------------------------------------------------------------------------------------- */ static void setup_monitor(t_global_monitor *global, gboolean supress_warnings)