From dcd914dbae039560a4ad4db4edd0264845f7024b Mon Sep 17 00:00:00 2001
From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
Date: Wed, 15 Jan 2025 15:22:22 +1100
Subject: better popup window

Not manual using css, instead use a combination of css opacity and Hyprland animations
---
 modules/launcher.tsx | 54 ++++++++++++++++++++++++++--------------------------
 1 file changed, 27 insertions(+), 27 deletions(-)

(limited to 'modules/launcher.tsx')

diff --git a/modules/launcher.tsx b/modules/launcher.tsx
index 83245ca..b212b85 100644
--- a/modules/launcher.tsx
+++ b/modules/launcher.tsx
@@ -8,7 +8,7 @@ import { Apps } from "../services/apps";
 import Math, { type HistoryItem } from "../services/math";
 import { getAppCategoryIcon } from "../utils/icons";
 import { launch } from "../utils/system";
-import { PopupWindow, setupCustomTooltip, TransitionType } from "../utils/widgets";
+import { convertPopupWindowProps, setupCustomTooltip } from "../utils/widgets";
 
 type Mode = "apps" | "files" | "math";
 
@@ -323,11 +323,7 @@ const LauncherContent = ({
     showResults: Variable<boolean>;
     entry: Widget.Entry;
 }) => (
-    <box
-        vertical
-        className={bind(mode).as(m => `launcher ${m}`)}
-        css={bind(AstalHyprland.get_default(), "focusedMonitor").as(m => `margin-top: ${m.height / 4}px;`)}
-    >
+    <box vertical className={bind(mode).as(m => `launcher ${m}`)}>
         <box className="search-bar">
             <label className="icon" label="search" />
             <SearchEntry entry={entry} />
@@ -351,7 +347,7 @@ const LauncherContent = ({
 );
 
 @register()
-export default class Launcher extends PopupWindow {
+export default class Launcher extends Widget.Window {
     readonly mode: Variable<Mode>;
 
     constructor() {
@@ -359,29 +355,33 @@ export default class Launcher extends PopupWindow {
         const mode = Variable<Mode>("apps");
         const showResults = Variable.derive([bind(entry, "textLength"), mode], (t, m) => t > 0 || m !== "apps");
 
-        super({
-            name: "launcher",
-            keymode: Astal.Keymode.EXCLUSIVE,
-            onKeyPressEvent(_, event) {
-                const keyval = event.get_keyval()[1];
-                // Focus entry on typing
-                if (!entry.isFocus && keyval >= 32 && keyval <= 126) {
-                    entry.text += String.fromCharCode(keyval);
-                    entry.grab_focus();
-                    entry.set_position(-1);
-
-                    // Consume event, if not consumed it will duplicate character in entry
-                    return true;
-                }
-            },
-            transitionType: TransitionType.SLIDE_DOWN,
-            halign: Gtk.Align.CENTER,
-            valign: Gtk.Align.START,
-            child: <LauncherContent mode={mode} showResults={showResults} entry={entry} />,
-        });
+        super(
+            convertPopupWindowProps({
+                name: "launcher",
+                anchor: Astal.WindowAnchor.TOP,
+                keymode: Astal.Keymode.EXCLUSIVE,
+                onKeyPressEvent(_, event) {
+                    const keyval = event.get_keyval()[1];
+                    // Focus entry on typing
+                    if (!entry.isFocus && keyval >= 32 && keyval <= 126) {
+                        entry.text += String.fromCharCode(keyval);
+                        entry.grab_focus();
+                        entry.set_position(-1);
+
+                        // Consume event, if not consumed it will duplicate character in entry
+                        return true;
+                    }
+                },
+                halign: Gtk.Align.CENTER,
+                valign: Gtk.Align.START,
+                child: <LauncherContent mode={mode} showResults={showResults} entry={entry} />,
+            })
+        );
 
         this.mode = mode;
 
+        this.connect("show", () => (this.marginTop = AstalHyprland.get_default().focusedMonitor.height / 4));
+
         // Clear search on hide if not in math mode
         this.connect("hide", () => mode.get() !== "math" && entry.set_text(""));
     }
-- 
cgit v1.2.3-freya

