[Xfce4-commits] [panel-plugins/xfce4-cpugraph-plugin] 01/01: Use css to change bar colors (Bug #15186)

noreply at xfce.org noreply at xfce.org
Sat Jun 22 18:05:28 CEST 2019


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-cpugraph-plugin.

commit 739df2586d5d413e0a0e94d7a22018d1175f02ca
Author: Andre Miranda <andreldm at xfce.org>
Date:   Sat Jun 22 13:01:25 2019 -0300

    Use css to change bar colors (Bug #15186)
---
 panel-plugin/cpu.c | 48 ++++++++++++++++++++++++++++--------------------
 panel-plugin/cpu.h |  1 +
 2 files changed, 29 insertions(+), 20 deletions(-)

diff --git a/panel-plugin/cpu.c b/panel-plugin/cpu.c
index 30594e5..6d36797 100644
--- a/panel-plugin/cpu.c
+++ b/panel-plugin/cpu.c
@@ -50,6 +50,7 @@ static void       set_bars_size        (CPUGraph           *base,
 static void       mode_cb              (XfcePanelPlugin    *plugin,
                                         XfcePanelPluginMode mode,
                                         CPUGraph           *base);
+static void       set_bars_color       (CPUGraph           *base);
 static void       set_bars_orientation (CPUGraph           *base,
                                         GtkOrientation      orientation);
 static gboolean   update_cb            (CPUGraph           *base);
@@ -132,6 +133,13 @@ create_gui (XfcePanelPlugin *plugin)
     base->tooltip_text = gtk_label_new (NULL);
     g_object_ref (base->tooltip_text);
 
+    base->css_provider = gtk_css_provider_new ();
+    gtk_style_context_add_provider_for_screen (
+            gtk_widget_get_screen (GTK_WIDGET (plugin)),
+            GTK_STYLE_PROVIDER (base->css_provider),
+            GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+    g_object_unref (base->css_provider);
+
     return base;
 }
 
@@ -175,18 +183,13 @@ create_bars (CPUGraph *base)
     for (i = 0; i < n; i++)
     {
         base->bars[i] = GTK_WIDGET (gtk_progress_bar_new ());
-        /* Set bar colors */
-        if (base->has_barcolor) {
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-            gtk_widget_override_background_color (base->bars[i], GTK_STATE_PRELIGHT, &base->colors[4]);
-            gtk_widget_override_background_color (base->bars[i], GTK_STATE_SELECTED, &base->colors[4]);
-            gtk_widget_override_color (base->bars[i], GTK_STATE_SELECTED, &base->colors[4]);
-G_GNUC_END_IGNORE_DEPRECATIONS
-        }
-
         gtk_box_pack_end (GTK_BOX (base->box), base->bars[i], FALSE, FALSE, 0);
         gtk_widget_show (base->bars[i]);
     }
+
+    if (base->has_barcolor) {
+        set_bars_color (base);
+    }
 }
 
 guint
@@ -309,6 +312,21 @@ mode_cb (XfcePanelPlugin *plugin, XfcePanelPluginMode mode, CPUGraph *base)
 }
 
 static void
+set_bars_color (CPUGraph *base)
+{
+    gchar *color = gdk_rgba_to_string (&base->colors[4]);
+    gchar *css = g_strdup_printf ("progressbar progress { \
+                                    background-color: %1$s; \
+                                    background-image: none; \
+                                    border-color: darker (%1$s)}", color);
+
+    gtk_css_provider_load_from_data (base->css_provider, css, strlen(css), NULL);
+
+    g_free (color);
+    g_free (css);
+}
+
+static void
 set_bars_orientation (CPUGraph *base, GtkOrientation orientation)
 {
     guint i, n;
@@ -560,17 +578,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
 
     if (number == 4 && base->has_bars && base->has_barcolor)
     {
-        n = nb_bars (base);
-
-        for (i = 0; i < n; i++)
-        {
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-            /* Set bar colors */
-            gtk_widget_override_background_color (base->bars[i], GTK_STATE_PRELIGHT, &base->colors[4]);
-            gtk_widget_override_background_color (base->bars[i], GTK_STATE_SELECTED, &base->colors[4]);
-            gtk_widget_override_color (base->bars[i], GTK_STATE_SELECTED, &base->colors[4]);
-G_GNUC_END_IGNORE_DEPRECATIONS
-        }
+        set_bars_color (base);
     }
 }
 
diff --git a/panel-plugin/cpu.h b/panel-plugin/cpu.h
index c49a751..4a76184 100644
--- a/panel-plugin/cpu.h
+++ b/panel-plugin/cpu.h
@@ -67,6 +67,7 @@ typedef struct
     guint *history;
     gssize history_size;
     CpuData *cpu_data;
+    GtkCssProvider *css_provider;
 } CPUGraph;
 
 void set_startup_notification (CPUGraph *base, gboolean startup_notification);

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


More information about the Xfce4-commits mailing list