[Xfce4-commits] [panel-plugins/xfce4-netload-plugin] 21/27: Add set_label/progressbar_csscolor helpers to deal with various Gtk versions

noreply at xfce.org noreply at xfce.org
Sat May 14 15:54:11 CEST 2016


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

landry pushed a commit to branch master
in repository panel-plugins/xfce4-netload-plugin.

commit 32cf3bae0769015a096ae5428726e58e1b56e2d7
Author: Landry Breuil <landry at xfce.org>
Date:   Sat May 14 15:43:18 2016 +0200

    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)

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


More information about the Xfce4-commits mailing list