From c27dc5147850a8026aec7e7753eb3b2538797fd8 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 3 Jul 2017 16:38:37 -0400 Subject: [PATCH] power: Linux /sys/class testing should skip "device" scopes. (the PS4 game controllers report their batteries through this interface, which is cool, but not helpful for powering the rest of the system. :) ) --- src/power/linux/SDL_syspower.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/power/linux/SDL_syspower.c b/src/power/linux/SDL_syspower.c index a53fca4a294b7..4c1d9d38f8d28 100644 --- a/src/power/linux/SDL_syspower.c +++ b/src/power/linux/SDL_syspower.c @@ -460,6 +460,16 @@ SDL_GetPowerInfo_Linux_sys_class_power_supply(SDL_PowerState *state, int *second continue; /* we don't care about UPS and such. */ } + /* if the scope is "device," it might be something like a PS4 + controller reporting its own battery, and not something that powers + the system. Most system batteries don't list a scope at all; we + assume it's a system battery if not specified. */ + if (read_power_file(base, name, "scope", str, sizeof (str))) { + if (SDL_strcmp(str, "device\n") != 0) { + continue; /* skip external devices with their own batteries. */ + } + } + /* some drivers don't offer this, so if it's not explicitly reported assume it's present. */ if (read_power_file(base, name, "present", str, sizeof (str)) && (SDL_strcmp(str, "0\n") == 0)) { st = SDL_POWERSTATE_NO_BATTERY;