// SPDX-License-Identifier: MIT // Copyright (C) 2026 Pooya Parsa // The desktop's resource widget (#desk-res): a slim right-aligned column // straight on the wallpaper in the workspace's top right corner, under every // window (Workspace.tsx; not in compact mode, where a window always covers // it). A line per resource: its history fading in from the left (stats.ts, // the last three minutes), then its value and name; the facts are in the // tooltip. One tint for all (style.css .desk-widget: white, or black on a // light wallpaper), amber from 85 % and red from 95 %. The disk only with a // data disk, the network only when on, the GPU and Vulkan only while their // renderer is loaded. Its button (#desk-res-toggle) hides the lines and // stays, alone in the corner, to show them again (widget.ts keeps which). It // takes the light samples; hidden, none. A press on it keeps the focus where // it is (the terminal). import { fmtBytes, fmtPct, fmtRate, fmtRateShort } from "../format.ts"; import { KW } from "../kw.ts"; import { useStats, type Point } from "../stats.ts"; import { useStore } from "../store.ts"; import { toggleWidget, useWidget } from "../widget.ts"; import { Spark, type Series } from "./Charts.tsx"; import { diskUse, GPU_STATE, gpuSeries, latest, VK_STATE, vkSeries } from "./Glance.tsx"; import { ActivityIcon, ChevronIcon } from "./icons.tsx"; const LINE = "var(--color-fg)", LINE2 = "var(--color-faint)"; /** A share's tone, as the top bar's meters. */ const tone = (v: number | null) => (v == null ? "" : v >= 0.95 ? "text-err" : v >= 0.85 ? "text-warn" : ""); function Line({ label, value, title, cls = "", points, series, max, fmt }: { label: string; value: string; title: string; cls?: string; points: Point[]; series: Series[]; max?: number; fmt: (v: number) => string; }) { return (
{value}
{label}
); } function Lines() { const st = useStats("lite"); const disk = useStore((s) => s.disk); const g = !st.waiting && !st.idle ? st.guest : null; const why = st.idle ? `not sampled: ${st.idle}` : "waiting for the guest"; const points = st.points; const cpu = g?.derived.cpu ?? null, load = g?.raw.load; const m = g?.raw.mem, used = m ? m.total - m.available : 0, mem = m && m.total > 0 ? used / m.total : null; const du = diskUse(st, disk), full = du ? du.used / du.size : null; const rx = g?.derived.rx ?? null, tx = g?.derived.tx ?? null; const gpu = st.gpu?.state === "ready" || st.gpu?.state === "lost" ? st.gpu : null, gs = gpu && gpuSeries(gpu), gv = gs && latest(points, gs.get); const vk = st.vk?.state === "ready" || st.vk?.state === "lost" ? st.vk : null, vs = vk && vkSeries(points), vv = vs && latest(points, vs.get); return (
p.cpu, label: "busy", color: LINE, area: true }]} /> p.mem, label: "in use", color: LINE, area: true }]} /> {du && p.rd, label: "read", color: LINE, area: true }, { get: (p) => p.wr, label: "write", color: LINE2 }]} />} {KW.config.net && p.rx, label: "in", color: LINE, area: true }, { get: (p) => p.tx, label: "out", color: LINE2 }]} />} {gpu && gs && } {vk && vs && }
); } export function ResourcesWidget() { const on = useWidget(); const label = on ? "Hide resources" : "Show resources"; return ( ); }