From eaba3a8978210f466d9eacb83a76ef2e2ffa10ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Av=C3=A9?= Date: Wed, 9 Jul 2025 16:09:53 +0200 Subject: [PATCH] Working on porting to new ags version --- home/ags/files/Bar.tsx | 218 +++++++++--------- home/ags/files/app.ts | 19 +- home/ags/files/env.d.ts | 16 +- home/ags/files/notifications/Notification.tsx | 28 +-- .../notifications/NotificationPopups.tsx | 10 +- home/ags/files/package.json | 5 + home/ags/files/tsconfig.json | 16 +- 7 files changed, 161 insertions(+), 151 deletions(-) create mode 100644 home/ags/files/package.json diff --git a/home/ags/files/Bar.tsx b/home/ags/files/Bar.tsx index bbdd9b0d..697a06cd 100644 --- a/home/ags/files/Bar.tsx +++ b/home/ags/files/Bar.tsx @@ -1,7 +1,9 @@ -import { App, Astal, Gdk, Gtk, Widget } from "astal/gtk3"; -import { GLib, Variable, bind } from "astal"; +import { Astal, Gdk } from "ags/gtk4"; +import app from "ags/gtk4/app" +import Gtk from "gi://Gtk?version=4.0" +import { createBinding, createState } from "ags" import Tray from "gi://AstalTray"; -import { execAsync } from "astal/process" +import { execAsync } from "ags/process" import Hyprland from "gi://AstalHyprland"; import { getIconName } from "./utils"; import Wp from "gi://AstalWp" @@ -15,17 +17,17 @@ function SysTray(): JSX.Element { const tray = Tray.get_default(); return ( - {bind(tray, "items").as((items) => + {createBinding(tray, "items").as((items) => items.map((item) => { - if (item.iconThemePath) App.add_icons(item.iconThemePath); + if (item.iconThemePath) app.add_icons(item.iconThemePath); return ( ["dbusmenu", ag])} - menuModel={bind(item, "menuModel")}> - + actionGroup={createBinding(item, "actionGroup").as(ag => ["dbusmenu", ag])} + menuModel={createBinding(item, "menuModel")}> + {/* */} ); }), @@ -34,7 +36,7 @@ function SysTray(): JSX.Element { ); } -function Left() : JSX.Element { +function Left(): JSX.Element { return ( @@ -42,7 +44,7 @@ function Left() : JSX.Element { ); } -function Center() : JSX.Element { +function Center(): JSX.Element { return ( @@ -51,10 +53,10 @@ function Center() : JSX.Element { } function Date({ format = "%Y-%m-%d" }): JSX.Element { - const time = Variable("").poll(60000, () => + const time = createState("").poll(60000, () => GLib.DateTime.new_now_local().format(format)!) return -} +// function BatteryIcon(): JSX.Element { +// if (battery.get_state() == 0) return ; +// return +// } function Icons() { return ( - + - + {/* */} ) } @@ -173,30 +175,30 @@ 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 icon = createBinding(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;" + const css = createBinding(audio.default_speaker, "mute").as((mute) => { + return mute ? "margin-left:0;" : "margin-left: 0.7em;" }); return ( - - )))} + .filter(ws => ws && ws.get_monitor() && ws.get_monitor().get_id() === fm.get_id()) + .map((ws) => ( + + )))} )} @@ -235,31 +237,31 @@ function shorten(title: string) { return title.length > 40 ? title.slice(0, 20) + "..." : title } -function Clients() : JSX.Element { +function Clients(): JSX.Element { const hyprland = Hyprland.get_default(); return ( { - bind(hyprland, "focusedWorkspace").as(fw => ( - + createBinding(hyprland, "focusedWorkspace").as(fw => ( + { - bind(hyprland, "clients").as(cls => + createBinding(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")} - > - - - ) - ) + .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")} + > + {/* */} + + ) + ) ) } @@ -271,23 +273,23 @@ function Clients() : JSX.Element { ); } -export default function Bar(gdkmonitor: Gdk.Monitor, scaleFactor: number = 1): Widget.Window { - return new Widget.Window({ +export default function Bar(gdkmonitor: Gdk.Monitor, scaleFactor: number = 1): Gtk.Window { + return new Gtk.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", + application: app, + class: "Bar", name: "top-bar", - setup: self => self.connect("destroy", () => { + s: self => self.connect("destroy", () => { print("Detroying bar"); - App.remove_window(self); + app.remove_window(self); }), - child: - -
- - + child: + +
+ + }) } diff --git a/home/ags/files/app.ts b/home/ags/files/app.ts index 1d896d2a..35e2ab1f 100644 --- a/home/ags/files/app.ts +++ b/home/ags/files/app.ts @@ -1,8 +1,10 @@ -import { App, Gdk, Widget } from "astal/gtk3" +import app from "ags/gtk4/app" import style from "./style.scss" import Bar from "./Bar" import Hyprland from "gi://AstalHyprland"; import NotificationPopups from "./notifications/NotificationPopups" +import Gtk from "gi://Gtk?version=4.0"; +import { Gdk } from "ags/gtk4"; const hyprland = Hyprland.get_default(); @@ -22,21 +24,26 @@ function find_main_monitor(): Hyprland.Monitor { } function register_windows(monitor: Hyprland.Monitor) { - let gtkMonitor = App.get_monitors()[0].get_display().get_monitor_at_point(monitor.get_x(), monitor.get_y()) - let scale = (monitor.get_width() >= 3000)? 1.2: 1 + let gtkMonitors = app.get_monitors()[0].get_display().get_monitors() + let gtkMonitor = gtkMonitors.get_item(0) + if (!gtkMonitor) { + console.error("No GTK monitor found for the Hyprland monitor:", monitor.get_name()); + return; + } + let scale = (monitor.get_width() >= 3000) ? 1.2 : 1 Bar(gtkMonitor, scale) NotificationPopups(gtkMonitor) } function switch_to_best_monitor() { let mainMonitor = find_main_monitor() - for (var wd of App.get_windows()) { + for (var wd of app.get_windows()) { wd.destroy(); } register_windows(mainMonitor); } -hyprland.connect("monitor-added", (_, monitor) => { +hyprland.connect("monitor-added", (_, _monitor: Hyprland.Monitor) => { switch_to_best_monitor() }) @@ -44,7 +51,7 @@ hyprland.connect("monitor-removed", () => { switch_to_best_monitor() }) -App.start({ +app.start({ css: style, iconTheme: "Papirus", main() { diff --git a/home/ags/files/env.d.ts b/home/ags/files/env.d.ts index 467c0a41..792ebfda 100644 --- a/home/ags/files/env.d.ts +++ b/home/ags/files/env.d.ts @@ -1,21 +1,21 @@ declare const SRC: string declare module "inline:*" { - const content: string - export default content + const content: string + export default content } declare module "*.scss" { - const content: string - export default content + const content: string + export default content } declare module "*.blp" { - const content: string - export default content + const content: string + export default content } declare module "*.css" { - const content: string - export default content + const content: string + export default content } diff --git a/home/ags/files/notifications/Notification.tsx b/home/ags/files/notifications/Notification.tsx index 5149d5b7..2fbf9d77 100644 --- a/home/ags/files/notifications/Notification.tsx +++ b/home/ags/files/notifications/Notification.tsx @@ -1,7 +1,7 @@ -import { GLib } from "astal" -import { Gtk, Astal } from "astal/gtk3" -import { type EventBox } from "astal/gtk3/widget" +import { Gtk, Astal } from "ags/gtk4" +import { EventBox } from "ags" import Notifd from "gi://AstalNotifd" +import GLib from "gi://GLib" const isIcon = (icon: string) => !!Astal.Icon.lookup_icon(icon) @@ -35,24 +35,24 @@ export default function Notification(props: Props) { const { START, CENTER, END } = Gtk.Align return - + {(n.appIcon || n.desktopEntry) && } - + {n.image && fileExists(n.image) && } {n.image && isIcon(n.image) && + class="icon-image"> } - {n.get_actions().length > 0 && + {n.get_actions().length > 0 && {n.get_actions().map(({ label, id }) => (