[Xfce4-commits] [panel-plugins/xfce4-verve-plugin] 04/05: Use CSS to customize background and foreground colors

noreply at xfce.org noreply at xfce.org
Wed Nov 22 23:38:36 CET 2017


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

i   s   a   a   c   s   c   h   e   m   m       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       i   s   a   a   c   s   c   h   e   m   m   /   g   t   k   3   
   in repository panel-plugins/xfce4-verve-plugin.

commit 261ff4207eee84f5e1c579012f935861e82834e3
Author: Isaac Schemm <isaacschemm at gmail.com>
Date:   Fri Nov 17 19:56:56 2017 -0600

    Use CSS to customize background and foreground colors
---
 panel-plugin/verve-plugin.c | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/panel-plugin/verve-plugin.c b/panel-plugin/verve-plugin.c
index ab5047f..73691ad 100644
--- a/panel-plugin/verve-plugin.c
+++ b/panel-plugin/verve-plugin.c
@@ -54,9 +54,11 @@ typedef struct
   GtkWidget        *event_box;
   GtkWidget        *label;
   GtkWidget        *input;
+  
   gchar            *fg_color_str;
   gchar            *bg_color_str;
   gchar            *base_color_str;
+  GtkCssProvider   *input_css;
   
   /* Command history */
   GList            *history_current;
@@ -538,6 +540,10 @@ verve_plugin_new (XfcePanelPlugin *plugin)
   gtk_widget_show (verve->input);
   gtk_container_add (GTK_CONTAINER (hbox), verve->input);
 
+  /* Set up a CSS provider for the entry */
+  verve->input_css = gtk_css_provider_new ();
+  gtk_style_context_add_provider (gtk_widget_get_style_context (verve->input), verve->input_css, GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
+
   /* Handle mouse button and key press events */
   g_signal_connect (verve->input, "key-press-event", G_CALLBACK (verve_plugin_keypress_cb), verve);
   g_signal_connect (verve->input, "button-press-event", G_CALLBACK (verve_plugin_buttonpress_cb), verve);
@@ -628,6 +634,18 @@ verve_plugin_update_label (XfcePanelPlugin *plugin,
 
 
 static gboolean
+write_string (GOutputStream *output_stream,
+              const gchar   *str1,
+              const gchar   *str2)
+{
+  gsize bytes_written;
+  const char* str = str1 && str1[0] ? str1 : str2;
+  return g_output_stream_write_all (output_stream, str, strlen (str), &bytes_written, NULL, NULL);
+}
+
+
+
+static gboolean
 verve_plugin_update_colors (XfcePanelPlugin *plugin,
                             const gchar     *fg_color_str,
                             const gchar     *bg_color_str,
@@ -636,25 +654,41 @@ verve_plugin_update_colors (XfcePanelPlugin *plugin,
 {
   g_return_val_if_fail (verve != NULL, FALSE);
 
-  GdkColor c;
+  GFileIOStream *tmp_file_stream;
+  GFile *tmp_file = g_file_new_tmp (NULL, &tmp_file_stream, NULL);
+  GOutputStream *output_stream = g_io_stream_get_output_stream (tmp_file_stream);
+
+  // Write CSS to temporary file
+  write_string (output_stream, "*{color:", "");
   if (fg_color_str) {
     if (verve->fg_color_str) {
       g_free (verve->fg_color_str);
     }
     verve->fg_color_str = g_strdup (fg_color_str);
   }
+  write_string (output_stream, verve->fg_color_str, "unset");
   if (bg_color_str) {
     if (verve->bg_color_str) {
       g_free (verve->bg_color_str);
     }
     verve->bg_color_str = g_strdup (bg_color_str);
   }
+  write_string (output_stream, ";background-color:", "");
   if (base_color_str) {
     if (verve->base_color_str) {
       g_free (verve->base_color_str);
     }
     verve->base_color_str = g_strdup (base_color_str);
   }
+  write_string (output_stream, verve->base_color_str, "unset");
+  write_string (output_stream, "}", "");
+
+  g_io_stream_close (tmp_file_stream, NULL, NULL);
+
+  gtk_css_provider_load_from_file (verve->input_css, tmp_file, NULL);
+  g_file_delete (tmp_file, NULL, NULL);
+
+  g_object_unref (tmp_file);
 
   return TRUE;
 }

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


More information about the Xfce4-commits mailing list