diff --git a/eww/eww-battery-monitor b/eww/eww-battery-monitor index d5ae9c7..cc0fe37 100755 --- a/eww/eww-battery-monitor +++ b/eww/eww-battery-monitor @@ -56,13 +56,24 @@ function warn_if_low() { function print_state() { percentage = state_info["percentage"] - printf "%s%s%d%%\n", - get_icon(percentage), - state_info["charging"] ? "󱐋" : "", - percentage + 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, + 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) {