From 02fd2e97f2c8a53bf2344e6fa8b14769cb15ee38 Mon Sep 17 00:00:00 2001
From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
Date: Thu, 16 Jan 2025 16:35:37 +1100
Subject: refactor: move ts to src

Also move popupwindow to own file
---
 src/modules/notifications.tsx | 57 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 src/modules/notifications.tsx

(limited to 'src/modules/notifications.tsx')

diff --git a/src/modules/notifications.tsx b/src/modules/notifications.tsx
new file mode 100644
index 0000000..66188a1
--- /dev/null
+++ b/src/modules/notifications.tsx
@@ -0,0 +1,57 @@
+import { Gtk } from "astal/gtk3";
+import AstalNotifd from "gi://AstalNotifd";
+import { PopupWindow, setupChildClickthrough } from "../utils/widgets";
+
+const List = () => (
+    <box
+        vertical
+        valign={Gtk.Align.START}
+        className="list"
+        setup={self => {
+            const notifd = AstalNotifd.get_default();
+            const map = new Map<number, NotifPopup>();
+            self.hook(notifd, "notified", (self, id) => {
+                const notification = notifd.get_notification(id);
+
+                const popup = (<NotifPopup notification={notification} />) as NotifPopup;
+                popup.connect("destroy", () => map.get(notification.id) === popup && map.delete(notification.id));
+                map.get(notification.id)?.destroyWithAnims();
+                map.set(notification.id, popup);
+
+                self.add(
+                    <eventbox
+                        // Dismiss on middle click
+                        onClick={(_, event) => event.button === Astal.MouseButton.MIDDLE && notification.dismiss()}
+                        // Close on hover lost
+                        onHoverLost={() => popup.destroyWithAnims()}
+                    >
+                        {popup}
+                    </eventbox>
+                );
+
+                // Limit number of popups
+                if (config.maxPopups > 0 && self.children.length > config.maxPopups)
+                    map.values().next().value?.destroyWithAnims();
+            });
+            self.hook(notifd, "resolved", (_, id) => map.get(id)?.destroyWithAnims());
+
+            // Change input region to child region so can click through empty space
+            setupChildClickthrough(self);
+        }}
+    />
+);
+
+export default class Notifications extends PopupWindow {
+    constructor() {
+        super({
+            name: "notifications",
+            child: (
+                <box>
+                    <List />
+                </box>
+            ),
+        });
+
+        setupChildClickthrough(self);
+    }
+}
-- 
cgit v1.2.3-freya

