Skip to content

Commit

Permalink
Merge pull request #486 from erbth/battery_status_idle
Browse files Browse the repository at this point in the history
Add another battery status called 'idle'
  • Loading branch information
orestisfl authored Jul 28, 2023
2 parents 8a91843 + 3272abc commit 6dac867
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions i3status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions include/i3status.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions man/i3status.man
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 14 additions & 1 deletion src/print_battery_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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=") ||
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion testcases/023-battery-not-charging/expected_output.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BAT
IDLE

0 comments on commit 6dac867

Please sign in to comment.