#ifndef C8_POWER_PROFILES_H
#define C8_POWER_PROFILES_H
#include <gio/gio.h>
#include <stdbool.h>
#include <string.h>
/*
* Power modes from power-profiles-daemon (or tuned-ppd, which serves the
* same interface): what the shell's Power tile and PC settings' Power
* page both need to list them.
*/
#define C8_PPD_NAME "org.freedesktop.UPower.PowerProfiles"
#define C8_PPD_PATH "/org/freedesktop/UPower/PowerProfiles"
static const struct {
const char *name, *label;
} c8_power_profiles[] = {
{ "power-saver", "Power saver" },
{ "balanced", "Balanced" },
{ "performance", "Best performance" },
};
/* Whether the daemon behind proxy offers the profile */
static inline bool c8_power_profile_offered(GDBusProxy *proxy,
const char *name) {
GVariant *list = proxy ? g_dbus_proxy_get_cached_property(proxy,
"Profiles") : NULL;
if (list == NULL) {
return false;
}
bool found = false;
GVariantIter iter;
GVariant *dict;
g_variant_iter_init(&iter, list);
while (!found && (dict = g_variant_iter_next_value(&iter))) {
const char *profile;
if (g_variant_lookup(dict, "Profile", "&s", &profile)) {
found = strcmp(profile, name) == 0;
}
g_variant_unref(dict);
}
g_variant_unref(list);
return found;
}
#endif