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 4920

Summary: Wider support for seconds of battery life left on Linux platforms using sys interface
Product: SDL Reporter: Murad <muradkarammaev>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: enhancement    
Priority: P2    
Version: 2.0.10   
Hardware: All   
OS: Linux   
Attachments: wider support for battery lifetime data on Linux platforms using sys interface

Description Murad 2019-12-27 11:57:35 UTC
Created attachment 4140 [details]
wider support for battery lifetime data on Linux platforms using sys interface

On my system, SDL_GetPowerInfo() returns -1 seconds of battery life left. I have quickly investigated that in my case SDL uses sys interface to get battery data. It tries to read "time_to_empty_now" file which is not always present. However, it is still possible to calculate remaining lifetime using "energy_now" and "power_now" files. This is what my simple patch (included as attachment) tries to accomplish.
Best wishes.
Comment 1 Murad 2019-12-27 12:05:25 UTC
This is my first contribution to any oss project ever, so, please, point me kindly at any mistake I have made. Thanks!
Comment 2 Sam Lantinga 2019-12-30 21:22:08 UTC
Patch added, thanks!
https://hg.libsdl.org/SDL/rev/8a12cc1abc9e