comparison src/sys/glib/dark_theme.cc @ 232:ff0061e75f0f

theme: add OS detection with glib
author Paper <mrpapersonic@gmail.com>
date Sat, 13 Jan 2024 11:06:16 -0500
parents
children 4d461ef7d424
comparison
equal deleted inserted replaced
231:69f4768a820c 232:ff0061e75f0f
1 #include <gio/gio.h>
2 #include <cstring>
3
4 #include <iostream>
5
6 namespace glib {
7
8 bool IsInDarkTheme() {
9 GSettings* settings = g_settings_new("org.gnome.desktop.interface");
10 if (!settings)
11 return false;
12
13 GVariant* val = g_settings_get_value(settings, "color-scheme");
14 if (!val)
15 return false;
16
17 const gchar* str;
18 g_variant_get(val, "&s", &str); /* should not be freed */
19 if (!str) /* how */
20 return false;
21
22 bool success = !std::strcmp(str, "prefer-dark");
23
24 /* unref these */
25 g_variant_unref(val);
26 g_object_unref(settings);
27
28 return success;
29 }
30
31 }