Use the aggregate upower device for power status when available
Build (All) / Create test plan (push) Has been cancelled
Build (All) / level1 (push) Has been cancelled
Build (All) / level2 (push) Has been cancelled

This commit is contained in:
Sam Lantinga
2025-12-19 17:41:52 -08:00
parent 190b902fac
commit 0d705ca275
+20 -3
View File
@@ -621,14 +621,29 @@ bool SDL_GetPowerInfo_Linux_org_freedesktop_upower(SDL_PowerState *state, int *s
#ifdef SDL_USE_LIBDBUS #ifdef SDL_USE_LIBDBUS
SDL_DBusContext *dbus = SDL_DBus_GetContext(); SDL_DBusContext *dbus = SDL_DBus_GetContext();
char **paths = NULL; char **paths = NULL;
char *path = NULL;
int i, numpaths = 0; int i, numpaths = 0;
if (!dbus || !SDL_DBus_CallMethodOnConnection(dbus->system_conn, UPOWER_DBUS_NODE, UPOWER_DBUS_PATH, UPOWER_DBUS_INTERFACE, "EnumerateDevices", if (!dbus) {
DBUS_TYPE_INVALID,
DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &paths, &numpaths, DBUS_TYPE_INVALID)) {
return false; // try a different approach than UPower. return false; // try a different approach than UPower.
} }
if (SDL_DBus_CallMethodOnConnection(dbus->system_conn, UPOWER_DBUS_NODE, UPOWER_DBUS_PATH, UPOWER_DBUS_INTERFACE, "GetDisplayDevice", DBUS_TYPE_INVALID, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) {
result = true; // Clearly we can use this interface.
*state = SDL_POWERSTATE_NO_BATTERY; // assume we're just plugged in.
*seconds = -1;
*percent = -1;
// Make a copy of the path before making more dbus calls
path = SDL_strdup(path);
if (!path) {
// Out of memory, try to do something else
return false;
}
check_upower_device(dbus->system_conn, path, state, seconds, percent);
SDL_free(path);
} else if (SDL_DBus_CallMethodOnConnection(dbus->system_conn, UPOWER_DBUS_NODE, UPOWER_DBUS_PATH, UPOWER_DBUS_INTERFACE, "EnumerateDevices", DBUS_TYPE_INVALID, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &paths, &numpaths, DBUS_TYPE_INVALID)) {
result = true; // Clearly we can use this interface. result = true; // Clearly we can use this interface.
*state = SDL_POWERSTATE_NO_BATTERY; // assume we're just plugged in. *state = SDL_POWERSTATE_NO_BATTERY; // assume we're just plugged in.
*seconds = -1; *seconds = -1;
@@ -639,6 +654,8 @@ bool SDL_GetPowerInfo_Linux_org_freedesktop_upower(SDL_PowerState *state, int *s
} }
dbus->free_string_array(paths); dbus->free_string_array(paths);
}
#endif // SDL_USE_LIBDBUS #endif // SDL_USE_LIBDBUS
return result; return result;