comparison 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
comparison
equal deleted inserted replaced
249:6b2441c776dd 250:c130f47f6f48
1 #include <gio/gio.h> 1 #include <gio/gio.h>
2 #include <cstring> 2 #include <cstring>
3 3 #include <string_view>
4 #include <iostream>
5 4
6 namespace glib { 5 namespace glib {
7 6
8 bool IsInDarkTheme() { 7 bool IsInDarkTheme() {
8 bool success = false;
9
9 GSettings* settings = ::g_settings_new("org.gnome.desktop.interface"); 10 GSettings* settings = ::g_settings_new("org.gnome.desktop.interface");
10 if (!settings) 11 if (!settings)
11 return false; 12 return false;
12 13
13 GVariant* val = ::g_settings_get_value(settings, "color-scheme"); 14 GVariant* val = ::g_settings_get_value(settings, "color-scheme");
17 const gchar* str; 18 const gchar* str;
18 ::g_variant_get(val, "&s", &str); /* should not be freed */ 19 ::g_variant_get(val, "&s", &str); /* should not be freed */
19 if (!str) /* how */ 20 if (!str) /* how */
20 return false; 21 return false;
21 22
22 bool success = !std::strcmp(str, "prefer-dark"); 23 success |= !std::strcmp(str, "prefer-dark");
23 24
24 /* unref these */
25 ::g_variant_unref(val); 25 ::g_variant_unref(val);
26
27 if (success) {
28 ::g_object_unref(settings);
29 return success;
30 }
31
32 GVariant* gtk_theme = ::g_settings_get_value(settings, "gtk-theme");
33 if (!gtk_theme)
34 return false;
35
36 const gchar* gtk_theme_str;
37 ::g_variant_get(gtk_theme, "&s", gtk_theme_str);
38 if (!gtk_theme_str)
39 return false;
40
41 static constexpr std::string_view suffix = "-dark";
42
43 size_t gtk_theme_len = strlen(gtk_theme_str);
44
45 success |= !std::strncmp(gtk_theme_str + gtk_theme_len - suffix.length(), suffix.data(), suffix.length());
46
26 ::g_object_unref(settings); 47 ::g_object_unref(settings);
27
28 return success; 48 return success;
29 } 49 }
30 50
31 } 51 }