Skip to content

Commit

Permalink
feat: fork Restore focus when switching desktops.
Browse files Browse the repository at this point in the history
  • Loading branch information
wwxiaoqi committed Aug 18, 2023
1 parent 4e8d9d6 commit 012cd26
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions virgo.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
typedef struct {
HWND *windows;
unsigned count;
HWND focus;
} Windows;

typedef struct {
Expand All @@ -43,6 +44,18 @@ typedef struct {
HWND pinned[NUM_PINNED];
} Virgo;

static void save_current_desktops_focus(Windows* desktops) {
desktops->focus = GetForegroundWindow();
}

static unsigned is_valid_window(HWND hwnd);
static void restore_current_desktops_focus(Windows* desktops) {
if (!desktops->focus || !is_valid_window(desktops->focus)) {
return;
}
SetForegroundWindow(desktops->focus);
}

static void *stb__sbgrowf(void *arr, unsigned increment, unsigned itemsize)
{
unsigned dbl_cur = arr ? 2 * stb__sbm(arr) : 0;
Expand Down Expand Up @@ -339,8 +352,10 @@ static void virgo_go_to_desk(Virgo *v, unsigned desk)
return;
}
virgo_update(v);
save_current_desktops_focus(&v->desktops[v->current]);
windows_hide(&v->desktops[v->current]);
windows_show(&v->desktops[desk]);
restore_current_desktops_focus(&v->desktops[desk]);
v->current = desk;
trayicon_set(&v->trayicon, v->current + 1);
}
Expand Down

0 comments on commit 012cd26

Please sign in to comment.