Added battey state widget

This commit is contained in:
pascalyazid committed 2026-03-25 23:49:59 +01:00
1 parent a65fa79bc3
commit 93be64eeaf
4 files changed
+40 -3

No files matched your search

+17 -1
View File
@@ -6,7 +6,8 @@
"": {
"dependencies": {
"ags": "*",
"gnim": "*"
"gnim": "*",
"prettier": "^3.8.1"
},
"devDependencies": {
"@eslint/js": "^10.0.1",
@@ -1121,6 +1122,21 @@
"node": ">= 0.8.0"
}
},
"node_modules/prettier": {
"version": "3.8.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.8.1.tgz",
"integrity": "sha512-UOnG6LftzbdaHZcKoPFtOcCKztrQ57WkHDeRD9t/PTQtmT0NHSeWWepj6pS0z/N7+08BHFDQVUrfmfMRcZwbMg==",
"license": "MIT",
"bin": {
"prettier": "bin/prettier.cjs"
},
"engines": {
"node": ">=14"
},
"funding": {
"url": "https://github.com/prettier/prettier?sponsor=1"
}
},
"node_modules/punycode": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
+1 -1
View File
@@ -72,7 +72,7 @@ window.Bar {
margin: 2px;
.tray-item {
padding: 2px 4px; // Reduced vertical padding
//padding: 2px 4px; // Reduced vertical padding
margin: 0;
background: transparent;
border: none;
+2 -1
View File
@@ -1,7 +1,7 @@
import app from "ags/gtk4/app"
import { Astal, Gtk, Gdk } from "ags/gtk4"
import Workspaces from "./Workspaces"
import { Clock, SysTray } from "./System"
import { Clock, SysTray, Battery } from "./System"
import Media from "./Media"
import Controls from "./Controls"
import ThemeSwitcher from "./ThemeSwitcher"
@@ -38,6 +38,7 @@ function Right({ gdkmonitor }: { gdkmonitor: Gdk.Monitor }) {
>
<ThemeSwitcher />
<SysTray />
<Battery />
<Controls gdkmonitor={gdkmonitor} />
</box>
)
+20
View File
@@ -1,6 +1,7 @@
import { Gtk } from "ags/gtk4"
import { createPoll } from "ags/time"
import AstalTray from "gi://AstalTray?version=0.1"
import AstalBattery from "gi://AstalBattery?version=0.1"
import { createBinding, For } from "ags"
export function Clock() {
@@ -55,3 +56,22 @@ export function SysTray() {
</box>
)
}
export function Battery() {
const bat = AstalBattery.get_default()
return (
<box
visible={createBinding(bat, "is-present")}
cssClasses={["battery"]}
valign={Gtk.Align.CENTER}
spacing={4}
>
<image iconName={createBinding(bat, "icon-name")} />
<label
label={createBinding(bat, "percentage").as(
(p) => `${Math.floor(p * 100)}%`,
)}
/>
</box>
)
}