From d1238f6a8e67ab4c137d5fcae4ac57171f4eb506 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Mon, 17 Feb 2025 12:50:56 +1100 Subject: bar: battery tooltip --- src/modules/bar.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/modules/bar.tsx') diff --git a/src/modules/bar.tsx b/src/modules/bar.tsx index cd36e42..2645fde 100644 --- a/src/modules/bar.tsx +++ b/src/modules/bar.tsx @@ -34,6 +34,12 @@ const getBatteryIcon = (perc: number) => { return "󰁹"; }; +const formatSeconds = (sec: number) => { + if (sec >= 3600) return `${Math.floor(sec / 3600)} hour${sec % 3600 === 0 ? "" : "s"}`; + if (sec >= 60) return `${Math.floor(sec / 60)} minute${sec % 60 === 0 ? "" : "s"}`; + return `${sec} second${sec === 1 ? "" : "s"}`; +}; + const hookFocusedClientProp = ( self: AstalWidget, prop: keyof AstalHyprland.Client, @@ -463,9 +469,17 @@ const NotifCount = () => ( ); const Battery = () => ( - `module battery ${p < 0.2 ? "low" : ""}`)}> + `module battery ${p < 0.2 ? "low" : ""}`)} + setup={self => + setupCustomTooltip( + self, + bind(AstalBattery.get_default(), "timeToEmpty").as(p => `${formatSeconds(p)} remaining`) + ) + } + > ); -- cgit v1.2.3-freya