feat: ags

This commit is contained in:
2024-12-27 15:42:51 +03:00
parent 21fe030dc7
commit 8ea1207bb9
21 changed files with 357 additions and 1214 deletions

View File

@ -0,0 +1,15 @@
import { bind } from "astal"
import Wp from "gi://AstalWp"
export default function Audio() {
const speaker = Wp.get_default()?.audio.defaultSpeaker!
return <box className="AudioSlider" css="min-width: 140px">
<icon icon={bind(speaker, "volumeIcon")} />
<slider
hexpand
onDragged={({ value }) => speaker.volume = value}
value={bind(speaker, "volume")}
/>
</box>
}

View File

@ -0,0 +1,14 @@
import { bind } from "astal"
import Battery from "gi://AstalBattery"
export default function BatteryLevel() {
const bat = Battery.get_default()
return <box className="Battery"
visible={bind(bat, "isPresent")}>
<icon icon={bind(bat, "batteryIconName")} />
<label label={bind(bat, "percentage").as(p =>
`${Math.floor(p * 100)} %`
)} />
</box>
}

View File

@ -0,0 +1,28 @@
import { bind } from "astal"
import { Gtk } from "astal/gtk3"
import Mpris from "gi://AstalMpris"
export default function Media() {
const mpris = Mpris.get_default()
return <box className="Media">
{bind(mpris, "players").as(ps => ps[0] ? (
<box>
<box
className="Cover"
valign={Gtk.Align.CENTER}
css={bind(ps[0], "coverArt").as(cover =>
`background-image: url('${cover}');`
)}
/>
<label
label={bind(ps[0], "title").as(() =>
`${ps[0].title} - ${ps[0].artist}`
)}
/>
</box>
) : (
"Nothing Playing"
))}
</box>
}

View File

@ -0,0 +1,18 @@
import { bind } from "astal"
import Tray from "gi://AstalTray"
export default function SysTray() {
const tray = Tray.get_default()
return <box className="SysTray">
{bind(tray, "items").as(items => items.map(item => (
<menubutton
tooltipMarkup={bind(item, "tooltipMarkup")}
usePopover={false}
actionGroup={bind(item, "action-group").as(ag => ["dbusmenu", ag])}
menuModel={bind(item, "menu-model")}>
<icon gicon={bind(item, "gicon")} />
</menubutton>
)))}
</box>
}

View File

@ -0,0 +1,12 @@
import { Variable, GLib } from "astal"
export default function Time({ format = "%H:%M - %A %e." }) {
const time = Variable<string>("").poll(1000, () =>
GLib.DateTime.new_now_local().format(format)!)
return <label
className="Time"
onDestroy={() => time.drop()}
label={time()}
/>
}

View File

@ -0,0 +1,17 @@
import { bind } from "astal"
import Network from "gi://AstalNetwork"
export default function Wifi() {
const network = Network.get_default()
const wifi = bind(network, "wifi")
return <box visible={wifi.as(Boolean)}>
{wifi.as(wifi => wifi && (
<icon
tooltipText={bind(wifi, "ssid").as(String)}
className="Wifi"
icon={bind(wifi, "iconName")}
/>
))}
</box>
}

View File

@ -0,0 +1,21 @@
import { bind } from "astal"
import Hyprland from "gi://AstalHyprland"
export default function Workspaces() {
const hypr = Hyprland.get_default()
return <box className="Workspaces">
{bind(hypr, "workspaces").as(wss => wss
.filter(ws => !(ws.id >= -99 && ws.id <= -2)) // filter out special workspaces
.sort((a, b) => a.id - b.id)
.map(ws => (
<button
className={bind(hypr, "focusedWorkspace").as(fw =>
ws === fw ? "focused" : "")}
onClicked={() => ws.focus()}>
{ws.id}
</button>
))
)}
</box>
}