Updating branch refs/heads/master
         to 5e59d5eafb9e91135160fd5ecb47c5a33a136556 (commit)
       from 3b5e6b2d49e34c4889a3869e4960ce76da6e8477 (commit)

commit 5e59d5eafb9e91135160fd5ecb47c5a33a136556
Author: Mike Massonnet <[email protected]>
Date:   Tue Mar 12 16:35:40 2013 +0100

    gtk3: Added theming support through GtkCssProvider
    
    Added a custom CSS file that is installed system-wide and contains
    modifications on top of the Adwaita theme to look monochrome with a
    customizable background color set within xfconf.
    
    Reading the default background color from GTK+ is not supported yet.
    
    Splitted color.c,h,vapi in two sections inside ext-gdk.c,h,vapi and
    theme-gtkrc.c,h,vapi. The source theme-gtkrc is used for GTK+2 and
    theme-gtkcss for GTK+3.

 data/gtk-3.0/gtk-main.css      |   37 +++++++++
 lib/Makefile.am                |   20 ++++-
 lib/application.vala           |    9 +-
 lib/color.c                    |  174 ----------------------------------------
 lib/color.vapi                 |    7 --
 lib/ext-gdk.c                  |   80 ++++++++++++++++++
 lib/{color.h => ext-gdk.h}     |   15 +---
 lib/ext-gdk.vapi               |    5 +
 lib/theme-gtkcss.vala          |   50 ++++++++++++
 lib/theme-gtkrc.c              |  102 +++++++++++++++++++++++
 lib/{popup.h => theme-gtkrc.h} |   19 ++---
 lib/theme-gtkrc.vapi           |    7 ++
 lib/{popup.h => theme.vala}    |   30 +++++---
 src/Makefile.am                |    5 +-
 src/main-settings-dialog.c     |    2 +-
 15 files changed, 334 insertions(+), 228 deletions(-)

diff --git a/data/gtk-3.0/gtk-main.css b/data/gtk-3.0/gtk-main.css
new file mode 100644
index 0000000..f0be8b7
--- /dev/null
+++ b/data/gtk-3.0/gtk-main.css
@@ -0,0 +1,37 @@
+@define-color theme_base_color @notes_bg_color;
+@define-color theme_text_color shade (@theme_base_color, 0.4);
+@define-color theme_bg_color @theme_base_color;
+@define-color theme_fg_color shade (@theme_base_color, 0.3);
+@define-color theme_selected_bg_color shade (@theme_base_color, 0.8);
+@define-color theme_selected_fg_color shade (@theme_base_color, 1.4);
+@define-color insensitive_fg_color shade (@theme_fg_color, 1.8);
+@define-color insensitive_bg_color shade (@theme_bg_color, 1.1);
+
+@define-color borders shade (@theme_base_color, 0.8);
+@define-color frame_color shade (@theme_base_color, 0.8);
+@define-color notebook_active_tab_border shade (@theme_base_color, 1.1);
+@define-color notebook_selected_tab_color shade (@theme_base_color, 0.9);
+
+GtkWindow {
+       background-image: linear-gradient(to bottom,
+                                         shade (@theme_base_color, 0.8),
+                                         shade (@theme_base_color, 0.95) 87px);
+}
+
+.button {
+       background-color: transparent;
+}
+
+.button *:active {
+        color: darker (@theme_fg_color);
+        text-shadow: 1 1 lighter (@theme_bg_color);
+}
+
+.tooltip {
+       border-style: solid;
+       border-width: 1px;
+       border-color: lighter (@theme_fg_color);
+       color: darker (@theme_fg_color);
+       text-shadow: 1 1 lighter (@theme_bg_color);
+}
+
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 498ee59..118582a 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -5,7 +5,6 @@ libnotes_la_VALAFLAGS =                                         
        \
        --header=libnotes.h                                             \
        --vapidir=$(srcdir)                                             \
        --pkg=config                                                    \
-       --pkg=color                                                     \
        --pkg=libxfconf-0                                               \
        --pkg=libxfce4util-1.0
 
@@ -15,6 +14,8 @@ libnotes_la_VALAFLAGS +=                                      
        \
        --pkg=gtk+-3.0
 else
 libnotes_la_VALAFLAGS +=                                               \
+       --pkg=ext-gdk                                                   \
+       --pkg=theme-gtkrc                                               \
        --pkg=gtk+-2.0
 endif
 
@@ -25,11 +26,16 @@ libnotes_la_SOURCES =                                       
                \
        hypertextview.vala                                              \
        note.vala                                                       \
        window.vala                                                     \
-       color.c
+       theme.vala
 
-if !ENABLE_GTK3
+if ENABLE_GTK3
 libnotes_la_SOURCES +=                                                 \
-       popup.c
+       theme-gtkcss.vala
+else
+libnotes_la_SOURCES +=                                                 \
+       popup.c                                                         \
+       ext-gdk.c                                                       \
+       theme-gtkrc.c
 endif
 
 libnotes_la_CFLAGS =                                                   \
@@ -50,13 +56,17 @@ libnotes_la_LIBADD =                                        
                \
        @XFCONF_LIBS@
 
 EXTRA_DIST =                                                           \
-       color.h                                                         \
+       ext-gdk.h                                                       \
+       theme-gtkrc.h                                                   \
        popup.h                                                         \
        libnotes.vapi                                                   \
        libnotes.h
 
 if ENABLE_GTK3
 EXTRA_DIST +=                                                          \
+       ext-gdk.c                                                       \
+       theme-gtkrc.c                                                   \
        popup.c
+else
 endif
 
diff --git a/lib/application.vala b/lib/application.vala
index caeccba..243f80e 100644
--- a/lib/application.vala
+++ b/lib/application.vala
@@ -31,9 +31,7 @@ namespace Xnp {
                private Xfconf.Channel xfconf_channel;
 
                construct {
-#if ENABLE_GTK3
-                       // TODO use GtkCssProvider
-#else
+#if !ENABLE_GTK3
                        var notesgtkrc = "%s/xfce4/xfce4-notes.gtkrc".printf 
(GLib.Environment.get_user_config_dir ());
                        Gtk.rc_parse (notesgtkrc);
 #endif
@@ -148,13 +146,14 @@ namespace Xnp {
                        string color = xfconf_channel.get_string 
("/global/background-color", "#F7EB96");
                        if (color == "GTK+") {
 #if ENABLE_GTK3
-                               // TODO use GtkStyleContext
+                               // TODO: Read from StyleContext with default 
CssProvider
+                               return;
 #else
                                var style_widget = new Gtk.Invisible ();
                                color = style_widget.get_style 
().bg[Gtk.StateType.NORMAL].to_string ();
 #endif
                        }
-                       Xnp.Color.set_background (color);
+                       Xnp.Theme.set_background_color (color);
                }
 
                private void quit () {
diff --git a/lib/color.c b/lib/color.c
deleted file mode 100644
index f8306b7..0000000
--- a/lib/color.c
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- *  Notes - panel plugin for Xfce Desktop Environment
- *  Copyright (C) 2009-2010  Mike Massonnet <[email protected]>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef HAVE_MATH_H
-#include <math.h>
-#endif
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#include <glib.h>
-#include <gdk/gdk.h>
-#include <gtk/gtk.h>
-
-#include "color.h"
-
-#define RC_STYLE \
-  "gtk_color_scheme = 
\"notes_fg_color:#xxxxxxxxxxxx\\nnotes_bg_color:#xxxxxxxxxxxx\\nnotes_base_color:#xxxxxxxxxxxx\\nnotes_text_color:#xxxxxxxxxxxx\\nnotes_selected_bg_color:#xxxxxxxxxxxx\\nnotes_selected_fg_color:#xxxxxxxxxxxx\"\n"
 \
-  "include \"" PKGDATADIR "/gtk-2.0/notes.gtkrc\""
-
-void
-color_set_background (const gchar *background)
-{
-  GdkColor color, *color2;
-  gchar *notesrc_file;
-  gchar *bg;
-  gchar *text;
-  gchar *selected;
-  gchar rc_style[] = RC_STYLE;
-  gchar *offset;
-
-  if (!gdk_color_parse (background, &color))
-    return;
-
-  /* bg */
-  bg = gdk_color_to_string (&color);
-
-  /* text */
-  color2 = gdk_color_copy (&color);
-  __gdk_color_contrast (color2, 5.);
-  text = gdk_color_to_string (color2);
-  gdk_color_free (color2);
-
-  /* selected */
-  color2 = gdk_color_copy (&color);
-  __gdk_color_contrast (color2, 3.2);
-  selected = gdk_color_to_string (color2);
-  gdk_color_free (color2);
-
-  /* notes_fg_color */
-  offset = rc_style + 35;
-  memcpy (offset, bg, 13);
-
-  /* notes_bg_color */
-  offset += 30;
-  memcpy (offset, text, 13);
-
-  /* notes_base_color */
-  offset += 32;
-  memcpy (offset, bg, 13);
-
-  /* notes_text_color */
-  offset += 32;
-  memcpy (offset, text, 13);
-
-  /* notes_selected_bg_color */
-  offset += 39;
-  memcpy (offset, selected, 13);
-
-  /* notes_selected_fg_color */
-  offset += 39;
-  memcpy (offset, bg, 13);
-
-  /* set the rc style */
-  notesrc_file = g_strdup_printf ("%s/xfce4/xfce4-notes.gtkrc", 
g_get_user_config_dir ());
-  g_file_set_contents (notesrc_file, rc_style, -1, NULL);
-
-  gtk_rc_reparse_all ();
-
-  g_free (notesrc_file);
-  g_free (bg);
-  g_free (text);
-  g_free (selected);
-}
-
-void
-__gdk_color_contrast (GdkColor *color,
-                      gdouble contrast)
-{
-  /* cf. http://accessibility.kde.org/hsl-adjusted.php */
-  gdouble N_r, N_g, N_b;
-  gdouble f_r = 0.2125, f_g = 0.7154, f_b = 0.0721;
-  gdouble L, L_, m, D, D_;
-  gdouble N__1, N_0, N_1;
-  gdouble N_r_, N_g_, N_b_;
-
-  g_return_if_fail (G_LIKELY (contrast >= 1 && contrast <= 21));
-
-  /* Calculate luminosity */
-  N_r = pow ((gdouble)color->red / G_MAXUINT16, 2.2);
-  N_g = pow ((gdouble)color->green / G_MAXUINT16, 2.2);
-  N_b = pow ((gdouble)color->blue / G_MAXUINT16, 2.2);
-
-  L = f_r * N_r + f_g * N_g + f_b * N_b;
-
-  /* Change luminosity */
-  L_ = (L + 0.05) / contrast - 0.05;
-
-  N__1 = MIN (N_r, MIN (N_g, N_b));
-  N_1 = MAX (N_r, MAX (N_g, N_b));
-  if (N_r > N__1 && N_r < N_1)
-    N_0 = N_r;
-  else if (N_g > N__1 && N_g < N_1)
-    N_0 = N_g;
-  else if (N_b > N__1 && N_b < N_1)
-    N_0 = N_b;
-  else
-    N_0 = N_1;
-
-  m = f_g + f_r * (N_0 - N__1) / (N_1 - N__1);
-  D = MIN (L / m, (1 - L) / (1 - m));
-  D_ = MIN (L_ / m, (1 - L_) / (1 - m));
-
-  N_r_ = L_ + (N_r - L) * D_ / D;
-  N_g_ = L_ + (N_g - L) * D_ / D;
-  N_b_ = L_ + (N_b - L) * D_ / D;
-
-  /* Conversion to RGB */
-  color->red   = G_MAXUINT16 * pow (N_r_, 1 / 2.2);
-  color->green = G_MAXUINT16 * pow (N_g_, 1 / 2.2);
-  color->blue  = G_MAXUINT16 * pow (N_b_, 1 / 2.2);
-}
-
-#if !GTK_CHECK_VERSION (2,12,0)
-gchar *
-gdk_color_to_string (const GdkColor *color)
-{
-  g_return_val_if_fail (color != NULL, NULL);
-
-  return g_strdup_printf ("#%04x%04x%04x", color->red, color->green, 
color->blue);
-}
-#endif
-
-#if !GTK_CHECK_VERSION (2,14,0)
-GtkWidget*
-gtk_color_selection_dialog_get_color_selection (GtkColorSelectionDialog 
*colorsel)
-{
-  g_return_val_if_fail (GTK_IS_COLOR_SELECTION_DIALOG (colorsel), NULL);
-
-  return colorsel->colorsel;
-}
-#endif
-
diff --git a/lib/color.vapi b/lib/color.vapi
deleted file mode 100644
index 57ed23f..0000000
--- a/lib/color.vapi
+++ /dev/null
@@ -1,7 +0,0 @@
-[CCode (cprefix = "", lower_case_prefix = "", cheader_filename = "color.h")]
-namespace Xnp.Color {
-       [CCode (cname = "color_set_background")]
-       public static void set_background (string color);
-       [CCode (cname = "__gdk_color_constrast")]
-       public static void contrast (Gdk.Color color, double contrast);
-}
diff --git a/lib/ext-gdk.c b/lib/ext-gdk.c
new file mode 100644
index 0000000..c1deec4
--- /dev/null
+++ b/lib/ext-gdk.c
@@ -0,0 +1,80 @@
+/*
+ *  Notes - panel plugin for Xfce Desktop Environment
+ *  Copyright (C) 2006-2013  Mike Massonnet <[email protected]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_MATH_H
+#include <math.h>
+#endif
+
+#include <glib.h>
+#include <gdk/gdk.h>
+
+#include "ext-gdk.h"
+
+void
+__gdk_color_contrast (GdkColor *color,
+                      gdouble contrast)
+{
+  /* cf. http://accessibility.kde.org/hsl-adjusted.php */
+  gdouble N_r, N_g, N_b;
+  gdouble f_r = 0.2125, f_g = 0.7154, f_b = 0.0721;
+  gdouble L, L_, m, D, D_;
+  gdouble N__1, N_0, N_1;
+  gdouble N_r_, N_g_, N_b_;
+
+  g_return_if_fail (G_LIKELY (contrast >= 1 && contrast <= 21));
+
+  /* Calculate luminosity */
+  N_r = pow ((gdouble)color->red / G_MAXUINT16, 2.2);
+  N_g = pow ((gdouble)color->green / G_MAXUINT16, 2.2);
+  N_b = pow ((gdouble)color->blue / G_MAXUINT16, 2.2);
+
+  L = f_r * N_r + f_g * N_g + f_b * N_b;
+
+  /* Change luminosity */
+  L_ = (L + 0.05) / contrast - 0.05;
+
+  N__1 = MIN (N_r, MIN (N_g, N_b));
+  N_1 = MAX (N_r, MAX (N_g, N_b));
+  if (N_r > N__1 && N_r < N_1)
+    N_0 = N_r;
+  else if (N_g > N__1 && N_g < N_1)
+    N_0 = N_g;
+  else if (N_b > N__1 && N_b < N_1)
+    N_0 = N_b;
+  else
+    N_0 = N_1;
+
+  m = f_g + f_r * (N_0 - N__1) / (N_1 - N__1);
+  D = MIN (L / m, (1 - L) / (1 - m));
+  D_ = MIN (L_ / m, (1 - L_) / (1 - m));
+
+  N_r_ = L_ + (N_r - L) * D_ / D;
+  N_g_ = L_ + (N_g - L) * D_ / D;
+  N_b_ = L_ + (N_b - L) * D_ / D;
+
+  /* Conversion to RGB */
+  color->red   = G_MAXUINT16 * pow (N_r_, 1 / 2.2);
+  color->green = G_MAXUINT16 * pow (N_g_, 1 / 2.2);
+  color->blue  = G_MAXUINT16 * pow (N_b_, 1 / 2.2);
+}
+
diff --git a/lib/color.h b/lib/ext-gdk.h
similarity index 67%
rename from lib/color.h
rename to lib/ext-gdk.h
index 031b5ba..f6aaedd 100644
--- a/lib/color.h
+++ b/lib/ext-gdk.h
@@ -1,6 +1,6 @@
 /*
  *  Notes - panel plugin for Xfce Desktop Environment
- *  Copyright (C) 2009-2010  Mike Massonnet <[email protected]>
+ *  Copyright (C) 2006-2013  Mike Massonnet <[email protected]>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -17,22 +17,13 @@
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#ifndef COLOR_H
-#define COLOR_H
+#ifndef EXT_GDK_H
+#define EXT_GDK_H
 
 #include <glib.h>
 #include <gdk/gdk.h>
-#include <gtk/gtk.h>
 
-void                    color_set_background            (const gchar 
*background);
 void                    __gdk_color_contrast            (GdkColor *color,
                                                          gdouble contrast);
-#if !GTK_CHECK_VERSION (2,12,0)
-gchar *                 gdk_color_to_string             (const GdkColor 
*color);
-#endif
-#if !GTK_CHECK_VERSION (2,14,0)
-GtkWidget*              gtk_color_selection_dialog_get_color_selection 
(GtkColorSelectionDialog *colorsel);
-#endif
-
 #endif
 
diff --git a/lib/ext-gdk.vapi b/lib/ext-gdk.vapi
new file mode 100644
index 0000000..3afac96
--- /dev/null
+++ b/lib/ext-gdk.vapi
@@ -0,0 +1,5 @@
+[CCode (cprefix = "", lower_case_prefix = "", cheader_filename = "ext-gdk.h")]
+namespace ExtGdk {
+       [CCode (cname = "__gdk_color_constrast")]
+       public static void color_contrast (Gdk.Color color, double contrast);
+}
diff --git a/lib/theme-gtkcss.vala b/lib/theme-gtkcss.vala
new file mode 100644
index 0000000..dc72317
--- /dev/null
+++ b/lib/theme-gtkcss.vala
@@ -0,0 +1,50 @@
+/*
+ *  Notes - panel plugin for Xfce Desktop Environment
+ *  Copyright (c) 2006-2013  Mike Massonnet <[email protected]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+namespace Xnp {
+
+       public class ThemeGtkcss : GLib.Object {
+
+               public static string get_css_path () {
+                       return "%s/xfce4/xfce4-notes.css".printf 
(GLib.Environment.get_user_config_dir ());
+               }
+
+               public static void update_css (Gdk.Color color) {
+                       string css = "@define-color notes_bg_color 
#%x%x%x;\n@import url(\"%s%c%s%cgtk-main.css\");"
+                               .printf (color.red >> 8, color.green >> 8, 
color.blue >> 8, Config.PKGDATADIR, GLib.Path.DIR_SEPARATOR, "gtk-3.0", 
GLib.Path.DIR_SEPARATOR);
+                       try {
+                               GLib.FileUtils.set_contents (get_css_path (), 
css, -1);
+                       } catch (FileError e) {
+                               warning ("Unable to update CSS file: %s", 
e.message);
+                       }
+               }
+
+               public static void update_style_context () {
+                       try {
+                               var cssprovider = new Gtk.CssProvider ();
+                               cssprovider.load_from_path (get_css_path ());
+                               Gtk.StyleContext.add_provider_for_screen 
(Gdk.Screen.get_default (), cssprovider, 255);
+                       } catch (GLib.Error e) {
+                               warning ("%s", e.message);
+                       }
+               }
+
+       }
+
+}
diff --git a/lib/theme-gtkrc.c b/lib/theme-gtkrc.c
new file mode 100644
index 0000000..5a45237
--- /dev/null
+++ b/lib/theme-gtkrc.c
@@ -0,0 +1,102 @@
+/*
+ *  Notes - panel plugin for Xfce Desktop Environment
+ *  Copyright (c) 2006-2013  Mike Massonnet <[email protected]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <glib.h>
+#include <gdk/gdk.h>
+
+#include "ext-gdk.h"
+
+
+
+#define RC_STYLE \
+  "gtk_color_scheme = 
\"notes_fg_color:#xxxxxxxxxxxx\\nnotes_bg_color:#xxxxxxxxxxxx\\n" \
+  "notes_base_color:#xxxxxxxxxxxx\\nnotes_text_color:#xxxxxxxxxxxx\\n" \
+  
"notes_selected_bg_color:#xxxxxxxxxxxx\\nnotes_selected_fg_color:#xxxxxxxxxxxx\"\n"
 \
+  "include \"" PKGDATADIR "/gtk-2.0/notes.gtkrc\""
+
+
+
+void
+update_gtkrc (const GdkColor color)
+{
+  GdkColor *color2;
+  gchar *notesrc_file;
+  gchar *bg;
+  gchar *text;
+  gchar *selected;
+  gchar rc_style[] = RC_STYLE;
+  gchar *offset;
+
+  /* bg */
+  bg = gdk_color_to_string (&color);
+
+  /* text */
+  color2 = gdk_color_copy (&color);
+  __gdk_color_contrast (color2, 5.);
+  text = gdk_color_to_string (color2);
+  gdk_color_free (color2);
+
+  /* selected */
+  color2 = gdk_color_copy (&color);
+  __gdk_color_contrast (color2, 3.2);
+  selected = gdk_color_to_string (color2);
+  gdk_color_free (color2);
+
+  /* notes_fg_color */
+  offset = rc_style + 35;
+  memcpy (offset, bg, 13);
+
+  /* notes_bg_color */
+  offset += 30;
+  memcpy (offset, text, 13);
+
+  /* notes_base_color */
+  offset += 32;
+  memcpy (offset, bg, 13);
+
+  /* notes_text_color */
+  offset += 32;
+  memcpy (offset, text, 13);
+
+  /* notes_selected_bg_color */
+  offset += 39;
+  memcpy (offset, selected, 13);
+
+  /* notes_selected_fg_color */
+  offset += 39;
+  memcpy (offset, bg, 13);
+
+  /* set the rc style */
+  notesrc_file = g_strdup_printf ("%s/xfce4/xfce4-notes.gtkrc", 
g_get_user_config_dir ());
+  g_file_set_contents (notesrc_file, rc_style, -1, NULL);
+
+  g_free (notesrc_file);
+  g_free (bg);
+  g_free (text);
+  g_free (selected);
+}
+
diff --git a/lib/popup.h b/lib/theme-gtkrc.h
similarity index 62%
copy from lib/popup.h
copy to lib/theme-gtkrc.h
index e984505..bd82cf6 100644
--- a/lib/popup.h
+++ b/lib/theme-gtkrc.h
@@ -1,7 +1,6 @@
 /*
  *  Notes - panel plugin for Xfce Desktop Environment
- *  Copyright (C) 2002-2006  Olivier Fourdan
- *  Copyright (C) 2009-2010       Mike Massonnet <[email protected]>
+ *  Copyright (c) 2006-2013  Mike Massonnet <[email protected]>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -11,22 +10,20 @@
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ *  GNU Library General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#ifndef __POPUP_H__
-#define __POPUP_H__
+#ifndef THEME_GTKRC_H
+#define THEME_GTKRC_H
 
-#include <gtk/gtk.h>
+#include <glib.h>
+#include <gdk/gdk.h>
 
-#define XFCE_NOTES_SELECTION    "XFCE_NOTES_SELECTION"
-#define NOTES_MSG_SHOW_HIDE     "SHOW_HIDE"
-
-gboolean popup_set_x_selection (GtkWidget *widget);
-const gchar* popup_get_message_from_event (GdkEventClient *event);
+void                     xnp_theme_update_gtkrc         (const GdkColor color);
 
 #endif
+
diff --git a/lib/theme-gtkrc.vapi b/lib/theme-gtkrc.vapi
new file mode 100644
index 0000000..606ab96
--- /dev/null
+++ b/lib/theme-gtkrc.vapi
@@ -0,0 +1,7 @@
+[CCode (cprefix = "", lower_case_prefix = "", cheader_filename = 
"theme-gtkrc.h")]
+namespace Xnp {
+       public class ThemeGtkrc {
+               public static void update_gtkrc (Gdk.Color color);
+       }
+}
+
diff --git a/lib/popup.h b/lib/theme.vala
similarity index 61%
copy from lib/popup.h
copy to lib/theme.vala
index e984505..d6b50ef 100644
--- a/lib/popup.h
+++ b/lib/theme.vala
@@ -1,7 +1,6 @@
 /*
  *  Notes - panel plugin for Xfce Desktop Environment
- *  Copyright (C) 2002-2006  Olivier Fourdan
- *  Copyright (C) 2009-2010       Mike Massonnet <[email protected]>
+ *  Copyright (c) 2006-2013  Mike Massonnet <[email protected]>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -18,15 +17,26 @@
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#ifndef __POPUP_H__
-#define __POPUP_H__
+namespace Xnp {
 
-#include <gtk/gtk.h>
+       public class Theme : GLib.Object {
 
-#define XFCE_NOTES_SELECTION    "XFCE_NOTES_SELECTION"
-#define NOTES_MSG_SHOW_HIDE     "SHOW_HIDE"
-
-gboolean popup_set_x_selection (GtkWidget *widget);
-const gchar* popup_get_message_from_event (GdkEventClient *event);
+               public static void set_background_color (string color) {
+                       Gdk.Color gdkcolor;
+                       if (!Gdk.Color.parse (color, out gdkcolor)) {
+                               warning ("Cannot parse background color %s", 
color);
+                               return;
+                       }
 
+#if ENABLE_GTK3
+                       Xnp.ThemeGtkcss.update_css (gdkcolor);
+                       Xnp.ThemeGtkcss.update_style_context ();
+#else
+                       Xnp.ThemeGtkrc.update_gtkrc (gdkcolor);
+                       Gtk.rc_reparse_all ();
 #endif
+               }
+
+       }
+
+}
diff --git a/src/Makefile.am b/src/Makefile.am
index 032eba4..4844e5a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,5 @@
 BUILT_SOURCES =
+
 INCLUDES =                                                             \
        -I$(top_srcdir)                                                 \
        -I$(top_srcdir)/lib                                             \
@@ -10,9 +11,9 @@ INCLUDES =                                                    
        \
 # Popup program
 #
 
-if ENABLE_GTK3
 bin_PROGRAMS = xfce4-popup-notes
 
+if ENABLE_GTK3
 if MAINTAINER_MODE
 xfce4_popup_notes_VALAFLAGS =                                          \
        --pkg=gtk+-3.0
@@ -31,8 +32,6 @@ xfce4_popup_notes_CFLAGS =                                    
        \
 xfce4_popup_notes_LDADD =                                              \
        @GTK_LIBS@
 else
-bin_PROGRAMS = xfce4-popup-notes
-
 xfce4_popup_notes_SOURCES =                                            \
        $(top_srcdir)/lib/popup.h                                       \
        xfce4-popup-notes.c
diff --git a/src/main-settings-dialog.c b/src/main-settings-dialog.c
index 6afb515..ae8ed44 100644
--- a/src/main-settings-dialog.c
+++ b/src/main-settings-dialog.c
@@ -30,7 +30,7 @@
 #include <libxfce4ui/libxfce4ui.h>
 
 #include "defines.h"
-#include "color.h"
+#include "ext-gdk.h"
 
 #if 0
 static GtkWidget *notes_path_button_new ();
_______________________________________________
Xfce4-commits mailing list
[email protected]
https://mail.xfce.org/mailman/listinfo/xfce4-commits

Reply via email to