We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2170 - Implement SDL_GetPowerInfo() on Linux using UPower
Summary: Implement SDL_GetPowerInfo() on Linux using UPower
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: main (show other bugs)
Version: HG 2.1
Hardware: x86_64 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-21 15:45 UTC by Bastien Nocera
Modified: 2017-08-15 05:17 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bastien Nocera 2013-10-21 15:45:50 UTC
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.
Comment 1 Ryan C. Gordon 2015-06-03 20:13:32 UTC
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.
Comment 2 Sam Lantinga 2017-08-15 05:17:31 UTC
Ryan implemented this here:
https://hg.libsdl.org/SDL/rev/5be3faa49e54