import { App, Astal, Gdk, Gtk, Widget } from "astal/gtk3"; import { GLib, Variable, bind } from "astal"; import Tray from "gi://AstalTray"; import { execAsync } from "astal/process" import Hyprland from "gi://AstalHyprland"; import { getIconName } from "./utils"; import Wp from "gi://AstalWp" import Battery from "gi://AstalBattery" const battery = Battery.get_default() const sensorsAvailable = await execAsync(['sensors']).then(() => true).catch(() => false); const wirePlumber = Wp.get_default(); function SysTray(): JSX.Element { const tray = Tray.get_default(); return ( {bind(tray, "items").as((items) => items.map((item) => { if (item.iconThemePath) App.add_icons(item.iconThemePath); return ( ["dbusmenu", ag])} menuModel={bind(item, "menuModel")}> ); }), )} ); } function Left() : JSX.Element { return ( ); } function Center() : JSX.Element { return ( ); } function Date({ format = "%Y-%m-%d" }): JSX.Element { const time = Variable("").poll(60000, () => GLib.DateTime.new_now_local().format(format)!) return } function Icons() { return ( ) } function Volume(): JSX.Element { if (!wirePlumber) return ; const audio = wirePlumber.audio; const icon = bind(audio.default_speaker, "volume").as((volume) => { const vol = volume * 100 const icon = [ [101, 'overamplified'], [67, 'high'], [34, 'medium'], [1, 'low'], [0, 'muted'], ].find(([threshold]) => Number(threshold) <= vol)?.[1] return `audio-volume-${icon}-symbolic` }); const css = bind(audio.default_speaker, "mute").as((mute) => { return mute ? "margin-left:0;": "margin-left: 0.7em;" }); return ( ); } function Workspaces() : JSX.Element { const hyprland = Hyprland.get_default(); return ( {bind(hyprland, "workspaces").as((wss) => {bind(hyprland, "focusedMonitor").as((fm) => wss.sort((a, b) => a.id - b.id) .filter(ws => ws && ws.get_monitor() && ws.get_monitor().get_id() === fm.get_id()) .map((ws) => ( )))} )} ); } function shorten(title: string) { return title.length > 40 ? title.slice(0, 20) + "..." : title } function Clients() : JSX.Element { const hyprland = Hyprland.get_default(); return ( { bind(hyprland, "focusedWorkspace").as(fw => ( { bind(hyprland, "clients").as(cls => cls .sort((a, b) => a.pid - b.pid) .filter(cl => !cl.title.includes("rofi")) .filter(cl => fw && cl.get_workspace().get_id() === fw.get_id()) .map(cl => ( a && a.address === cl.address ? "focused" : "unfocused")} > ) ) ) } ) ) } ); } export default function Bar(gdkmonitor: Gdk.Monitor, scaleFactor: number = 1): Widget.Window { return new Widget.Window({ gdkmonitor, css: "font-size: " + scaleFactor + "em;", exclusivity: Astal.Exclusivity.EXCLUSIVE, anchor: Astal.WindowAnchor.TOP | Astal.WindowAnchor.LEFT | Astal.WindowAnchor.RIGHT, application: App, className: "Bar", name: "top-bar", setup: self => self.connect("destroy", () => { print("Detroying bar"); App.remove_window(self); }), child:
}) }