Mercurial > gbwm
comparison gbwm.c @ 12:1f03f3ca1a96
remember last focused window per workspace
author | Atarwn Gard <a@qwa.su> |
---|---|
date | Tue, 14 Oct 2025 18:09:23 +0500 |
parents | 90d8c905af50 |
children | 7d783901ff7d |
comparison
equal
deleted
inserted
replaced
11:90d8c905af50 | 12:1f03f3ca1a96 |
---|---|
41 } Key; | 41 } Key; |
42 | 42 |
43 static Display *dpy; | 43 static Display *dpy; |
44 static Window root; | 44 static Window root; |
45 static Client *workspaces[9] = {NULL}; // 9 workspaces | 45 static Client *workspaces[9] = {NULL}; // 9 workspaces |
46 static Client *last_focused[9] = {NULL}; | |
46 static int current_ws = 0; | 47 static int current_ws = 0; |
47 static Client *focused = NULL; | 48 static Client *focused = NULL; |
48 static int sw, sh; | 49 static int sw, sh; |
49 static int overlay_mode = 0; | 50 static int overlay_mode = 0; |
50 static char overlay_input[3] = {0}; | 51 static char overlay_input[3] = {0}; |
241 if (!c) return; | 242 if (!c) return; |
242 | 243 |
243 Client *old = focused; | 244 Client *old = focused; |
244 focused = c; | 245 focused = c; |
245 | 246 |
246 if (old && old != c) | 247 if (old && old != c) { |
247 updateborder(old); | 248 updateborder(old); |
249 last_focused[old->workspace] = old; | |
250 } | |
248 | 251 |
249 updateborder(c); | 252 updateborder(c); |
250 XRaiseWindow(dpy, c->win); | 253 XRaiseWindow(dpy, c->win); |
251 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); | 254 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); |
252 sendevent(c, wm_take_focus); | 255 sendevent(c, wm_take_focus); |
521 // Workspace functions | 524 // Workspace functions |
522 static void switchws(const Arg *arg) { | 525 static void switchws(const Arg *arg) { |
523 int ws = arg->i; | 526 int ws = arg->i; |
524 if (ws < 0 || ws >= 9 || ws == current_ws) return; | 527 if (ws < 0 || ws >= 9 || ws == current_ws) return; |
525 | 528 |
529 if (focused) { | |
530 last_focused[current_ws] = focused; | |
531 } | |
532 | |
533 | |
526 current_ws = ws; | 534 current_ws = ws; |
527 | 535 |
528 // Hide all windows from all workspaces | 536 // Hide all windows from all workspaces |
529 for (int i = 0; i < 9; i++) { | 537 for (int i = 0; i < 9; i++) { |
530 for (Client *c = workspaces[i]; c; c = c->next) { | 538 for (Client *c = workspaces[i]; c; c = c->next) { |
535 // Show current workspace windows | 543 // Show current workspace windows |
536 for (Client *c = workspaces[current_ws]; c; c = c->next) { | 544 for (Client *c = workspaces[current_ws]; c; c = c->next) { |
537 XMapWindow(dpy, c->win); | 545 XMapWindow(dpy, c->win); |
538 } | 546 } |
539 | 547 |
540 focused = workspaces[current_ws]; | 548 // Restore the last focus on this WS, otherwise the first one |
541 if (focused) focus(focused, 1); | 549 focused = last_focused[current_ws]; |
550 if (!focused) focused = workspaces[current_ws]; | |
551 | |
552 if (focused) { | |
553 focus(focused, 1); | |
554 } else { | |
555 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); | |
556 } | |
557 | |
542 arrange(); | 558 arrange(); |
543 } | 559 } |
544 | 560 |
545 static void movewin_to_ws(const Arg *arg) { | 561 static void movewin_to_ws(const Arg *arg) { |
546 int ws = arg->i; | 562 int ws = arg->i; |