[libadwaita/wip/exalm/empty] main: Load stylesheet in a separate provider instead of gtk theme
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/empty] main: Load stylesheet in a separate provider instead of gtk theme
- Date: Tue, 18 May 2021 17:58:25 +0000 (UTC)
commit 07840bd7d56e0c11ee00bccab1d835d1590fbdc7
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue May 18 22:57:32 2021 +0500
main: Load stylesheet in a separate provider instead of gtk theme
src/adw-main.c | 40 ++++++++++++++++++------
src/stylesheet/adwaita-stylesheet.gresources.xml | 26 +++------------
src/stylesheet/empty.css | 0
3 files changed, 34 insertions(+), 32 deletions(-)
---
diff --git a/src/adw-main.c b/src/adw-main.c
index 2c9e3a5a..1b3493d3 100644
--- a/src/adw-main.c
+++ b/src/adw-main.c
@@ -10,6 +10,7 @@
#include <gtk/gtk.h>
static int adw_initialized = FALSE;
+static GtkCssProvider *provider;
static gboolean
is_high_contrast (void)
@@ -29,26 +30,37 @@ is_high_contrast (void)
!g_strcmp0 (theme_name, "HighContrastInverse");
}
+static void
+load_theme (gboolean dark,
+ gboolean high_contrast)
+{
+ g_autofree char *path = NULL;
+ const char *variant;
+
+ if (high_contrast)
+ variant = dark ? "hc-dark" : "hc";
+ else
+ variant = dark ? "dark" : "light";
+
+ path = g_strdup_printf ("/org/gtk/libgtk/theme/Adwaita/Adwaita-%s.css", variant);
+
+ gtk_css_provider_load_from_resource (provider, path);
+}
+
static void
update_theme (void)
{
GtkSettings *settings = gtk_settings_get_default ();
- g_autofree char *new_theme_name = NULL;
gboolean prefer_dark_theme;
- const char *variant;
g_object_get (settings,
"gtk-application-prefer-dark-theme", &prefer_dark_theme,
NULL);
- if (is_high_contrast ())
- variant = prefer_dark_theme ? "hc-dark" : "hc";
- else
- variant = prefer_dark_theme ? "dark" : "light";
+ // Empty doesn't have a gtk-dark.css so we'll make our own instead
+ g_object_set (settings, "gtk-theme-name", "Adwaita", NULL);
- new_theme_name = g_strdup_printf ("Adwaita-%s", variant);
-
- g_object_set (settings, "gtk-theme-name", new_theme_name, NULL);
+ load_theme (prefer_dark_theme, is_high_contrast ());
}
static void
@@ -64,6 +76,7 @@ adw_style_init (void)
{
static gsize guard = 0;
GtkSettings *settings;
+ GdkDisplay *display;
if (!g_once_init_enter (&guard))
return;
@@ -76,6 +89,13 @@ adw_style_init (void)
return;
}
+ display = gdk_display_get_default ();
+
+ provider = gtk_css_provider_new ();
+ gtk_style_context_add_provider_for_display (display,
+ GTK_STYLE_PROVIDER (provider),
+ GTK_STYLE_PROVIDER_PRIORITY_THEME);
+
g_signal_connect (settings,
"notify::gtk-application-prefer-dark-theme",
G_CALLBACK (update_theme),
@@ -83,7 +103,7 @@ adw_style_init (void)
/* If gtk_settings_get_default() has worked, GdkDisplay
* exists, so we don't need to check that separately. */
- g_signal_connect (gdk_display_get_default (),
+ g_signal_connect (display,
"setting-changed",
G_CALLBACK (setting_changed_cb),
NULL);
diff --git a/src/stylesheet/adwaita-stylesheet.gresources.xml
b/src/stylesheet/adwaita-stylesheet.gresources.xml
index feb16bdf..98f36aca 100644
--- a/src/stylesheet/adwaita-stylesheet.gresources.xml
+++ b/src/stylesheet/adwaita-stylesheet.gresources.xml
@@ -1,28 +1,10 @@
<?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>
+ <file alias='gtk.css'>empty.css</file>
+ <file alias='gtk-dark.css'>empty.css</file>
+ <file alias='gtk-hc.css'>empty.css</file>
+ <file alias='gtk-hc-dark.css'>empty.css</file>
<file>Adwaita-light.css</file>
<file>Adwaita-dark.css</file>
diff --git a/src/stylesheet/empty.css b/src/stylesheet/empty.css
new file mode 100644
index 00000000..e69de29b
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]