i3 / i3status

Generates status bar to use with i3bar, dzen2 or xmobar
BSD 3-Clause "New" or "Revised" License
598 stars 251 forks source link

i3status doesn't distinguish between Idle and discharging battery. #488

Open adippl opened 2 years ago

adippl commented 2 years ago

At some point i3status on my computer stopped correctly displaying battery status while battery is idle. It is a really annoying bug. I'm using gentoo linux.

I've looked into the code and discovered that i3status treats Discharging and Not charging states the same way. Could you please considering merging this small patch to fix it? This is small change causes i3status to display status_unk string when battery state is detected as Not charging

diff --git a/src/print_battery_info.c b/src/print_battery_info.c
index 7465d17..f9fd037 100644
--- a/src/print_battery_info.c
+++ b/src/print_battery_info.c
@@ -187,8 +187,10 @@ static bool slurp_battery_info(battery_info_ctx_t *ctx, struct battery_info *bat
             batt_info->status = CS_CHARGING;
         else if (BEGINS_WITH(last, "POWER_SUPPLY_STATUS=Full"))
             batt_info->status = CS_FULL;
-        else if (BEGINS_WITH(last, "POWER_SUPPLY_STATUS=Discharging") || BEGINS_WITH(last, "POWER_SUPPLY_STATUS=Not charging"))
+        else if (BEGINS_WITH(last, "POWER_SUPPLY_STATUS=Discharging"))
             batt_info->status = CS_DISCHARGING;
+        else if (BEGINS_WITH(last, "POWER_SUPPLY_STATUS=Not charging"))
+            batt_info->status = CS_UNKNOWN;
         else if (BEGINS_WITH(last, "POWER_SUPPLY_STATUS="))
             batt_info->status = CS_UNKNOWN;
         else if (BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_FULL_DESIGN=") ||
simontunnat commented 2 years ago

I get the same issue on a ThinkPad X1 Nano:

$ cat /sys/class/power_supply/BAT0/status    

Not charging 

My other devices seem to only use the unknown status.

Would appreciate a bugfix for this.

adippl commented 2 years ago

I currently have i3status installed on 3 lenovo laptops: x270, T550, T480 All 3 laptops use Not charging state.

Example with dual batteries:

$ grep -n "" /sys/class/power_supply/BAT*/status
/sys/class/power_supply/BAT0/status:1:Not charging
/sys/class/power_supply/BAT1/status:1:Charging
erbth commented 1 year ago

Some time ago I run into this, too, and created #486. It adds another status and prints 'IDLE' when a battery is reported as "Not charging" by the driver. I've just rebased it to current main. If you like you could give it a try.