fixed attachBottom dropping clients after the anchor, removed dead ChangeAttachMethod action, stored attach method as enum and applied it to all attach sites
Browse files
+1 −1 resources/test-config.lua
| @@ -40,7 +40,7 @@ oxwm.bar.set_hide_vacant_tags(false); | |||
| 40 | oxwm.set_layout_symbol("tiling", "[T]") | 40 | oxwm.set_layout_symbol("tiling", "[T]") |
| 41 | oxwm.set_layout_symbol("normie", "[F]") | 41 | oxwm.set_layout_symbol("normie", "[F]") |
| 42 | 42 | ||
| 43 | -oxwm.set_attach_method("above") | 43 | +oxwm.set_attach_method("top") |
| 44 | 44 | ||
| 45 | oxwm.border.set_width(2) | 45 | oxwm.border.set_width(2) |
| 46 | oxwm.border.set_focused_color(colors.blue) | 46 | oxwm.border.set_focused_color(colors.blue) |
+38 −46 src/client.zig
| @@ -1,6 +1,7 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const xlib = @import("x11/xlib.zig"); | 2 | const xlib = @import("x11/xlib.zig"); |
| 3 | const Monitor = @import("monitor.zig").Monitor; | 3 | const Monitor = @import("monitor.zig").Monitor; |
| 4 | +const AttachMethods = @import("config/config.zig").AttachMethods; | ||
| 4 | 5 | ||
| 5 | pub const Client = struct { | 6 | pub const Client = struct { |
| 6 | name: [256]u8 = std.mem.zeroes([256]u8), | 7 | name: [256]u8 = std.mem.zeroes([256]u8), |
| @@ -151,21 +152,23 @@ pub fn nextTagged(client: *Client) ?*Client { | |||
| 151 | pub fn lastTagged(client: *Client) ?*Client { | 152 | pub fn lastTagged(client: *Client) ?*Client { |
| 152 | const monitor = client.monitor orelse return null; | 153 | const monitor = client.monitor orelse return null; |
| 153 | var walked = monitor.clients; | 154 | var walked = monitor.clients; |
| 154 | - var last_tiled: u32 = 0; | 155 | + var last: ?*Client = null; |
| 155 | - var i: u32 = 0; | ||
| 156 | while (walked) |iter| { | 156 | while (walked) |iter| { |
| 157 | - if (!iter.is_floating and isVisibleOnTag(iter, client.tags)) | 157 | + if (!iter.is_floating and isVisibleOnTag(iter, client.tags)) last = iter; |
| 158 | - last_tiled = i; | ||
| 159 | walked = iter.next; | 158 | walked = iter.next; |
| 160 | - i += 1; | ||
| 161 | } | 159 | } |
| 162 | - walked = monitor.clients; | 160 | + return last; |
| 163 | - i = 0; | 161 | +} |
| 164 | - while (i < last_tiled) { | 162 | + |
| 165 | - walked = walked.?.next; | 163 | +/// Inserts `client` into its monitor's client list using `method`. |
| 166 | - i += 1; | 164 | +pub fn attachWith(client: *Client, method: AttachMethods) void { |
| 165 | + switch (method) { | ||
| 166 | + .aside => attachAside(client), | ||
| 167 | + .top => attach(client), | ||
| 168 | + .bottom => attachBottom(client), | ||
| 169 | + .above => attachAbove(client), | ||
| 170 | + .below => attachBelow(client), | ||
| 167 | } | 171 | } |
| 168 | - return walked; | ||
| 169 | } | 172 | } |
| 170 | 173 | ||
| 171 | /// Inserts `client` just after the first client that shares its tags, | 174 | /// Inserts `client` just after the first client that shares its tags, |
| @@ -180,43 +183,45 @@ pub fn attachAside(client: *Client) void { | |||
| 180 | at.?.next = client; | 183 | at.?.next = client; |
| 181 | } | 184 | } |
| 182 | 185 | ||
| 183 | -/// Inserts `client` at the top of the client stack. | 186 | +/// Inserts `client` just after the last client that shares its tags, |
| 184 | -pub fn attachTop(client: *Client) void { | 187 | +/// falling back to prepend if none exists. |
| 185 | - client.next = client.monitor.?.clients; | ||
| 186 | - client.monitor.?.clients = client; | ||
| 187 | -} | ||
| 188 | - | ||
| 189 | -/// Inserts `client` at the bottom of the client stack. | ||
| 190 | pub fn attachBottom(client: *Client) void { | 188 | pub fn attachBottom(client: *Client) void { |
| 191 | - const last = lastTagged(client); | 189 | + const last = lastTagged(client) orelse { |
| 192 | - if (last == null) { | ||
| 193 | attach(client); | 190 | attach(client); |
| 194 | return; | 191 | return; |
| 195 | - } | 192 | + }; |
| 196 | - client.next = null; | 193 | + client.next = last.next; |
| 197 | - last.?.next = client; | 194 | + last.next = client; |
| 198 | } | 195 | } |
| 199 | 196 | ||
| 200 | -/// Inserts `client` above the selected client, | 197 | +/// Inserts `client` just before the selected client, falling back to |
| 201 | -/// falling back to prepend if none exists. | 198 | +/// prepend if there is no selection or the selection is floating. |
| 202 | pub fn attachAbove(client: *Client) void { | 199 | pub fn attachAbove(client: *Client) void { |
| 203 | const monitor = client.monitor orelse return; | 200 | const monitor = client.monitor orelse return; |
| 204 | - if (monitor.sel == null) { | 201 | + const sel = monitor.sel orelse { |
| 202 | + attach(client); | ||
| 203 | + return; | ||
| 204 | + }; | ||
| 205 | + if (sel == client or sel.is_floating) { | ||
| 205 | attach(client); | 206 | attach(client); |
| 206 | return; | 207 | return; |
| 207 | } | 208 | } |
| 208 | - insertBefore(client, monitor.sel orelse return); | 209 | + insertBefore(client, sel); |
| 209 | } | 210 | } |
| 210 | 211 | ||
| 211 | -/// Inserts `client` below the selected client, | 212 | +/// Inserts `client` just after the selected client, falling back to |
| 212 | -/// falling back to prepend if none exists. | 213 | +/// prepend if there is no selection or the selection is floating. |
| 213 | pub fn attachBelow(client: *Client) void { | 214 | pub fn attachBelow(client: *Client) void { |
| 214 | const monitor = client.monitor orelse return; | 215 | const monitor = client.monitor orelse return; |
| 215 | - if (monitor.sel == null) { | 216 | + const sel = monitor.sel orelse { |
| 217 | + attach(client); | ||
| 218 | + return; | ||
| 219 | + }; | ||
| 220 | + if (sel == client or sel.is_floating) { | ||
| 216 | attach(client); | 221 | attach(client); |
| 217 | return; | 222 | return; |
| 218 | } | 223 | } |
| 219 | - insertAfter(client, monitor.sel orelse return); | 224 | + insertAfter(client, sel); |
| 220 | } | 225 | } |
| 221 | 226 | ||
| 222 | /// Counts non-floating, visible clients on `monitor`. | 227 | /// Counts non-floating, visible clients on `monitor`. |
| @@ -285,21 +290,8 @@ pub fn insertAfter(client: *Client, target: *Client) void { | |||
| 285 | 290 | ||
| 286 | detach(client); | 291 | detach(client); |
| 287 | 292 | ||
| 288 | - if (monitor.clients == target) { | 293 | + client.next = target.next; |
| 289 | - client.next = target.next; | 294 | + target.next = client; |
| 290 | - monitor.clients.?.next = client; | ||
| 291 | - return; | ||
| 292 | - } | ||
| 293 | - | ||
| 294 | - var current = monitor.clients; | ||
| 295 | - while (current) |iter| { | ||
| 296 | - if (iter.next == target) { | ||
| 297 | - client.next = target.next; | ||
| 298 | - iter.next.?.next = client; | ||
| 299 | - return; | ||
| 300 | - } | ||
| 301 | - current = iter.next; | ||
| 302 | - } | ||
| 303 | } | 295 | } |
| 304 | 296 | ||
| 305 | /// Swaps the positions of `client_a` and `client_b` in their shared monitor's | 297 | /// Swaps the positions of `client_a` and `client_b` in their shared monitor's |
+3 −10 src/config/config.zig
| @@ -23,7 +23,6 @@ pub const Action = enum { | |||
| 23 | set_layout, | 23 | set_layout, |
| 24 | set_layout_tiling, | 24 | set_layout_tiling, |
| 25 | set_layout_floating, | 25 | set_layout_floating, |
| 26 | - set_attach_method, | ||
| 27 | view_tag, | 26 | view_tag, |
| 28 | view_next_tag, | 27 | view_next_tag, |
| 29 | view_prev_tag, | 28 | view_prev_tag, |
| @@ -103,7 +102,7 @@ pub const Layouts = enum(u32) { | |||
| 103 | } | 102 | } |
| 104 | }; | 103 | }; |
| 105 | 104 | ||
| 106 | -pub const AttachMethods = enum(u32) { | 105 | +pub const AttachMethods = enum { |
| 107 | aside, | 106 | aside, |
| 108 | top, | 107 | top, |
| 109 | bottom, | 108 | bottom, |
| @@ -111,13 +110,7 @@ pub const AttachMethods = enum(u32) { | |||
| 111 | below, | 110 | below, |
| 112 | 111 | ||
| 113 | pub fn fromString(name: []const u8) ?AttachMethods { | 112 | pub fn fromString(name: []const u8) ?AttachMethods { |
| 114 | - if (std.meta.stringToEnum(AttachMethods, name)) |v| return v; | 113 | + return std.meta.stringToEnum(AttachMethods, name); |
| 115 | - if (std.mem.eql(u8, name, "aside")) return .aside; | ||
| 116 | - if (std.mem.eql(u8, name, "top")) return .top; | ||
| 117 | - if (std.mem.eql(u8, name, "bottom")) return .bottom; | ||
| 118 | - if (std.mem.eql(u8, name, "above")) return .above; | ||
| 119 | - if (std.mem.eql(u8, name, "below")) return .below; | ||
| 120 | - return null; | ||
| 121 | } | 114 | } |
| 122 | }; | 115 | }; |
| 123 | 116 | ||
| @@ -206,7 +199,7 @@ pub const Config = struct { | |||
| 206 | tags: [12][]const u8 = .{ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }, | 199 | tags: [12][]const u8 = .{ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }, |
| 207 | tag_count: u32 = 9, | 200 | tag_count: u32 = 9, |
| 208 | layout: []const u8 = "tiling", | 201 | layout: []const u8 = "tiling", |
| 209 | - attach_method: []const u8 = "aside", | 202 | + attach_method: AttachMethods = .aside, |
| 210 | tag_layouts: [12]?[]const u8 = .{null} ** 12, | 203 | tag_layouts: [12]?[]const u8 = .{null} ** 12, |
| 211 | 204 | ||
| 212 | border_width: i32 = 2, | 205 | border_width: i32 = 2, |
+2 −12 src/config/lua.zig
| @@ -639,12 +639,6 @@ fn luaLayoutScrollRight(state: ?*c.lua_State) callconv(.c) c_int { | |||
| 639 | return 1; | 639 | return 1; |
| 640 | } | 640 | } |
| 641 | 641 | ||
| 642 | -fn luaAttachMethodSet(state: ?*c.lua_State) callconv(.c) c_int { | ||
| 643 | - const s = state orelse return 0; | ||
| 644 | - createActionTableWithString(s, "ChangeAttachMethod"); | ||
| 645 | - return 1; | ||
| 646 | -} | ||
| 647 | - | ||
| 648 | fn luaTagView(state: ?*c.lua_State) callconv(.c) c_int { | 642 | fn luaTagView(state: ?*c.lua_State) callconv(.c) c_int { |
| 649 | const s = state orelse return 0; | 643 | const s = state orelse return 0; |
| 650 | const idx: i32 = @intCast(c.lua_tointegerx(s, 1, null)); | 644 | const idx: i32 = @intCast(c.lua_tointegerx(s, 1, null)); |
| @@ -1108,13 +1102,10 @@ fn luaSetAttachMethod(state: ?*c.lua_State) callconv(.c) c_int { | |||
| 1108 | const cfg = config orelse return 0; | 1102 | const cfg = config orelse return 0; |
| 1109 | const s = state orelse return 0; | 1103 | const s = state orelse return 0; |
| 1110 | const name = getStringArg(s, 1) orelse return 0; | 1104 | const name = getStringArg(s, 1) orelse return 0; |
| 1111 | - if (config_mod.AttachMethods.fromString(name) == null) { | 1105 | + cfg.attach_method = config_mod.AttachMethods.fromString(name) orelse { |
| 1112 | std.debug.print("set_attach_method: unknown attach method '{s}'\n", .{name}); | 1106 | std.debug.print("set_attach_method: unknown attach method '{s}'\n", .{name}); |
| 1113 | return 0; | 1107 | return 0; |
| 1114 | - } | 1108 | + }; |
| 1115 | - if (dupeLuaString(s, 1)) |attach_method| { | ||
| 1116 | - cfg.attach_method = attach_method; | ||
| 1117 | - } | ||
| 1118 | return 0; | 1109 | return 0; |
| 1119 | } | 1110 | } |
| 1120 | 1111 | ||
| @@ -1418,7 +1409,6 @@ fn parseAction(name: []const u8) ?Action { | |||
| 1418 | .{ "ToggleBar", Action.toggle_bar }, | 1409 | .{ "ToggleBar", Action.toggle_bar }, |
| 1419 | .{ "CycleLayout", Action.cycle_layout }, | 1410 | .{ "CycleLayout", Action.cycle_layout }, |
| 1420 | .{ "ChangeLayout", Action.set_layout }, | 1411 | .{ "ChangeLayout", Action.set_layout }, |
| 1421 | - .{ "ChangeAttachMethod", Action.set_attach_method }, | ||
| 1422 | .{ "ViewTag", Action.view_tag }, | 1412 | .{ "ViewTag", Action.view_tag }, |
| 1423 | .{ "ViewNextTag", Action.view_next_tag }, | 1413 | .{ "ViewNextTag", Action.view_next_tag }, |
| 1424 | .{ "ViewPreviousTag", Action.view_prev_tag }, | 1414 | .{ "ViewPreviousTag", Action.view_prev_tag }, |
+2 −14 src/wm/actions.zig
| @@ -440,17 +440,6 @@ pub fn setLayoutIndex(index: u32, wm: *WindowManager) void { | |||
| 440 | } | 440 | } |
| 441 | } | 441 | } |
| 442 | 442 | ||
| 443 | -pub fn setAttachMethod(attach_method_name: ?[]const u8, wm: *WindowManager) void { | ||
| 444 | - const name = attach_method_name orelse return; | ||
| 445 | - const new_att_m: u32 = if (config_mod.AttachMethods.fromString(name)) |value| | ||
| 446 | - @intFromEnum(value) | ||
| 447 | - else { | ||
| 448 | - std.debug.print("set_attach_method: unknown attach method '{s}'\n", .{name}); | ||
| 449 | - return; | ||
| 450 | - }; | ||
| 451 | - wm.attach_method = new_att_m; | ||
| 452 | -} | ||
| 453 | - | ||
| 454 | fn warpCursorToMonitor(monitor: *Monitor, wm: *WindowManager) void { | 443 | fn warpCursorToMonitor(monitor: *Monitor, wm: *WindowManager) void { |
| 455 | const center_x = monitor.win_x + @divTrunc(monitor.win_w, 2); | 444 | const center_x = monitor.win_x + @divTrunc(monitor.win_w, 2); |
| 456 | const center_y = monitor.win_y + @divTrunc(monitor.win_h, 2); | 445 | const center_y = monitor.win_y + @divTrunc(monitor.win_h, 2); |
| @@ -485,7 +474,7 @@ pub fn sendmon(direction: i32, wm: *WindowManager) void { | |||
| 485 | client_mod.detachStack(client); | 474 | client_mod.detachStack(client); |
| 486 | client.monitor = target; | 475 | client.monitor = target; |
| 487 | client.tags = target.tagset[target.sel_tags]; | 476 | client.tags = target.tagset[target.sel_tags]; |
| 488 | - client_mod.attachAside(client); | 477 | + client_mod.attachWith(client, wm.config.attach_method); |
| 489 | client_mod.attachStack(client); | 478 | client_mod.attachStack(client); |
| 490 | 479 | ||
| 491 | core.focusTopClient(source_monitor, wm); | 480 | core.focusTopClient(source_monitor, wm); |
| @@ -602,7 +591,7 @@ pub fn movemouse(wm: *WindowManager) void { | |||
| 602 | client_mod.detachStack(client); | 591 | client_mod.detachStack(client); |
| 603 | client.monitor = new_mon; | 592 | client.monitor = new_mon; |
| 604 | client.tags = new_mon.?.tagset[new_mon.?.sel_tags]; | 593 | client.tags = new_mon.?.tagset[new_mon.?.sel_tags]; |
| 605 | - client_mod.attachAside(client); | 594 | + client_mod.attachWith(client, wm.config.attach_method); |
| 606 | client_mod.attachStack(client); | 595 | client_mod.attachStack(client); |
| 607 | wm.selected_monitor = new_mon; | 596 | wm.selected_monitor = new_mon; |
| 608 | core.focus(client, wm); | 597 | core.focus(client, wm); |
| @@ -843,7 +832,6 @@ pub fn executeAction(action: config_mod.Action, int_arg: i32, str_arg: ?[]const | |||
| 843 | .set_layout => setLayout(str_arg, wm), | 832 | .set_layout => setLayout(str_arg, wm), |
| 844 | .set_layout_tiling => setLayoutIndex(0, wm), | 833 | .set_layout_tiling => setLayoutIndex(0, wm), |
| 845 | .set_layout_floating => setLayoutIndex(2, wm), | 834 | .set_layout_floating => setLayoutIndex(2, wm), |
| 846 | - .set_attach_method => setAttachMethod(str_arg, wm), | ||
| 847 | .view_tag => { | 835 | .view_tag => { |
| 848 | const tag_mask: u32 = @as(u32, 1) << @intCast(int_arg); | 836 | const tag_mask: u32 = @as(u32, 1) << @intCast(int_arg); |
| 849 | core.view(tag_mask, wm); | 837 | core.view(tag_mask, wm); |
+1 −14 src/wm/core.zig
| @@ -90,7 +90,7 @@ pub fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *Wind | |||
| 90 | _ = xlib.XRaiseWindow(wm.display.handle, client.window); | 90 | _ = xlib.XRaiseWindow(wm.display.handle, client.window); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | - attach(client, wm.attach_method); | 93 | + client_mod.attachWith(client, wm.config.attach_method); |
| 94 | client_mod.attachStack(client); | 94 | client_mod.attachStack(client); |
| 95 | 95 | ||
| 96 | _ = xlib.XChangeProperty(wm.display.handle, wm.display.root, wm.atoms.net_client_list, xlib.XA_WINDOW, 32, xlib.PropModeAppend, @ptrCast(&client.window), 1); | 96 | _ = xlib.XChangeProperty(wm.display.handle, wm.display.root, wm.atoms.net_client_list, xlib.XA_WINDOW, 32, xlib.PropModeAppend, @ptrCast(&client.window), 1); |
| @@ -267,19 +267,6 @@ pub fn arrange(monitor: *Monitor, wm: *WindowManager) void { | |||
| 267 | restack(monitor, wm); | 267 | restack(monitor, wm); |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | -pub fn attach(client: *Client, att_m: u32) void { | ||
| 271 | - switch (att_m) { | ||
| 272 | - @intFromEnum(config_mod.AttachMethods.aside) => client_mod.attachAside(client), | ||
| 273 | - @intFromEnum(config_mod.AttachMethods.top) => client_mod.attachTop(client), | ||
| 274 | - @intFromEnum(config_mod.AttachMethods.bottom) => client_mod.attachBottom(client), | ||
| 275 | - @intFromEnum(config_mod.AttachMethods.above) => client_mod.attachAbove(client), | ||
| 276 | - @intFromEnum(config_mod.AttachMethods.below) => client_mod.attachBelow(client), | ||
| 277 | - else => { | ||
| 278 | - std.debug.print("No attach method found! Value: {}\n", .{att_m}); | ||
| 279 | - }, | ||
| 280 | - } | ||
| 281 | -} | ||
| 282 | - | ||
| 283 | pub fn showhide(monitor: *Monitor, wm: *WindowManager) void { | 270 | pub fn showhide(monitor: *Monitor, wm: *WindowManager) void { |
| 284 | showhideClient(monitor.stack, wm); | 271 | showhideClient(monitor.stack, wm); |
| 285 | } | 272 | } |
+1 −6 src/wm/wm.zig
| @@ -77,8 +77,6 @@ pub const WindowManager = struct { | |||
| 77 | /// The monitor that currently has input focus. | 77 | /// The monitor that currently has input focus. |
| 78 | selected_monitor: ?*Monitor, | 78 | selected_monitor: ?*Monitor, |
| 79 | 79 | ||
| 80 | - attach_method: u32, | ||
| 81 | - | ||
| 82 | /// Head of the linked list of status bars (one per monitor). | 80 | /// Head of the linked list of status bars (one per monitor). |
| 83 | bars: ?*Bar, | 81 | bars: ?*Bar, |
| 84 | 82 | ||
| @@ -127,7 +125,6 @@ pub const WindowManager = struct { | |||
| 127 | .config_path = config_path, | 125 | .config_path = config_path, |
| 128 | .monitors = null, | 126 | .monitors = null, |
| 129 | .selected_monitor = null, | 127 | .selected_monitor = null, |
| 130 | - .attach_method = @intFromEnum(config_mod.AttachMethods.fromString(config.attach_method) orelse config_mod.AttachMethods.aside), | ||
| 131 | .bars = null, | 128 | .bars = null, |
| 132 | .chord = .{}, | 129 | .chord = .{}, |
| 133 | .overlay = null, | 130 | .overlay = null, |
| @@ -355,7 +352,7 @@ pub const WindowManager = struct { | |||
| 355 | client_mod.detachStack(c); | 352 | client_mod.detachStack(c); |
| 356 | c.monitor = target; | 353 | c.monitor = target; |
| 357 | c.tags = target.tagset[target.sel_tags]; | 354 | c.tags = target.tagset[target.sel_tags]; |
| 358 | - client_mod.attachAside(c); | 355 | + client_mod.attachWith(c, self.config.attach_method); |
| 359 | client_mod.attachStack(c); | 356 | client_mod.attachStack(c); |
| 360 | } | 357 | } |
| 361 | } | 358 | } |
| @@ -721,8 +718,6 @@ pub const WindowManager = struct { | |||
| 721 | 718 | ||
| 722 | loadFn(self); | 719 | loadFn(self); |
| 723 | 720 | ||
| 724 | - self.attach_method = @intFromEnum(config_mod.AttachMethods.fromString(self.config.attach_method) orelse config_mod.AttachMethods.aside); | ||
| 725 | - | ||
| 726 | bar_mod.destroyBars(self.bars, self.display.handle); | 721 | bar_mod.destroyBars(self.bars, self.display.handle); |
| 727 | self.bars = null; | 722 | self.bars = null; |
| 728 | self.setupBars(); | 723 | self.setupBars(); |