From 9c3c59fb33c6f3d325bda7a9ce360c135410b3dd Mon Sep 17 00:00:00 2001
From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
Date: Tue, 21 Jan 2025 23:26:47 +1100
Subject: session: logout grab focus on open

---
 src/modules/session.tsx | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

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

diff --git a/src/modules/session.tsx b/src/modules/session.tsx
index 7d04870..1c58d48 100644
--- a/src/modules/session.tsx
+++ b/src/modules/session.tsx
@@ -1,10 +1,19 @@
 import { execAsync } from "astal";
-import { Astal, Gtk } from "astal/gtk3";
+import { App, Astal, Gtk } from "astal/gtk3";
 import PopupWindow from "../widgets/popupwindow";
 
-const Item = ({ icon, label, cmd }: { icon: string; label: string; cmd: string }) => (
+const Item = ({ icon, label, cmd, isDefault }: { icon: string; label: string; cmd: string; isDefault?: boolean }) => (
     <box vertical className="item">
-        <button cursor="pointer" onClicked={() => execAsync(cmd).catch(console.error)}>
+        <button
+            cursor="pointer"
+            onClicked={() => execAsync(cmd).catch(console.error)}
+            setup={self =>
+                isDefault &&
+                self.hook(App, "window-toggled", (_, window) => {
+                    if (window.name === "session" && window.visible) self.grab_focus();
+                })
+            }
+        >
             <label className="icon" label={icon} />
         </button>
         <label className="label" label={label} />
@@ -22,7 +31,7 @@ export default () => (
     >
         <box vertical halign={Gtk.Align.CENTER} valign={Gtk.Align.CENTER} className="inner">
             <box>
-                <Item icon="logout" label="Logout" cmd="uwsm stop" />
+                <Item icon="logout" label="Logout" cmd="uwsm stop" isDefault />
                 <Item icon="cached" label="Reboot" cmd="systemctl reboot" />
             </box>
             <box>
-- 
cgit v1.2.3-freya

