2zw

2zw - X11 Windowmanager

Files | Log | Commits | Refs | README


96b0ef8

Author: erikbackman

Date: 2024-02-20

Subject: focus the globally previous node instead of relative to cursor

Diff

commit 96b0ef80d2813355f473672870e469fae04a185f
Author: erikbackman <erikbackman@users.noreply.github.com>
Date:   Tue Feb 20 22:35:12 2024 +0100

    focus the globally previous node instead of relative to cursor

diff --git a/src/main.zig b/src/main.zig
index cd790cd..9053ead 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -97,6 +97,7 @@ var display: *C.Display = undefined;
 var root: C.Window = undefined;
 var mouse: C.XButtonEvent = undefined;
 var window_changes: C.XWindowChanges = undefined;
+var previously_focused: ?*L.Node = undefined;
 
 // Clients are kept in a doubly-linked list
 const L = std.DoublyLinkedList(Client);
@@ -147,7 +148,10 @@ fn center(c: *L.Node) void {
 
 fn focus(node: *L.Node) void {
     if (list.len == 0) return;
-    if (cursor) |prev| _ = C.XSetWindowBorder(display, prev.data.w, NORMAL_BORDER_COLOR);
+    if (cursor) |c| {
+        _ = C.XSetWindowBorder(display, c.data.w, NORMAL_BORDER_COLOR);
+        previously_focused = c;
+    }
 
     _ = C.XSetInputFocus(
         display,
@@ -185,7 +189,7 @@ fn unmanage(allocator: std.mem.Allocator, node: *L.Node, destroyed: bool) void {
     list.remove(node);
     allocator.destroy(node);
 
-    if (cursor) |c| focus(c) else {
+    if (previously_focused) |c| focus(c) else {
         _ = C.XSetInputFocus(
             display,
             root,