refactor!: start migration to latest ags

This commit is contained in:
2025-12-05 17:00:22 -08:00
parent 1759e2d976
commit 42b4f99c37
12 changed files with 191 additions and 147 deletions

View File

@@ -1,43 +1,35 @@
import { App, Astal, Gtk, Gdk } from "astal/gtk3";
import Workspaces from "./workspaces";
import Audio from "./audio";
import NetworkModule from "./network";
import Cpu from "./cpu-widget";
import Ram from "./ram";
import Disk from "./disk";
import Battery from "./battery";
import { Astal, Gtk, Gdk } from "ags/gtk4";
// import Workspaces from "./workspaces";
// import Audio from "./audio";
// import NetworkModule from "./network";
// import Cpu from "./cpu-widget";
// import Ram from "./ram";
// import Disk from "./disk";
// import Battery from "./battery";
import Time from "./time";
import Title from "./title";
import app from "ags/gtk4/app";
import Workspaces from "./workspaces";
export default function Bar(gdkmonitor: Gdk.Monitor) {
const { TOP, LEFT, RIGHT } = Astal.WindowAnchor;
//@ts-ignore
return (
<window
className="Bar"
visible
name="bar"
class="Bar"
gdkmonitor={gdkmonitor}
exclusivity={Astal.Exclusivity.EXCLUSIVE}
anchor={TOP | LEFT | RIGHT}
application={App}
application={app}
>
<centerbox>
<box hexpand halign={Gtk.Align.START}>
<box className="nix-icon">
<icon icon="nixos-3" />
</box>
<Workspaces monitor={gdkmonitor} />
</box>
<box className="client-title">
<Workspaces $type="start" monitor={gdkmonitor} />
<box $type="center" class="client-title">
<Title />
</box>
<box hexpand halign={Gtk.Align.END}>
<Audio />
<NetworkModule />
<Cpu />
<Ram />
<Disk />
<Battery />
<box $type="end">
<Time />
</box>
</centerbox>

View File

@@ -3,15 +3,16 @@ import AstalWp from "gi://AstalWp?version=0.1"
export default function Audio() {
const speaker = AstalWp.get_default()?.default_speaker!
const derived = Variable.derive([bind(speaker, "volume"), bind(speaker, "mute")], (volume: number, muted: boolean) => {
if (muted) {
return { label: ` (muted)`, muted }
}
return { label: `${Math.floor(volume * 100)}% ` }
})
// const derived = Variable.derive([bind(speaker, "volume"), bind(speaker, "mute")], (volume: number, muted: boolean) => {
// if (muted) {
// return { label: ` (muted)`, muted }
// }
// return { label: `${Math.floor(volume * 100)}% ` }
// })
// return <box className={derived((v) => ["status-box", v.muted && "inactive"].filter(Boolean).join(" "))}>
// <label
// label={derived((v) => v.label)} />
// </box>
return <box className={derived((v) => ["status-box", v.muted && "inactive"].filter(Boolean).join(" "))}>
<label
label={derived((v) => v.label)} />
</box>
}

View File

@@ -1,15 +1,24 @@
import { bind, GLib, Variable } from "astal"
// let current_time = Variable(GLib.DateTime.new_now_local().format("%H:%M"))
// GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, () => {
// const now = GLib.DateTime.new_now_local()
// current_time.set(now.format("%b %e (%a) %H:%M"))
// return true
let current_time = Variable(GLib.DateTime.new_now_local().format("%H:%M"))
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, () => {
const now = GLib.DateTime.new_now_local()
current_time.set(now.format("%b %e (%a) %H:%M"))
return true
})
import { createPoll } from "ags/time"
// })
export default function Time() {
const time = createPoll("", 500, () => {
return new Date().toLocaleString(undefined, {
hour12: false
})
})
return <box className="status-box">
<label label={bind(current_time)} />
return <box class="status-box">
<label label={time} />
</box>
// return <box class="status-box">
// <label label={bind(current_time)} />
// </box>
}

View File

@@ -1,5 +1,6 @@
import { bind, Variable } from "astal"
import { createPoll } from "ags/time";
import AstalHyprland from "gi://AstalHyprland?version=0.1";
import { createState } from "gnim";
const hyprland = AstalHyprland.get_default()
@@ -7,10 +8,15 @@ function get_title() {
return hyprland.focusedClient?.title ?? ""
}
const title = Variable(get_title()).poll(200, () => get_title())
// const title = Variable(get_title()).poll(200, () => get_title())
export default function Title() {
const title = createPoll("", 200, () => get_title())
return (
<label label={title(t => t)} />
<label label={title} />
)
// return (
// <label label={title(t => t)} />
// )
}

View File

@@ -1,23 +1,35 @@
import { bind } from "astal"
import { Gdk } from "astal/gtk3"
import { Gdk } from "ags/gtk4"
import AstalHyprland from "gi://AstalHyprland?version=0.1"
import { createBinding, For } from "gnim"
export default function Workspaces({ monitor }: { monitor: Gdk.Monitor }) {
const hypr = AstalHyprland.get_default()
const workspaces = createBinding(hypr, "workspaces").as(wss => wss.sort((a, b) => a.id - b.id))
return <box className="workspaces">
{bind(hypr, "workspaces").as(wss => wss.filter(ws => !(ws.id >= -99 && ws.id <= -2))
.sort((a, b) => a.id - b.id)
.map(ws => {
if (ws.monitor.model !== monitor.model) return <></>
return (
<button
className={bind(hypr, "focusedWorkspace").as(fw =>
ws === fw ? "focused" : "")}
onClicked={() => ws.focus()}>
{ws.id}
return (
<box class="workspaces">
<For each={workspaces}>
{(ws) => (
<button class={createBinding(hypr, "focusedWorkspace").as((fw) => ws === fw ? "focused" : "")}>
<label label={ws.id.toString()} />
</button>
)
}))}
</box>
)}
</For>
</box>
)
// return <box className="workspaces">
// {bind(hypr, "workspaces").as(wss => wss.filter(ws => !(ws.id >= -99 && ws.id <= -2))
// .sort((a, b) => a.id - b.id)
// .map(ws => {
// if (ws.monitor.model !== monitor.model) return <></>
// return (
// <button
// className={bind(hypr, "focusedWorkspace").as(fw =>
// ws === fw ? "focused" : "")}
// onClicked={() => ws.focus()}>
// {ws.id}
// </button>
// )
// }))}
// </box>
}