annotate src/sys/glib/dark_theme.cc @ 256:6f3d193cb4b7

*: add missing binary data
author Paper <paper@paper.us.eu.org>
date Wed, 07 Feb 2024 17:06:31 -0500
parents c130f47f6f48
children 862d0d8619f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
232
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include <gio/gio.h>
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 #include <cstring>
250
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
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() {
250
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
8 bool success = false;
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
9
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 232
diff changeset
10 GSettings* settings = ::g_settings_new("org.gnome.desktop.interface");
232
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 if (!settings)
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 return false;
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 232
diff changeset
14 GVariant* val = ::g_settings_get_value(settings, "color-scheme");
232
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 if (!val)
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 return false;
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 const gchar* str;
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 232
diff changeset
19 ::g_variant_get(val, "&s", &str); /* should not be freed */
232
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 if (!str) /* how */
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 return false;
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22
250
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
23 success |= !std::strcmp(str, "prefer-dark");
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
24
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
25 ::g_variant_unref(val);
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
26
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
27 if (success) {
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
28 ::g_object_unref(settings);
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
29 return success;
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
30 }
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
31
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
32 GVariant* gtk_theme = ::g_settings_get_value(settings, "gtk-theme");
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
33 if (!gtk_theme)
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
34 return false;
232
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
35
250
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
36 const gchar* gtk_theme_str;
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
37 ::g_variant_get(gtk_theme, "&s", gtk_theme_str);
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
38 if (!gtk_theme_str)
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
39 return false;
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
40
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
41 static constexpr std::string_view suffix = "-dark";
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
42
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
43 size_t gtk_theme_len = strlen(gtk_theme_str);
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
44
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
45 success |= !std::strncmp(gtk_theme_str + gtk_theme_len - suffix.length(), suffix.data(), suffix.length());
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
46
236
4d461ef7d424 HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents: 232
diff changeset
47 ::g_object_unref(settings);
232
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
48 return success;
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
49 }
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50
ff0061e75f0f theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
51 }