Mercurial > minori
annotate 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 |
| 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> |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
3 |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
4 #include <iostream> |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
5 |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
6 namespace glib { |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
7 |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
8 bool IsInDarkTheme() { |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
9 GSettings* settings = g_settings_new("org.gnome.desktop.interface"); |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
10 if (!settings) |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
11 return false; |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
12 |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
13 GVariant* val = g_settings_get_value(settings, "color-scheme"); |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
14 if (!val) |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
15 return false; |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
16 |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
17 const gchar* str; |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
18 g_variant_get(val, "&s", &str); /* should not be freed */ |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
19 if (!str) /* how */ |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
20 return false; |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
21 |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
22 bool success = !std::strcmp(str, "prefer-dark"); |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
23 |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
24 /* unref these */ |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
25 g_variant_unref(val); |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
26 g_object_unref(settings); |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
27 |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
28 return success; |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
29 } |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
30 |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
31 } |
