Mercurial > minori
annotate 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 |
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 | 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 | 8 bool success = false; |
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 | 23 success |= !std::strcmp(str, "prefer-dark"); |
24 | |
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; | |
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
35 |
250 | 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 | |
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 } |