diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/sys/glib/dark_theme.cc	Sat Jan 13 11:06:16 2024 -0500
@@ -0,0 +1,31 @@
+#include <gio/gio.h>
+#include <cstring>
+
+#include <iostream>
+
+namespace glib {
+
+bool IsInDarkTheme() {
+	GSettings* settings = g_settings_new("org.gnome.desktop.interface");
+	if (!settings)
+		return false;
+
+	GVariant* val = g_settings_get_value(settings, "color-scheme");
+	if (!val)
+		return false;
+
+	const gchar* str;
+	g_variant_get(val, "&s", &str); /* should not be freed */
+	if (!str) /* how */
+		return false;
+
+	bool success = !std::strcmp(str, "prefer-dark");
+
+	/* unref these */
+	g_variant_unref(val);
+	g_object_unref(settings);
+
+	return success;
+}
+
+}