summaryrefslogtreecommitdiff
path: root/pkgs/astal/src/widget/bar/battery.lua
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/astal/src/widget/bar/battery.lua')
-rw-r--r--pkgs/astal/src/widget/bar/battery.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/pkgs/astal/src/widget/bar/battery.lua b/pkgs/astal/src/widget/bar/battery.lua
new file mode 100644
index 0000000..d13143a
--- /dev/null
+++ b/pkgs/astal/src/widget/bar/battery.lua
@@ -0,0 +1,21 @@
+local astal = require("astal")
+local Widget = require("astal.gtk3.widget")
+local Battery = astal.require("AstalBattery")
+local bind = astal.bind
+
+return function()
+ local bat = Battery.get_default()
+
+ return Widget.Box({
+ class_name = "battery",
+ visible = bind(bat, "is-present"),
+ Widget.Icon({
+ icon = bind(bat, "battery-icon-name"),
+ }),
+ Widget.Label({
+ label = bind(bat, "percentage"):as(function(p)
+ return tostring(math.floor(p * 100)) .. '%'
+ end)
+ }),
+ })
+end