Mercurial > minori
diff src/sys/glib/dark_theme.cc @ 250:c130f47f6f48
*: many many changes
e.g. the search page is actually implemented now!
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sun, 04 Feb 2024 21:17:17 -0500 |
parents | 4d461ef7d424 |
children | 862d0d8619f6 |
line wrap: on
line diff
--- a/src/sys/glib/dark_theme.cc Wed Jan 24 20:18:59 2024 -0500 +++ b/src/sys/glib/dark_theme.cc Sun Feb 04 21:17:17 2024 -0500 @@ -1,11 +1,12 @@ #include <gio/gio.h> #include <cstring> - -#include <iostream> +#include <string_view> namespace glib { bool IsInDarkTheme() { + bool success = false; + GSettings* settings = ::g_settings_new("org.gnome.desktop.interface"); if (!settings) return false; @@ -19,12 +20,31 @@ if (!str) /* how */ return false; - bool success = !std::strcmp(str, "prefer-dark"); + success |= !std::strcmp(str, "prefer-dark"); + + ::g_variant_unref(val); + + if (success) { + ::g_object_unref(settings); + return success; + } + + GVariant* gtk_theme = ::g_settings_get_value(settings, "gtk-theme"); + if (!gtk_theme) + return false; - /* unref these */ - ::g_variant_unref(val); + const gchar* gtk_theme_str; + ::g_variant_get(gtk_theme, "&s", gtk_theme_str); + if (!gtk_theme_str) + return false; + + static constexpr std::string_view suffix = "-dark"; + + size_t gtk_theme_len = strlen(gtk_theme_str); + + success |= !std::strncmp(gtk_theme_str + gtk_theme_len - suffix.length(), suffix.data(), suffix.length()); + ::g_object_unref(settings); - return success; }