Mercurial > minori
diff src/sys/glib/dark_theme.cc @ 351:c844f8bb87ce
gui/theme: add xsettings backend
this also adds newly-necessary endianness methods in core/endian.h
which just so happen to be constexpr as well
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sun, 14 Jul 2024 23:23:56 -0400 |
parents | daa03aa2262d |
children | 99c961c91809 |
line wrap: on
line diff
--- a/src/sys/glib/dark_theme.cc Sun Jul 14 19:12:40 2024 -0400 +++ b/src/sys/glib/dark_theme.cc Sun Jul 14 23:23:56 2024 -0400 @@ -5,6 +5,7 @@ #include <string_view> #include <memory> #include <array> +#include <iostream> namespace glib { @@ -33,6 +34,29 @@ template<typename T> using GMallocPtr = std::unique_ptr<T, g_malloc_del<T>>; +/* not really "glib" but GNOME-related enough */ +bool IsGTKThemeDark(const std::string_view str) { + /* if that doesn't exist, use the GTK theme and check for some known + * suffixes. if one is found, return + * + * XXX probably better to use case folding here */ + static constexpr std::array<std::string_view, 3> suffixes = { + "-dark", /* Adwaita-dark */ + "-Dark", /* Arc-Dark */ + "-Darker", /* Arc-Darker */ + }; + + for (const auto& suffix : suffixes) { + if (str.size() < suffix.size()) + continue; + + if (std::equal(str.data() + str.size() - suffix.length(), str.data() + str.size(), suffix.begin(), suffix.end())) + return true; + } + + return false; +} + bool IsInDarkTheme() { GObjectPtr<GSettings> settings(::g_settings_new("org.gnome.desktop.interface")); if (!settings) @@ -50,22 +74,13 @@ if (!str) return false; - bool success = !std::strncmp(str, size, "prefer-dark"); + bool success = !std::strncmp(str, "prefer-dark", size); if (success) return true; } { - /* if that doesn't exist, use the GTK theme and check for some known - * suffixes. if one is found, return - * - * XXX probably better to use case folding here */ - static constexpr std::array<std::string_view, 3> suffixes = { - "-dark", /* Adwaita-dark */ - "-Dark", /* Arc-Dark */ - "-Darker", /* Arc-Darker */ - }; GVariantPtr<GVariant> gtk_theme(::g_settings_get_value(settings.get(), "gtk-theme")); if (!gtk_theme) @@ -76,13 +91,8 @@ if (!str) return false; - for (const auto& suffix : suffixes) { - if (size < suffix.size()) - continue; - - if (std::equal(str + size - suffix.length(), str + size, suffix.begin(), suffix.end())) - return true; - } + if (IsGTKThemeDark({str, size})) + return true; } /* welp, we tried */