battery as well as battery_short display the battery status but allways with the percentage.
So if i want to show different colors or icons instead of text there is no simple option.
So i'd like an option to get the battery status.

2 years, 8 months passed. Okay, I understand what you want. You want {battery_status} to print Discharging, Charging, Full, Empty, Unknown. We should add this so you can use this with conky conditionals.
I think we should remove percentages too... in battery and battery_short in favor of existing {battery_percent}. I think I'd remove {battery_short} variable too in favor of {battery_status} + conky conditionals where users can make it short again (or replace it with icons now).
Conky conditionals. Untested.
-- replaces ${battery_status} with icons
${if_match ${battery_status}==Discharging}🔋${endif}
${if_match ${battery_status}==Charging}âš¡${endif}
${if_match ${battery_status}==Full}☻${endif}
-- ${if_match ${battery_status}==Empty}E${endif} -- skip empty
-- ${if_match ${battery_status}==Unknown}?${endif} -- skip unknown
-- behaves like ${battery_short}
${if_match ${battery_status}==Discharging}D${endif}
${if_match ${battery_status}==Charging}C${endif}
${if_match ${battery_status}==Full}F${endif}
-- ${if_match ${battery_status}==Empty}E${endif} -- skip empty
-- ${if_match ${battery_status}==Unknown}U${endif} -- skip unknown
Is this change okay with you? @brndnmtthws
EDIT: Actually, it'd be just {battery} now because of percentages. If we want to simplify variables too since {battery} and {battery_short} contains combined variables, we would have no more than...
battery_statusbattery_barbattery_percentbattery_time@su8 We can close this today. Easy peasy.
@su8 We can close this today. Easy peasy.
What's about to be changed exactly ?
So i'd like an option to get the battery status.
So he/she/it would like a new variable called ${battery_status} to be added that prints the Discharging/Charging/Full/etc ?
Yes... He/she/it want to if_match against discharging. He/she/it claims he/she/it can't if_match because of the percents, but we know that's not true... because technically, he/she/it can make all 100 if_match lines, one for each percent, but no, he/she/it want an easy life... so he/she/it files this issue instead of working his/her/it ass off making us fixing this issue to make him/her/it happy.
I think we should break everything to correct battery_* variables for once and all.
battery_status, eg dischargingbattery_bar, eg ######....battery_percent, eg 85battery_time, eg 2h 17 10sOkay that's easy then.
With Upper or Lower Case to print the status ?
I think leave it as-is, which is Upper.... based on /sys/class/power_supply/BAT0/status.
Can you test this diff since I no longer have laptop, ${battery_status BAT0}
diff --git a/src/core.cc b/src/core.cc
index 7a438b2e..725823f8 100644
--- a/src/core.cc
+++ b/src/core.cc
@@ -545,6 +545,10 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->data.s = strndup(bat, text_buffer_size.get(*state));
obj->callbacks.print = &print_battery_short;
obj->callbacks.free = &gen_free_opaque;
+
+ END OBJ(battery_status, 0) obj->data.s = STRNDUP_ARG;
+ obj->callbacks.print = &print_battery_status;
+ obj->callbacks.free = &gen_free_opaque;
END OBJ(battery_time, nullptr) char bat[64];
if (arg != nullptr) {
diff --git a/src/linux.cc b/src/linux.cc
index a9c65a86..19cd0dcd 100644
--- a/src/linux.cc
+++ b/src/linux.cc
@@ -2185,6 +2185,23 @@ void get_battery_short_status(char *buffer, unsigned int n, const char *bat) {
// Otherwise, don't shorten.
}
+void print_battery_status(struct text_object *obj, char *p, unsigned int p_max_size) {
+ get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
+ if (0 == strncmp("charging", p, 8)) {
+ snprintf(p, p_max_size, "%s", "Charging");
+ } else if (0 == strncmp("discharging", p, 11)) {
+ snprintf(p, p_max_size, "%s", "Discharging");
+ } else if (0 == strncmp("charged", p, 7)) {
+ snprintf(p, p_max_size, "%s", "Charged");
+ } else if (0 == strncmp("not present", p, 11)) {
+ snprintf(p, p_max_size, "%s", "Not present");
+ } else if (0 == strncmp("empty", p, 5)) {
+ snprintf(p, p_max_size, "%s", "Empty");
+ } else if (0 == strncmp("unknown", p, 7)) {
+ snprintf(p, p_max_size, "%s", "Unknown");
+ }
+}
+
int _get_battery_perct(const char *bat) {
static int rep = 0;
int idx;
diff --git a/src/linux.h b/src/linux.h
index 6468bcb3..1943cc93 100644
--- a/src/linux.h
+++ b/src/linux.h
@@ -39,6 +39,7 @@ int gateway_exists(struct text_object *);
void print_gateway_iface(struct text_object *, char *, unsigned int);
void print_gateway_iface2(struct text_object *, char *, unsigned int);
void print_gateway_ip(struct text_object *, char *, unsigned int);
+void print_battery_status(struct text_object *, char *, unsigned int);
enum { PB_BATT_STATUS, PB_BATT_PERCENT, PB_BATT_TIME };
void get_powerbook_batt_info(struct text_object *, char *, unsigned int);
No more diffs. From now on, link me to your branches. I have rarely used laptop here. Can test. Gotta update system (Idk when last time), install build essentials, install conky, etc.
EDIT: It's good idea to force you to do this.. so you can get better at git over time. First one. <3
This does not seems to remove battery_short and other things I wanted to break?
It's good idea to battery_short, someone might be using it and if we remove it (like the weather) things will break and no longer work.
What things will break?
The user config will no longer print the battery_short status.
Then he/she/it should update their config... to ${battery_status} ${battery_percent}. In fact, ${battery_short} looks too damn like ${battery_percent} so I'm not convinced that it's useful to keep it. Also, our He/she/it want ${battery_status} to display icons instead. It can be done exactly the same way to display single characters.
EDIT: ${if_match ${battery_status}==Discharging}D${else}${if_match ${battery_status}==Charging}C${else}${if_match ${battery_status}==Full}F${endif}
While waiting on your reply to see whether the code is working, I'll be watching a movie :blush:
Dusting off old Manjaro i3wm.

Most helpful comment
Yes... He/she/it want to
if_matchagainstdischarging. He/she/it claims he/she/it can'tif_matchbecause of the percents, but we know that's not true... because technically, he/she/it can make all 100if_matchlines, one for each percent, but no, he/she/it want an easy life... so he/she/it files this issue instead of working his/her/it ass off making us fixing this issue to make him/her/it happy.I think we should break everything to correct
battery_*variables for once and all.battery_status, egdischargingbattery_bar, eg######....battery_percent, eg85battery_time, eg2h 17 10s