summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-02-17 12:40:34 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-02-17 12:40:34 +1100
commit94ac778fcda4b9245d40afb79e56e1fd9b1ba48d (patch)
tree29da102d52aff85a4bb4b7805fda93098fc4b780 /src
parentgpu: fix auto detection (diff)
downloadcaelestia-shell-94ac778fcda4b9245d40afb79e56e1fd9b1ba48d.tar.gz
caelestia-shell-94ac778fcda4b9245d40afb79e56e1fd9b1ba48d.tar.bz2
caelestia-shell-94ac778fcda4b9245d40afb79e56e1fd9b1ba48d.zip
bar: battery indicator
Diffstat (limited to 'src')
-rw-r--r--src/modules/bar.tsx22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/modules/bar.tsx b/src/modules/bar.tsx
index ea953d7..cd36e42 100644
--- a/src/modules/bar.tsx
+++ b/src/modules/bar.tsx
@@ -11,6 +11,7 @@ import { execAsync, register, Variable } from "astal";
import { bind, kebabify } from "astal/binding";
import { App, Astal, astalify, Gdk, Gtk, type ConstructProps } from "astal/gtk3";
import { bar as config } from "config";
+import AstalBattery from "gi://AstalBattery";
import AstalBluetooth from "gi://AstalBluetooth";
import AstalHyprland from "gi://AstalHyprland";
import AstalNetwork from "gi://AstalNetwork";
@@ -20,6 +21,19 @@ import AstalWp01 from "gi://AstalWp";
const hyprland = AstalHyprland.get_default();
+const getBatteryIcon = (perc: number) => {
+ if (perc < 0.1) return "󰁺";
+ if (perc < 0.2) return "󰁻";
+ if (perc < 0.3) return "󰁼";
+ if (perc < 0.4) return "󰁽";
+ if (perc < 0.5) return "󰁾";
+ if (perc < 0.6) return "󰁿";
+ if (perc < 0.7) return "󰂀";
+ if (perc < 0.8) return "󰂁";
+ if (perc < 0.9) return "󰂂";
+ return "󰁹";
+};
+
const hookFocusedClientProp = (
self: AstalWidget,
prop: keyof AstalHyprland.Client,
@@ -448,6 +462,13 @@ const NotifCount = () => (
</button>
);
+const Battery = () => (
+ <box className={bind(AstalBattery.get_default(), "percentage").as(p => `module battery ${p < 0.2 ? "low" : ""}`)}>
+ <label className="icon" label={bind(AstalBattery.get_default(), "percentage").as(getBatteryIcon)} />
+ <label label={bind(AstalBattery.get_default(), "percentage").as(p => `${p * 100}%`)} />
+ </box>
+);
+
const DateTime = () => (
<button
onClick={(self, event) => event.button === Astal.MouseButton.PRIMARY && togglePopup(self, event, "sideright")}
@@ -502,6 +523,7 @@ export default ({ monitor }: { monitor: Monitor }) => (
<StatusIcons />
<PkgUpdates />
<NotifCount />
+ {bind(AstalBattery.get_default(), "isBattery").as(b => b && <Battery />)}
<DateTime />
<Power />
</box>