diff --git a/i3status.c b/i3status.c index 88fb90e0..2f60b4e5 100644 --- a/i3status.c +++ b/i3status.c @@ -322,6 +322,7 @@ int main(int argc, char *argv[]) { CFG_STR("status_bat", "BAT", CFGF_NONE), CFG_STR("status_unk", "UNK", CFGF_NONE), CFG_STR("status_full", "FULL", CFGF_NONE), + CFG_STR("status_idle", "IDLE", CFGF_NONE), CFG_STR("path", "/sys/class/power_supply/BAT%d/uevent", CFGF_NONE), CFG_INT("low_threshold", 30, CFGF_NONE), CFG_STR("threshold_type", "time", CFGF_NONE), @@ -742,6 +743,7 @@ int main(int argc, char *argv[]) { .status_bat = cfg_getstr(sec, "status_bat"), .status_unk = cfg_getstr(sec, "status_unk"), .status_full = cfg_getstr(sec, "status_full"), + .status_idle = cfg_getstr(sec, "status_idle"), .low_threshold = cfg_getint(sec, "low_threshold"), .threshold_type = cfg_getstr(sec, "threshold_type"), .last_full_capacity = cfg_getbool(sec, "last_full_capacity"), diff --git a/include/i3status.h b/include/i3status.h index fe44780b..1bc2c85f 100644 --- a/include/i3status.h +++ b/include/i3status.h @@ -271,6 +271,7 @@ typedef struct { const char *status_bat; const char *status_unk; const char *status_full; + const char *status_idle; int low_threshold; char *threshold_type; bool last_full_capacity; diff --git a/man/i3status.man b/man/i3status.man index 725c27c6..3cd231cb 100644 --- a/man/i3status.man +++ b/man/i3status.man @@ -87,6 +87,7 @@ battery 0 { status_bat = "🔋 BAT" status_unk = "? UNK" status_full = "☻ FULL" + status_idle = "☻ IDLE" path = "/sys/class/power_supply/BAT%d/uevent" low_threshold = 10 } diff --git a/src/print_battery_info.c b/src/print_battery_info.c index 7465d171..8864978b 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -49,6 +49,7 @@ typedef enum { CS_DISCHARGING, CS_CHARGING, CS_FULL, + CS_IDLE, } charging_status_t; /* A description of the state of one or more batteries. */ @@ -129,6 +130,13 @@ static void add_battery_info(struct battery_info *acc, const struct battery_info acc->status = batt_info->status; /* else: retain FULL, since it is more specific than UNKNOWN */ break; + + case CS_IDLE: + if (batt_info->status != CS_UNKNOWN && batt_info->status != CS_FULL) + acc->status = batt_info->status; + /* else: retain IDLE, since it is more specific than UNKNOWN and is + * implied by CS_FULL though correct for all batteries */ + break; } acc->present_rate = abs(present_rate); @@ -187,8 +195,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_IDLE; else if (BEGINS_WITH(last, "POWER_SUPPLY_STATUS=")) batt_info->status = CS_UNKNOWN; else if (BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_FULL_DESIGN=") || @@ -674,6 +684,9 @@ void print_battery_info(battery_info_ctx_t *ctx) { case CS_FULL: statusstr = ctx->status_full; break; + case CS_IDLE: + statusstr = ctx->status_idle; + break; default: statusstr = ctx->status_unk; } diff --git a/testcases/023-battery-not-charging/expected_output.txt b/testcases/023-battery-not-charging/expected_output.txt index 6fc5dfbb..0ec43b39 100644 --- a/testcases/023-battery-not-charging/expected_output.txt +++ b/testcases/023-battery-not-charging/expected_output.txt @@ -1 +1 @@ -BAT +IDLE