Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions i3status.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,18 @@ int main(int argc, char *argv[]) {
CFG_STR("format_percentage", "%.02f%s", CFGF_NONE),
CFG_STR("status_chr", "CHR", CFGF_NONE),
CFG_STR("status_bat", "BAT", CFGF_NONE),
CFG_STR("status_bat_low", "BAT", CFGF_NONE),
CFG_STR("status_bat_quarter", "BAT", CFGF_NONE),
CFG_STR("status_bat_half", "BAT", CFGF_NONE),
CFG_STR("status_bat_three_quarters", "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_INT("quarter_threshold", 45, CFGF_NONE),
CFG_INT("half_threshold", 60, CFGF_NONE),
CFG_INT("three_quarters_threshold", 75, CFGF_NONE),
CFG_STR("threshold_type", "time", CFGF_NONE),
CFG_BOOL("last_full_capacity", false, CFGF_NONE),
CFG_BOOL("integer_battery_capacity", false, CFGF_NONE),
Expand Down Expand Up @@ -741,10 +748,17 @@ int main(int argc, char *argv[]) {
.format_down = cfg_getstr(sec, "format_down"),
.status_chr = cfg_getstr(sec, "status_chr"),
.status_bat = cfg_getstr(sec, "status_bat"),
.status_bat_low = cfg_getstr(sec, "status_bat_low"),
.status_bat_quarter = cfg_getstr(sec, "status_bat_quarter"),
.status_bat_half = cfg_getstr(sec, "status_bat_half"),
.status_bat_three_quarters = cfg_getstr(sec, "status_bat_three_quarters"),
.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"),
.quarter_threshold = cfg_getint(sec, "quarter_threshold"),
.half_threshold = cfg_getint(sec, "half_threshold"),
.three_quarters_threshold = cfg_getint(sec, "three_quarters_threshold"),
.threshold_type = cfg_getstr(sec, "threshold_type"),
.last_full_capacity = cfg_getbool(sec, "last_full_capacity"),
.format_percentage = cfg_getstr(sec, "format_percentage"),
Expand Down
7 changes: 7 additions & 0 deletions include/i3status.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,17 @@ typedef struct {
const char *format_down;
const char *status_chr;
const char *status_bat;
const char *status_bat_low;
const char *status_bat_quarter;
const char *status_bat_half;
const char *status_bat_three_quarters;
const char *status_unk;
const char *status_full;
const char *status_idle;
int low_threshold;
int quarter_threshold;
int half_threshold;
int three_quarters_threshold;
char *threshold_type;
bool last_full_capacity;
const char *format_percentage;
Expand Down
46 changes: 41 additions & 5 deletions man/i3status.man
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ battery 0 {
low_threshold = 10
}

battery 1 {
format = "%status %percentage %remaining %emptytime"
format_down = "No battery"
status_chr = "⚡ CHR"
status_bat = "🔋 BAT"
status_unk = "? UNK"
status_full = "☻ FULL"
status_idle = "☻ IDLE"
status_bat_low = "LOW"
status_bat_half = "½"
status_bat_quarter = "¼"
status_bat_three_quarters = "¾"
path = "/sys/class/power_supply/BAT%d/uevent"
low_threshold = 15
quarter_threshold = 35
half_threshold = 65
threshold_type = "percentage"
}

run_watch DHCP {
pidfile = "/var/run/dhclient*.pid"
}
Expand Down Expand Up @@ -389,7 +408,8 @@ battery states. This makes it possible to display individual symbols
for each state (charging, discharging, unknown, full).
Of course it will also work with special iconic fonts, such as FontAwesome.
If any of these special status strings are omitted, the default (CHR, BAT, UNK,
FULL) is used.
FULL) is used. Battery capacity can also be shown with different custom strings
per quartile, with definable thresholds.

*Example order (for the first battery)*: +battery 0+

Expand All @@ -405,18 +425,34 @@ FULL) is used.

*Example status_bat*: +🔋 BAT+

*Example status_bat_half*: +½+

*Example status_bat_low*: +LOW+

*Example status_bat_quarter*: +¼+

*Example status_bat_three_quarters*: +¾+

*Example status_unk*: +? UNK+

*Example status_full*: +☻ FULL+

*Example low_threshold*: +30+

*Example threshold_type*: +time+
*Example threshold_type*: +time+ or +percentage+

*Example path (%d replaced by title number)*: +/sys/class/power_supply/CMB%d/uevent+

*Example path (ignoring the number)*: +/sys/class/power_supply/CMB1/uevent+

*Example half_threshold (e.g., percentage)*: +65+

*Example low_threshold*: +15+

*Example quarter_threshold*: +35+

*Example three_quarters_threshold*: +85+

=== CPU-Temperature

Gets the temperature of the given thermal zone. It is possible to
Expand Down Expand Up @@ -497,7 +533,7 @@ decimals can be configured via the +decimals+ option. If no such option is
given the converted format placeholder will have one decimal.

As Linux' meminfo doesn't expose the overall memory in use, there are multiple
methods to distinguish the actually used memory.
methods to distinguish the actually used memory.

*Example memory_used_method*: +memavailable+ ("total memory" - "MemAvailable", matches +free+ command)

Expand All @@ -524,7 +560,7 @@ methods to distinguish the actually used memory.
Gets the system load (number of processes waiting for CPU time in the last
1, 5 and 15 minutes). It is possible to define a max_threshold that will
color the load value +color_bad+ in case the load average of the last minute is
getting higher than the configured threshold. Defaults to 5. The output
getting higher than the configured threshold. Defaults to 5. The output
format when above +max_threshold+ can be customized with
+format_above_threshold+.

Expand Down Expand Up @@ -657,7 +693,7 @@ volume master {

Outputs the contents of the specified file. You can use this to check contents
of files on your system, for example /proc/uptime. By default the function only
reads the first 254 characters of the file, if you want to override this set
reads the first 254 characters of the file, if you want to override this set
the +Max_characters+ option. It will never read beyond the first 4095
characters. If the file is not found "no file" will be printed, if the file
can't be read "error read" will be printed.
Expand Down
60 changes: 49 additions & 11 deletions src/print_battery_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ static bool slurp_battery_info(battery_info_ctx_t *ctx, struct battery_info *bat
batt_info->status = CS_DISCHARGING;
#elif defined(__OpenBSD__)
/*
* We're using apm(4) here, which is the interface to acpi(4) on amd64/i386 and
* the generic interface on macppc/sparc64/zaurus. Machines that have ACPI
* battery sensors gain some extra information.
*/
* We're using apm(4) here, which is the interface to acpi(4) on amd64/i386 and
* the generic interface on macppc/sparc64/zaurus. Machines that have ACPI
* battery sensors gain some extra information.
*/
struct apm_power_info apm_info;
struct sensordev sensordev;
struct sensor sensor;
Expand Down Expand Up @@ -601,6 +601,10 @@ void print_battery_info(battery_info_ctx_t *ctx) {
.status = CS_UNKNOWN,
};
bool colorful_output = false;
bool discharging_low = false;
bool discharging_quarter = false;
bool discharging_half = false;
bool discharging_three_quarters = false;

#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__OpenBSD__)
/* These OSes report battery stats in whole percent. */
Expand Down Expand Up @@ -661,16 +665,38 @@ void print_battery_info(battery_info_ctx_t *ctx) {
batt_info.seconds_remaining = 0;
}

if (batt_info.status == CS_DISCHARGING && ctx->low_threshold > 0) {
if (batt_info.percentage_remaining >= 0 && strcasecmp(ctx->threshold_type, "percentage") == 0 && batt_info.percentage_remaining < ctx->low_threshold) {
START_COLOR("color_bad");
colorful_output = true;
} else if (batt_info.seconds_remaining >= 0 && strcasecmp(ctx->threshold_type, "time") == 0 && batt_info.seconds_remaining < 60 * ctx->low_threshold) {
START_COLOR("color_bad");
colorful_output = true;
if (batt_info.status == CS_DISCHARGING) {
if (!strcasecmp(ctx->threshold_type, "percentage")) {
if (batt_info.percentage_remaining <= ctx->low_threshold)
discharging_low = true;
else if (batt_info.percentage_remaining <= ctx->quarter_threshold)
discharging_quarter = true;
else if (batt_info.percentage_remaining <= ctx->half_threshold)
discharging_half = true;
else if (batt_info.percentage_remaining <= ctx->three_quarters_threshold)
discharging_three_quarters = true;
} else if (!strcasecmp(ctx->threshold_type, "time")) {
if (batt_info.seconds_remaining <= 60 * ctx->low_threshold)
discharging_low = true;
else if (batt_info.seconds_remaining <= 60 * ctx->quarter_threshold)
discharging_quarter = true;
else if (batt_info.seconds_remaining <= 60 * ctx->half_threshold)
discharging_half = true;
else if (batt_info.seconds_remaining <= 60 * ctx->three_quarters_threshold)
discharging_three_quarters = true;
}
}

if (discharging_low) {
START_COLOR("color_bad");
colorful_output = true;
}

if (discharging_quarter) {
START_COLOR("color_degraded");
colorful_output = true;
}

char string_status[STRING_SIZE];
char string_percentage[STRING_SIZE];
// following variables are not alwasy set. If they are not set they should be empty.
Expand All @@ -685,6 +711,18 @@ void print_battery_info(battery_info_ctx_t *ctx) {
break;
case CS_DISCHARGING:
statusstr = ctx->status_bat;

if (discharging_low && strcmp(ctx->status_bat_low, "BAT"))
statusstr = ctx->status_bat_low;

if (discharging_quarter && strcmp(ctx->status_bat_quarter, "BAT"))
statusstr = ctx->status_bat_quarter;

if (discharging_half && strcmp(ctx->status_bat_half, "BAT"))
statusstr = ctx->status_bat_half;

if (discharging_three_quarters && strcmp(ctx->status_bat_three_quarters, "BAT"))
statusstr = ctx->status_bat_three_quarters;
break;
case CS_FULL:
statusstr = ctx->status_full;
Expand Down
8 changes: 4 additions & 4 deletions src/print_eth_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ static int print_eth_speed(char *outwalk, const char *interface) {

for (desc = ifm_subtype_descriptions; desc->ifmt_string != NULL; desc++) {
/*
* Skip these non-informative values and go right ahead to the
* actual speeds.
*/
* Skip these non-informative values and go right ahead to the
* actual speeds.
*/
if (BEGINS_WITH(desc->ifmt_string, "autoselect") ||
BEGINS_WITH(desc->ifmt_string, "auto"))
continue;
Expand Down Expand Up @@ -157,7 +157,7 @@ void print_eth_info(eth_info_ctx_t *ctx) {
/*
* Removing '%' and following characters from IPv6 since the interface identifier is redundant,
* as the output already includes the interface name.
*/
*/
if (ipv6_address != NULL) {
char *prct_ptr = strstr(ipv6_address, "%");
if (prct_ptr != NULL) {
Expand Down
4 changes: 4 additions & 0 deletions testcases/027-battery-quartiles/BAT0_uevent
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_TIME_TO_EMPTY_NOW=655
POWER_SUPPLY_CHARGE_FULL_DESIGN=7800000
POWER_SUPPLY_CHARGE_NOW=7600000
4 changes: 4 additions & 0 deletions testcases/027-battery-quartiles/BAT0_uevent_half_pct
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_TIME_TO_EMPTY_NOW=655
POWER_SUPPLY_CHARGE_FULL_DESIGN=7800000
POWER_SUPPLY_CHARGE_NOW=3900000
4 changes: 4 additions & 0 deletions testcases/027-battery-quartiles/BAT0_uevent_half_time
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_TIME_TO_EMPTY_NOW=60
POWER_SUPPLY_CHARGE_FULL_DESIGN=7800000
POWER_SUPPLY_CHARGE_NOW=7600000
4 changes: 4 additions & 0 deletions testcases/027-battery-quartiles/BAT0_uevent_low_pct
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_TIME_TO_EMPTY_NOW=655
POWER_SUPPLY_CHARGE_FULL_DESIGN=7800000
POWER_SUPPLY_CHARGE_NOW=1014000
4 changes: 4 additions & 0 deletions testcases/027-battery-quartiles/BAT0_uevent_low_time
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_TIME_TO_EMPTY_NOW=30
POWER_SUPPLY_CHARGE_FULL_DESIGN=7800000
POWER_SUPPLY_CHARGE_NOW=7600000
4 changes: 4 additions & 0 deletions testcases/027-battery-quartiles/BAT0_uevent_quarter_pct
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_TIME_TO_EMPTY_NOW=655
POWER_SUPPLY_CHARGE_FULL_DESIGN=7800000
POWER_SUPPLY_CHARGE_NOW=1950000
4 changes: 4 additions & 0 deletions testcases/027-battery-quartiles/BAT0_uevent_quarter_time
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_TIME_TO_EMPTY_NOW=45
POWER_SUPPLY_CHARGE_FULL_DESIGN=7800000
POWER_SUPPLY_CHARGE_NOW=7600000
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_TIME_TO_EMPTY_NOW=655
POWER_SUPPLY_CHARGE_FULL_DESIGN=7800000
POWER_SUPPLY_CHARGE_NOW=5850000
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_TIME_TO_EMPTY_NOW=75
POWER_SUPPLY_CHARGE_FULL_DESIGN=7800000
POWER_SUPPLY_CHARGE_NOW=7600000
1 change: 1 addition & 0 deletions testcases/027-battery-quartiles/expected_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
L 13.00% 10:55 | Q 25.00% 10:55 | H 50.00% 10:55 | T 75.00% 10:55 | L 97.44% 00:30 | Q 97.44% 00:45 | H 97.44% 01:00 | T 97.44% 01:15 | BAT 97.44% 10:55
Loading