Add tooltip to eww-battery-monitor

This commit is contained in:
Alexander Rosenberg 2025-02-06 15:09:37 -08:00
parent c8657e9378
commit a4106633c8
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

View File

@ -56,13 +56,24 @@ function warn_if_low() {
function print_state() {
percentage = state_info["percentage"]
printf "%s%s%d%%\n",
tooltip = ""
if (state_info["charging"]) {
tooltip = "Until Full: " state_info["time to full"]
} else {
tooltip = "Until Empty: " state_info["time to empty"]
}
printf "{\"text\":\"%s%s%d%%\",\"tooltip\":\"%s\"}\n",
get_icon(percentage),
state_info["charging"] ? "󱐋" : "",
percentage
percentage,
tooltip
fflush()
}
function string_or(str, def) {
return str == "" ? def : str
}
function parse_record(record, exit_on_absent) {
split(record, fields)
for (i in fields) {
@ -77,6 +88,8 @@ function parse_record(record, exit_on_absent) {
} else if ((! BATTERY && props["power supply"] == "yes" && \
props["native-path"] ~ /BAT[0-9]+/) || name == BATTERY) {
state_info["percentage"] = props["percentage"] + 0
state_info["time to full"] = string_or(props["time to full"], "Unknown")
state_info["time to empty"] = string_or(props["time to empty"], "Unknown")
return 1
} else if ((! ADAPTER && props["power supply"] == "yes" && \
props["native-path"] ~ /ADP[0-9]+/) || name == ADAPTER) {