Skip to content

Instantly share code, notes, and snippets.

@sulincix
Created April 7, 2022 23:58
Show Gist options
  • Save sulincix/3e09ffb3b407ed05c7b0f9d944fb922e to your computer and use it in GitHub Desktop.
Save sulincix/3e09ffb3b407ed05c7b0f9d944fb922e to your computer and use it in GitHub Desktop.
libadwaita theme support
diff --git a/src/adw-style-manager.c b/src/adw-style-manager.c
index ae1a858d..c5b5ac73 100644
--- a/src/adw-style-manager.c
+++ b/src/adw-style-manager.c
@@ -14,6 +14,8 @@
#include "adw-settings-private.h"
#include <gtk/gtk.h>
+int file_exists(const char *fname);
+
#define SWITCH_DURATION 250
/**
@@ -165,7 +167,6 @@ update_stylesheet (AdwStyleManager *self)
gtk_css_provider_load_from_resource (self->provider,
"/org/gnome/Adwaita/styles/base.css");
}
-
if (self->colors_provider) {
if (self->dark)
gtk_css_provider_load_from_resource (self->colors_provider,
@@ -175,12 +176,41 @@ update_stylesheet (AdwStyleManager *self)
"/org/gnome/Adwaita/styles/defaults-light.css");
}
+ /* Theming support */
+ gchar *thm;
+ GSettings *settings;
+ settings = g_settings_new ("org.gnome.desktop.interface");
+ g_settings_get (settings, "gtk-theme", "s", &thm);
+ char theme_path[1024];
+ sprintf(theme_path,"/usr/share/themes/%s/gtk-4.0/gtk.css",(char*)thm);
+ GFile *file = NULL;
+ if (file_exists(theme_path)){
+ file=g_file_new_for_path(theme_path);
+ }
+ sprintf(theme_path,"%s/.themes/%s/gtk-4.0/gtk.css",getenv("HOME"),(char*)thm);
+ if (file_exists(theme_path)){
+ file=g_file_new_for_path(theme_path);
+ }
+ if (G_IS_FILE(file)){
+ gtk_css_provider_load_from_file(self->colors_provider,file);
+ }
+
+
self->animation_timeout_id =
g_timeout_add (SWITCH_DURATION,
G_SOURCE_FUNC (enable_animations_cb),
self);
}
-
+int file_exists(const char *fname)
+{
+ FILE *file;
+ if ((file = fopen(fname, "r")))
+ {
+ fclose(file);
+ return 1;
+ }
+ return 0;
+}
static gboolean
get_is_dark (AdwStyleManager *self)
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment