| Summary: | Implement SDL_GetPowerInfo() on Linux using UPower | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Bastien Nocera <bugzilla> |
| Component: | main | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | bugzilla, icculus |
| Version: | HG 2.1 | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
I just implemented an updated SDL_GetPowerInfo() that parses the sysfs entries (which is basically what UPower does, I assume), which we would need anyhow for embedded systems that don't offer D-Bus, but I think talking to UPower is the preferred way to do this, so we should implement this at some point and keep the sysfs implementation as a fallback. The sysfs stuff is here: https://hg.libsdl.org/SDL/rev/d8cc85e50561 I'll take this bug for now, but I won't be hooking up to UPower before SDL 2.0.4 ships. --ryan. Ryan implemented this here: https://hg.libsdl.org/SDL/rev/5be3faa49e54 |
On Linux, OpenBSD and FreeBSD, one can use D-Bus to query the state of batteries. UPower 1.0, slated for release in 2014 along with GNOME 3.12, introduces a "display" battery that aggregates all the batteries and power state. This is the output of a command-line call that displays the battery info: $ gdbus call --system --dest org.freedesktop.UPower --object-path /org/freedesktop/UPower/devices/DisplayDevice --method org.freedesktop.DBus.Properties.GetAll 'org.freedesktop.UPower.Device' ({'NativePath': <''>, 'Vendor': <''>, 'Model': <''>, 'Serial': <''>, 'UpdateTime': <uint64 0>, 'Type': <uint32 2>, 'PowerSupply': <true>, 'HasHistory': <false>, 'HasStatistics': <false>, 'Online': <false>, 'Energy': <44.670000000000002>, 'EnergyEmpty': <0.0>, 'EnergyFull': <44.670000000000002>, 'EnergyFullDesign': <0.0>, 'EnergyRate': <10.019>, 'Voltage': <0.0>, 'Luminosity': <0.0>, 'TimeToEmpty': <int64 16050>, 'TimeToFull': <int64 0>, 'Percentage': <100.0>, 'Temperature': <0.0>, 'IsPresent': <true>, 'State': <uint32 2>, 'IsRechargeable': <false>, 'Capacity': <0.0>, 'Technology': <uint32 0>, 'WarningLevel': <uint32 1>, 'IconName': <'battery-full-symbolic'>},) And you can see that it makes it easy to implement returning the time-to-empty, the percentage of battery left, and even the state, even if there are multiple batteries. I haven't implemented it, as it would be quite a bit of code, and I'm wondering whether it's useful to games and other applications before implementing it.