Added workspace widget

This commit is contained in:
Pascal Thuma committed 2026-03-24 19:28:41 +01:00
1 parent fe35b5b10b
commit 01f10ccf92
3 files changed
+44 -1

No files matched your search

+2 -1
View File
@@ -1,10 +1,11 @@
import app from "ags/gtk4/app"
import { Astal, Gtk, Gdk } from "ags/gtk4"
import Workspaces from "./Workspaces"
function Left() {
return (
<box $type="start" halign={Gtk.Align.START} cssClasses={["left-box"]}>
<label label="Left Widget Area" />
<Workspaces />
</box>
)
}
+27
View File
@@ -0,0 +1,27 @@
import { Gtk } from "ags/gtk4"
import { execAsync } from "ags/process"
import { createPoll } from "ags/time"
export default function Workspaces() {
// Poll the active workspace ID from Hyprland
const activeWs = createPoll(1, 250, (prev) =>
execAsync("hyprctl activeworkspace -j")
.then((out) => JSON.parse(out).id as number)
.catch(() => prev),
)
return (
<box cssClasses={["workspaces"]} spacing={4}>
{Array.from({ length: 9 }, (_, i) => i + 1).map((i) => (
<button
cssClasses={activeWs((active) =>
active === i ? ["workspace-btn", "active"] : ["workspace-btn"],
)}
onClicked={() => execAsync(`hyprctl dispatch workspace ${i}`)}
>
<label label={`${i}`} />
</button>
))}
</box>
)
}