[gtk/wip/otte/css: 6/17] testgtk: Use global css provider



commit 38fc2ef430a4bb51496c7614435f043a1c415732
Author: Benjamin Otte <otte redhat com>
Date:   Sat Feb 8 03:59:55 2020 +0100

    testgtk: Use global css provider

 tests/testgtk.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/tests/testgtk.c b/tests/testgtk.c
index 998a13d218..bfedeeff48 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -185,26 +185,30 @@ create_alpha_window (GtkWidget *widget)
 
   if (!window)
     {
+      static GtkCssProvider *provider = NULL;
       GtkWidget *content_area;
       GtkWidget *vbox;
       GtkWidget *label;
       GdkDisplay *display;
-      GtkCssProvider *provider;
       
       window = gtk_dialog_new_with_buttons ("Alpha Window",
                                            GTK_WINDOW (gtk_widget_get_root (widget)), 0,
                                            "_Close", 0,
                                            NULL);
-      provider = gtk_css_provider_new ();
-      gtk_css_provider_load_from_data (provider,
-                                       "dialog {\n"
-                                       "  background: radial-gradient(ellipse at center, #FFBF00, 
#FFBF0000);\n"
-                                       "}\n",
-                                       -1);
-      gtk_style_context_add_provider (gtk_widget_get_style_context (window),
-                                      GTK_STYLE_PROVIDER (provider),
-                                      GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
-      g_object_unref (provider);
+      gtk_widget_add_style_class (window, "alpha");
+      if (provider == NULL)
+        {
+          provider = gtk_css_provider_new ();
+          gtk_css_provider_load_from_data (provider,
+                                           "dialog.alpha {\n"
+                                           "  background: radial-gradient(ellipse at center, #FFBF00, 
#FFBF0000);\n"
+                                           "}\n",
+                                           -1);
+          gtk_style_context_add_provider_for_display (gtk_widget_get_display (window),
+                                                      GTK_STYLE_PROVIDER (provider),
+                                                      GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+          g_object_unref (provider);
+        }
 
       content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
 


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