From 6462a708450784c24fc131c7ff337f353e45bd86 Mon Sep 17 00:00:00 2001 From: kitty-panics Date: Fri, 7 Apr 2023 01:00:39 -0400 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=90=88=E5=B9=B6=20#20=20(=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E6=A1=8C=E9=9D=A2=E6=97=B6=E8=AE=B0=E4=BD=8F=E7=84=A6?= =?UTF-8?q?=E7=82=B9=E7=AA=97=E5=8F=A3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Title: remember focused window when switching desktops Links: https://github.com/henkman/virgo/pull/20 ```Describe-Text i was a bit annoyed that switching desktops would sometimes keep the hidden window focused and make me accidentally type into it so I made this simple edit that remembers the focused window for each desktop the focus restore should silently fail and not cause issues if the window is somehow closed while it's hidden ``` --- virgo.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/virgo.c b/virgo.c index 474fffb..2680abb 100644 --- a/virgo.c +++ b/virgo.c @@ -41,6 +41,7 @@ typedef struct { Windows desktops[NUM_DESKTOPS]; Trayicon trayicon; HWND pinned[NUM_PINNED]; + HWND focused[NUM_DESKTOPS]; } Virgo; static void *stb__sbgrowf(void *arr, unsigned increment, unsigned itemsize) @@ -339,8 +340,10 @@ static void virgo_go_to_desk(Virgo *v, unsigned desk) return; } virgo_update(v); + v->focused[v->current] = GetForegroundWindow(); windows_hide(&v->desktops[v->current]); windows_show(&v->desktops[desk]); + SetForegroundWindow(v->focused[desk]); v->current = desk; trayicon_set(&v->trayicon, v->current + 1); }