Mercurial > minori
view src/sys/glib/dark_theme.cc @ 258:862d0d8619f6
*: HUUUGE changes
animia has been renamed to animone, so instead of thinking of a
health condition, you think of a beautiful flower :)
I've also edited some of the code for animone, but I have no idea
if it even works or not because I don't have a mac or windows
machine lying around. whoops!
... anyway, all of the changes divergent from Anisthesia are now
licensed under BSD. it's possible that I could even rewrite most
of the code to where I don't even have to keep the MIT license,
but that's thinking too far into the future
I've been slacking off on implementing the anime seasons page,
mostly out of laziness. I think I'd have to create another db file
specifically for the seasons
anyway, this code is being pushed *primarily* because the hard drive
it's on is failing! yay :)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Mon, 01 Apr 2024 02:43:44 -0400 |
parents | c130f47f6f48 |
children | ac1451035c85 |
line wrap: on
line source
#include <cstring> #include <gio/gio.h> #include <string_view> namespace glib { bool IsInDarkTheme() { GSettings* settings = ::g_settings_new("org.gnome.desktop.interface"); if (!settings) return false; { GVariant* val = ::g_settings_get_value(settings, "color-scheme"); if (!val) { ::g_object_unref(settings); return false; } const gchar* str = nullptr; ::g_variant_get(val, "&s", &str); /* should not be freed */ if (!str) { /* how */ ::g_variant_unref(val); ::g_object_unref(settings); return false; } bool success = !std::strcmp(str, "prefer-dark"); ::g_variant_unref(val); if (success) return true; } { GVariant* gtk_theme = ::g_settings_get_value(settings, "gtk-theme"); if (!gtk_theme) { ::g_object_unref(settings); return false; } const gchar* gtk_theme_str = nullptr; ::g_variant_get(gtk_theme, "&s", gtk_theme_str); if (!gtk_theme_str) { ::g_variant_unref(gtk_theme); ::g_object_unref(settings); return false; } static constexpr std::string_view suffix = "-dark"; size_t gtk_theme_len = strlen(gtk_theme_str); if (gtk_theme_len < suffix.length()) { ::g_variant_unref(gtk_theme); ::g_object_unref(settings); return false; } bool success = !std::strncmp(gtk_theme_str + gtk_theme_len - suffix.length(), suffix.data(), suffix.length()); ::g_variant_unref(gtk_theme); ::g_object_unref(settings); if (success) return true; } return false; } } // namespace glib