Mercurial > minori
annotate src/sys/glib/dark_theme.cc @ 327:b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
ToLocalString has also been altered to take in both season
and year because lots of locales actually treat formatting
seasons differently! most notably is Russian which adds a
suffix at the end to notate seasons(??)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 13 Jun 2024 01:49:18 -0400 |
parents | ac1451035c85 |
children | daa03aa2262d |
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 |
292 | 5 /* this file uses the regular gio C interface because I don't |
6 * see any real benefit to using the C++ bindings. */ | |
7 | |
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
8 namespace glib { |
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
9 |
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
10 bool IsInDarkTheme() { |
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
11 GSettings* settings = ::g_settings_new("org.gnome.desktop.interface"); |
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
12 if (!settings) |
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
13 return false; |
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
14 |
258 | 15 { |
16 GVariant* val = ::g_settings_get_value(settings, "color-scheme"); | |
17 if (!val) { | |
18 ::g_object_unref(settings); | |
19 return false; | |
20 } | |
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
21 |
258 | 22 const gchar* str = nullptr; |
23 ::g_variant_get(val, "&s", &str); /* should not be freed */ | |
24 if (!str) { /* how */ | |
25 ::g_variant_unref(val); | |
26 ::g_object_unref(settings); | |
27 return false; | |
28 } | |
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
29 |
258 | 30 bool success = !std::strcmp(str, "prefer-dark"); |
250 | 31 |
258 | 32 ::g_variant_unref(val); |
33 | |
34 if (success) | |
35 return true; | |
250 | 36 } |
37 | |
258 | 38 { |
39 GVariant* gtk_theme = ::g_settings_get_value(settings, "gtk-theme"); | |
40 if (!gtk_theme) { | |
41 ::g_object_unref(settings); | |
42 return false; | |
43 } | |
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
44 |
258 | 45 const gchar* gtk_theme_str = nullptr; |
46 ::g_variant_get(gtk_theme, "&s", gtk_theme_str); | |
47 if (!gtk_theme_str) { | |
48 ::g_variant_unref(gtk_theme); | |
49 ::g_object_unref(settings); | |
50 return false; | |
51 } | |
52 | |
53 static constexpr std::string_view suffix = "-dark"; | |
250 | 54 |
258 | 55 size_t gtk_theme_len = strlen(gtk_theme_str); |
250 | 56 |
258 | 57 if (gtk_theme_len < suffix.length()) { |
58 ::g_variant_unref(gtk_theme); | |
59 ::g_object_unref(settings); | |
60 return false; | |
61 } | |
250 | 62 |
258 | 63 bool success = !std::strncmp(gtk_theme_str + gtk_theme_len - suffix.length(), suffix.data(), suffix.length()); |
64 | |
65 ::g_variant_unref(gtk_theme); | |
66 ::g_object_unref(settings); | |
250 | 67 |
258 | 68 if (success) |
69 return true; | |
70 } | |
71 | |
72 return false; | |
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
73 } |
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
74 |
258 | 75 } // namespace glib |