[aisleriot] sol: Install default CSS provider



commit 5668c7107e97f29ca898e2cc9ef3f5eb5fa0dd2e
Author: Christian Persch <chpe gnome org>
Date:   Sun Dec 4 14:18:27 2011 +0100

    sol: Install default CSS provider
    
    This ensures that the selection colour is always defined; remove
    NULL checks.

 src/ar-style-gtk.c     |   56 +++++++++++++++++++++++++++++++++++++----------
 src/ar-style-private.h |    3 ++
 src/board-noclutter.c  |    2 -
 3 files changed, 47 insertions(+), 14 deletions(-)
---
diff --git a/src/ar-style-gtk.c b/src/ar-style-gtk.c
index 19e19ec..d59e90d 100644
--- a/src/ar-style-gtk.c
+++ b/src/ar-style-gtk.c
@@ -36,6 +36,36 @@
 
 /* private functions */
 
+/*
+ * ar_style_provider_new:
+ * 
+ * Returns: (transfer full): a new #GtkStyleProvider
+ */
+static GtkStyleProvider *
+ar_style_provider_new (void)
+{
+#ifdef HAVE_CLUTTER
+#define NAME "ArClutterEmbed"
+#else
+#define NAME "AisleriotBoard"
+#endif
+  static const char css[] =
+    "" NAME "{\n"
+    "-" NAME "-selection-color: " DEFAULT_SELECTION_COLOR_STRING ";\n"
+  "}\n";
+#undef NAME
+
+  GtkCssProvider *provider;
+  GError *err = NULL;
+
+  provider = gtk_css_provider_new ();
+  gtk_css_provider_load_from_data (provider, css, -1,  &err);
+  if (err)
+    g_error ("ERROR: %s\n", err->message);
+
+  return GTK_STYLE_PROVIDER (provider);
+}
+
 static void
 sync_settings (GtkSettings *settings,
                GParamSpec *pspec,
@@ -202,8 +232,7 @@ style_updated_cb (GtkWidget *widget,
 {
   ArStylePrivate *style_priv = style->priv;
   GObject *style_object = G_OBJECT (style);
-  GdkRGBA selection_color;
-  GdkRGBA *color = NULL;
+  GdkRGBA *selection_color = NULL;
   int focus_line_width, focus_padding;
   gboolean interior_focus;
   double card_slot_ratio, card_overhang, card_step;
@@ -221,7 +250,7 @@ style_updated_cb (GtkWidget *widget,
                         "card-slot-ratio", &card_slot_ratio,
                         "card-overhang", &card_overhang,
                         "card-step", &card_step,
-                        "selection-color", &color,
+                        "selection-color", &selection_color,
                         NULL);
 
   if (style_priv->interior_focus != interior_focus) {
@@ -260,18 +289,12 @@ style_updated_cb (GtkWidget *widget,
     g_object_notify (style_object, AR_STYLE_PROP_CARD_STEP);
   }
 
-  if (color != NULL) {
-    selection_color = *color;
-    gdk_rgba_free (color);
-  } else {
-    selection_color = default_selection_color;
-  }
-
-  if (!gdk_rgba_equal (&style_priv->selection_color, &selection_color)) {
-    style_priv->selection_color = selection_color;
+  if (!gdk_rgba_equal (&style_priv->selection_color, selection_color)) {
+    style_priv->selection_color = *selection_color;
 
     g_object_notify (style_object, AR_STYLE_PROP_SELECTION_COLOR);
   }
+  gdk_rgba_free (selection_color);
 
   g_object_thaw_notify (style_object);
 }
@@ -352,12 +375,21 @@ void
 _ar_style_gtk_attach (ArStyle *style,
                       GtkWidget *widget)
 {
+  GtkStyleContext *context;
+  GtkStyleProvider *provider;
+
   g_return_if_fail (AR_IS_STYLE (style));
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
   ar_debug_print (AR_DEBUG_GAME_STYLE,
                       "[ArStyle %p] Attaching to widget %p\n", style, widget);
 
+  context = gtk_widget_get_style_context (widget);
+  provider = ar_style_provider_new ();
+  gtk_style_context_add_provider (context, provider,
+                                  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+  g_object_unref (provider);
+
   g_assert (g_object_get_data (G_OBJECT (widget), "Ar::Style") == NULL);
   g_object_set_data (G_OBJECT (widget), "Ar::Style", style);
 
diff --git a/src/ar-style-private.h b/src/ar-style-private.h
index 55c45d4..9f9d33f 100644
--- a/src/ar-style-private.h
+++ b/src/ar-style-private.h
@@ -23,6 +23,9 @@ G_BEGIN_DECLS
 static const GdkRGBA default_selection_color = { 0. /* red */, 0. /* green */, 0.6666 /* blue */, 0.5 /* alpha */ };
 static const GdkRGBA default_baize_color = { 0. /* red */, 0.3125 /* green */, 0.0625 /* blue */, 1.0 /* alpha */ };
 
+#define DEFAULT_SELECTION_COLOR_STRING  "rgba(0%,0%,66%,0.5)"
+#define DEFAULT_BAIZE_COLOR_STRING      "rgb(0%, 31%,6%)"
+
 /* The proportion of a slot dedicated to the card (horiz or vert). */
 #define DEFAULT_CARD_OVERHANG (0.0)
 
diff --git a/src/board-noclutter.c b/src/board-noclutter.c
index 4b3b843..d658b29 100644
--- a/src/board-noclutter.c
+++ b/src/board-noclutter.c
@@ -3217,8 +3217,6 @@ aisleriot_board_init (AisleriotBoard *board)
 
   priv = board->priv = AISLERIOT_BOARD_GET_PRIVATE (board);
 
-  gtk_widget_set_name (widget, "aisleriot-board");
-
   gtk_widget_set_can_focus (widget, TRUE);
 
   priv->is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]