view src/sys/glib/dark_theme.cc @ 241:06d6c351925c

*: reorganize resources, +docs, build translations with autotools
author Paper <paper@paper.us.eu.org>
date Mon, 22 Jan 2024 16:36:19 -0500
parents 4d461ef7d424
children c130f47f6f48
line wrap: on
line source

#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;
}

}