[libadwaita/wip/exalm/inspector: 2/3] style-manager: Load stylesheet without gtk-theme-name




commit cb423717c2acc2a5fa9a4e73e440c31e5c8bfbda
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sun Sep 26 21:22:03 2021 +0500

    style-manager: Load stylesheet without gtk-theme-name
    
    Set it to "Empty" on startup, manage a custom css provider instead. This
    allows us to stop injecting the stylesheet into GTK resource paths, which
    in turn allows to skip loading the inspector page without problems if the
    app hadn't been using libadwaita.

 src/adw-style-manager.c                          | 21 +++++++++++++++++---
 src/stylesheet/adwaita-stylesheet.gresources.xml | 25 +-----------------------
 2 files changed, 19 insertions(+), 27 deletions(-)
---
diff --git a/src/adw-style-manager.c b/src/adw-style-manager.c
index 2fe7ca21..21367370 100644
--- a/src/adw-style-manager.c
+++ b/src/adw-style-manager.c
@@ -53,6 +53,7 @@ struct _AdwStyleManager
 
   GdkDisplay *display;
   AdwSettings *settings;
+  GtkCssProvider *provider;
 
   AdwColorScheme color_scheme;
   gboolean dark;
@@ -130,7 +131,7 @@ static void
 update_stylesheet (AdwStyleManager *self)
 {
   const char *variant;
-  g_autofree char *new_theme_name = NULL;
+  g_autofree char *stylesheet_path = NULL;
   GtkSettings *gtk_settings;
   gboolean enable_animations;
 
@@ -144,7 +145,7 @@ update_stylesheet (AdwStyleManager *self)
   else
     variant = self->dark ? "dark" : "light";
 
-  new_theme_name = g_strdup_printf ("Adwaita-%s", variant);
+  stylesheet_path = g_strdup_printf ("/org/gnome/Adwaita/styles/Adwaita-%s.css", variant);
 
   if (self->animation_timeout_id) {
     g_clear_handle_id (&self->animation_timeout_id, g_source_remove);
@@ -157,9 +158,11 @@ update_stylesheet (AdwStyleManager *self)
 
   g_object_set (gtk_settings,
                 "gtk-enable-animations", FALSE,
-                "gtk-theme-name", new_theme_name,
                 NULL);
 
+  if (self->provider)
+    gtk_css_provider_load_from_resource (self->provider, stylesheet_path);
+
   if (enable_animations) {
     self->animation_timeout_id =
       g_timeout_add (SWITCH_DURATION,
@@ -237,6 +240,17 @@ adw_style_manager_constructed (GObject *object)
                              G_CALLBACK (warn_prefer_dark_theme),
                              self,
                              0);
+
+    if (!g_getenv ("GTK_THEME")) {
+      g_object_set (gtk_settings_get_for_display (self->display),
+                    "gtk-theme-name", "Empty",
+                    NULL);
+
+      self->provider = gtk_css_provider_new ();
+      gtk_style_context_add_provider_for_display (self->display,
+                                                  GTK_STYLE_PROVIDER (self->provider),
+                                                  GTK_STYLE_PROVIDER_PRIORITY_THEME);
+    }
   }
 
   self->settings = adw_settings_get_default ();
@@ -262,6 +276,7 @@ adw_style_manager_dispose (GObject *object)
   AdwStyleManager *self = ADW_STYLE_MANAGER (object);
 
   g_clear_handle_id (&self->animation_timeout_id, g_source_remove);
+  g_clear_object (&self->provider);
 
   G_OBJECT_CLASS (adw_style_manager_parent_class)->dispose (object);
 }
diff --git a/src/stylesheet/adwaita-stylesheet.gresources.xml 
b/src/stylesheet/adwaita-stylesheet.gresources.xml
index 786faba8..83ed9c02 100644
--- a/src/stylesheet/adwaita-stylesheet.gresources.xml
+++ b/src/stylesheet/adwaita-stylesheet.gresources.xml
@@ -1,29 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
-  <gresource prefix="/org/gtk/libgtk/theme/Adwaita-light">
-    <file alias='gtk.css'>gtk-light.css</file>
-  </gresource>
-
-  <gresource prefix="/org/gtk/libgtk/theme/Adwaita-dark">
-    <file alias='gtk.css'>gtk-dark.css</file>
-    <file alias='gtk-dark.css'>gtk-dark.css</file>
-  </gresource>
-
-  <gresource prefix="/org/gtk/libgtk/theme/Adwaita-hc">
-    <file alias='gtk.css'>gtk-hc.css</file>
-  </gresource>
-
-  <gresource prefix="/org/gtk/libgtk/theme/Adwaita-hc-dark">
-    <file alias='gtk.css'>gtk-hc-dark.css</file>
-    <file alias='gtk-dark.css'>gtk-hc-dark.css</file>
-  </gresource>
-
-  <gresource prefix="/org/gtk/libgtk/theme/Adwaita">
-    <file>gtk.css</file>
-    <file>gtk-light.css</file>
-    <file>gtk-hc.css</file>
-    <file>gtk-hc-dark.css</file>
-
+  <gresource prefix="/org/gnome/Adwaita/styles">
     <file>Adwaita-light.css</file>
     <file>Adwaita-dark.css</file>
     <file>Adwaita-hc.css</file>


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