2zw

2zw - X11 Windowmanager

Files | Log | Commits | Refs | README


dfac945

Author: erikbackman

Date: 2024-02-08

Subject: return node when adding client and let caller decide what to do after adding

Diff

commit dfac9455c9351edafcd999b10901e2b713deaecf
Author: erikbackman <erikbackman@users.noreply.github.com>
Date:   Thu Feb 8 22:43:52 2024 +0100

    return node when adding client and let caller decide what to do after adding

diff --git a/src/main.zig b/src/main.zig
index 7bb66c7..13c5d97 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -105,7 +105,7 @@ const L = std.DoublyLinkedList(Client);
 var list = L{};
 var cursor: ?*L.Node = null; // having the cursor be nullable is annoying..
 
-fn addClient(allocator: std.mem.Allocator, window: C.Window) !void {
+fn addClient(allocator: std.mem.Allocator, window: C.Window) !*L.Node {
     var attributes: C.XWindowAttributes = undefined;
     _ = C.XGetWindowAttributes(display, window, &attributes);
 
@@ -122,8 +122,8 @@ fn addClient(allocator: std.mem.Allocator, window: C.Window) !void {
 
     node.data = client;
     list.append(node);
-    focus(node);
-    cursor = node;
+
+    return node;
 }
 
 fn center(c: *L.Node) void {
@@ -212,12 +212,8 @@ fn onMapRequest(allocator: std.mem.Allocator, event: *C.XEvent) !void {
     _ = C.XMapWindow(display, window);
     _ = C.XSetWindowBorderWidth(display, window, BORDER_WIDTH);
 
-    try addClient(allocator, window);
-
-    if (cursor) |node| {
-        //center(node);
-        focus(node);
-    }
+    const node = try addClient(allocator, window);
+    focus(node);
 }
 
 fn onUnmapNotify(allocator: std.mem.Allocator, e: *C.XEvent) void {