Mercurial > minori
annotate 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 | 
| rev | line source | 
|---|---|
| 258 | 1 #include <cstring> | 
| 232 
ff0061e75f0f
theme: add OS detection with glib
 Paper <mrpapersonic@gmail.com> parents: diff
changeset | 2 #include <gio/gio.h> | 
| 250 | 3 #include <string_view> | 
| 232 
ff0061e75f0f
theme: add OS detection with glib
 Paper <mrpapersonic@gmail.com> parents: diff
changeset | 4 | 
| 
ff0061e75f0f
theme: add OS detection with glib
 Paper <mrpapersonic@gmail.com> parents: diff
changeset | 5 namespace glib { | 
| 
ff0061e75f0f
theme: add OS detection with glib
 Paper <mrpapersonic@gmail.com> parents: diff
changeset | 6 | 
| 
ff0061e75f0f
theme: add OS detection with glib
 Paper <mrpapersonic@gmail.com> parents: diff
changeset | 7 bool IsInDarkTheme() { | 
| 236 
4d461ef7d424
HUGE UPDATE: convert build system to autotools
 Paper <mrpapersonic@gmail.com> parents: 
232diff
changeset | 8 GSettings* settings = ::g_settings_new("org.gnome.desktop.interface"); | 
| 232 
ff0061e75f0f
theme: add OS detection with glib
 Paper <mrpapersonic@gmail.com> parents: diff
changeset | 9 if (!settings) | 
| 
ff0061e75f0f
theme: add OS detection with glib
 Paper <mrpapersonic@gmail.com> parents: diff
changeset | 10 return false; | 
| 
ff0061e75f0f
theme: add OS detection with glib
 Paper <mrpapersonic@gmail.com> parents: diff
changeset | 11 | 
| 258 | 12 { | 
| 13 GVariant* val = ::g_settings_get_value(settings, "color-scheme"); | |
| 14 if (!val) { | |
| 15 ::g_object_unref(settings); | |
| 16 return false; | |
| 17 } | |
| 232 
ff0061e75f0f
theme: add OS detection with glib
 Paper <mrpapersonic@gmail.com> parents: diff
changeset | 18 | 
| 258 | 19 const gchar* str = nullptr; | 
| 20 ::g_variant_get(val, "&s", &str); /* should not be freed */ | |
| 21 if (!str) { /* how */ | |
| 22 ::g_variant_unref(val); | |
| 23 ::g_object_unref(settings); | |
| 24 return false; | |
| 25 } | |
| 232 
ff0061e75f0f
theme: add OS detection with glib
 Paper <mrpapersonic@gmail.com> parents: diff
changeset | 26 | 
| 258 | 27 bool success = !std::strcmp(str, "prefer-dark"); | 
| 250 | 28 | 
| 258 | 29 ::g_variant_unref(val); | 
| 30 | |
| 31 if (success) | |
| 32 return true; | |
| 250 | 33 } | 
| 34 | |
| 258 | 35 { | 
| 36 GVariant* gtk_theme = ::g_settings_get_value(settings, "gtk-theme"); | |
| 37 if (!gtk_theme) { | |
| 38 ::g_object_unref(settings); | |
| 39 return false; | |
| 40 } | |
| 232 
ff0061e75f0f
theme: add OS detection with glib
 Paper <mrpapersonic@gmail.com> parents: diff
changeset | 41 | 
| 258 | 42 const gchar* gtk_theme_str = nullptr; | 
| 43 ::g_variant_get(gtk_theme, "&s", gtk_theme_str); | |
| 44 if (!gtk_theme_str) { | |
| 45 ::g_variant_unref(gtk_theme); | |
| 46 ::g_object_unref(settings); | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 static constexpr std::string_view suffix = "-dark"; | |
| 250 | 51 | 
| 258 | 52 size_t gtk_theme_len = strlen(gtk_theme_str); | 
| 250 | 53 | 
| 258 | 54 if (gtk_theme_len < suffix.length()) { | 
| 55 ::g_variant_unref(gtk_theme); | |
| 56 ::g_object_unref(settings); | |
| 57 return false; | |
| 58 } | |
| 250 | 59 | 
| 258 | 60 bool success = !std::strncmp(gtk_theme_str + gtk_theme_len - suffix.length(), suffix.data(), suffix.length()); | 
| 61 | |
| 62 ::g_variant_unref(gtk_theme); | |
| 63 ::g_object_unref(settings); | |
| 250 | 64 | 
| 258 | 65 if (success) | 
| 66 return true; | |
| 67 } | |
| 68 | |
| 69 return false; | |
| 232 
ff0061e75f0f
theme: add OS detection with glib
 Paper <mrpapersonic@gmail.com> parents: diff
changeset | 70 } | 
| 
ff0061e75f0f
theme: add OS detection with glib
 Paper <mrpapersonic@gmail.com> parents: diff
changeset | 71 | 
| 258 | 72 } // namespace glib | 
