From 9030de6b64c943b399cefdd29d47423d9c9fe43b Mon Sep 17 00:00:00 2001 From: Ben Buhse Date: Mon, 26 Jan 2026 17:44:34 -0600 Subject: [PATCH] Get tags working with actual tag-switching support I added 7 new Commands to XkbKeybinds.Commands, though 3 of them don't work yet. The new commands that *work* are + set_output_tags: u32, + set_window_tags: u32, + toggle_output_tags: u32, + toggle_window_tags: u32, They each take a 32-bit value as a bitmask to set (or toggle) tags. The 3 unimplemented commands are + spawn_tagmask: u32, + focus_previous_tags, + send_to_previous_tags, and they will all panic if they're used. For now, default keybinds are hardcoded as part of WindowManager's initializing in the first \`manage_start\` event. Multi-output support is not added yet, so this will still all happen on a single Output. --- README.md | 3 +++ src/Window.zig | 24 +++++++++++++++++++++-- src/WindowManager.zig | 17 ++++++++++++++++- src/XkbBindings.zig | 44 +++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 83 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fbaf1b2..eaba651 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,6 @@ SPDX-License-Identifier: EUPL-1.2 ## TODOs [ ] Support multiple outputs [ ] Support multiple seats +[ ] Support floating windows +[ ] Support wallpapers +[ ] Support a bar diff --git a/src/Window.zig b/src/Window.zig index 8b6138a..b4b4102 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -18,7 +18,11 @@ fullscreen: bool = false, maximized: bool = false, tags: u32 = 0x0001, -output: ?*Output, +// output: ?*Output, + +// XXX: Do I really even need to store `show`? +// I think I only would if I was trying not to send extraneous requests. +show: bool = true, initialized: bool = false, @@ -42,6 +46,7 @@ pub const PendingManage = struct { maximized: ?bool = null, tags: ?u32 = null, + // output: ?*Output = null, }; pub const PendingRender = struct { @@ -49,6 +54,8 @@ pub const PendingRender = struct { y: ?i32 = null, focused: ?bool = null, + + show: ?bool = null, }; pub fn create(context: *Context, river_window_v1: *river.WindowV1, output: *Output) !*Window { @@ -59,11 +66,11 @@ pub fn create(context: *Context, river_window_v1: *river.WindowV1, output: *Outp .context = context, .river_window_v1 = river_window_v1, .river_node_v1 = river_window_v1.getNode() catch @panic("Failed to get node"), + // .output = output, .tags = if (output.tags != 0) output.tags else 0x0001, .link = undefined, // Handled by the wl.list }; - window.river_window_v1.setListener(*Window, windowListener, window); return window; @@ -197,6 +204,19 @@ pub fn render(window: *Window) void { } } } + + // Show or hide the Window + if (window.pending_render.show) |show| { + if (show) { + if (!window.show) { + window.river_window_v1.show(); + } + } else { + if (window.show) { + window.river_window_v1.hide(); + } + } + } } fn applyBorders(window: *Window, color: utils.RiverColor) void { diff --git a/src/WindowManager.zig b/src/WindowManager.zig index 3d178d8..cf4f0ff 100644 --- a/src/WindowManager.zig +++ b/src/WindowManager.zig @@ -104,6 +104,9 @@ fn calculatePrimaryStackLayout(wm: *WindowManager) void { if (output.tags & window.tags != 0x0000) { active_list.append(&window.active_list_node); active_count += 1; + window.pending_render.show = true; + } else { + window.pending_render.show = false; } } @@ -185,9 +188,21 @@ fn manage_start(wm: *WindowManager) void { context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.t, .{ .mod4 = true }, .{ .spawn = &.{"foot"} }); context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.j, .{ .mod4 = true }, .focus_next); context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.k, .{ .mod4 = true }, .focus_prev); - context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.f, .{ .mod4 = true }, .fullscreen); + context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.f, .{ .mod4 = true }, .toggle_fullscreen); context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.q, .{ .mod4 = true, .shift = true }, .close_window); context.xkb_bindings.addBinding(river_seat_v1, xkbcommon.Keysym.e, .{ .mod4 = true, .shift = true }, .exit); + + // Tag bindings + comptime var i: u8 = 1; + comptime var buffer: [1]u8 = undefined; + inline while (i <= 9) : (i += 1) { + const tags: u32 = 1 << (i - 1); + buffer[0] = i + '0'; + context.xkb_bindings.addBinding(river_seat_v1, @field(xkbcommon.Keysym, &buffer), .{ .mod4 = true }, .{ .set_output_tags = tags }); + context.xkb_bindings.addBinding(river_seat_v1, @field(xkbcommon.Keysym, &buffer), .{ .mod4 = true, .shift = true }, .{ .set_window_tags = tags }); + context.xkb_bindings.addBinding(river_seat_v1, @field(xkbcommon.Keysym, &buffer), .{ .mod4 = true, .ctrl = true }, .{ .toggle_output_tags = tags }); + context.xkb_bindings.addBinding(river_seat_v1, @field(xkbcommon.Keysym, &buffer), .{ .mod4 = true, .shift = true, .ctrl = true }, .{ .toggle_window_tags = tags }); + } } { diff --git a/src/XkbBindings.zig b/src/XkbBindings.zig index 88fd4fa..9adaa0b 100644 --- a/src/XkbBindings.zig +++ b/src/XkbBindings.zig @@ -8,9 +8,17 @@ pub const Command = union(enum) { spawn: []const []const u8, focus_next, focus_prev, - fullscreen, + toggle_fullscreen, close_window, exit, + // Tag management + set_output_tags: u32, + set_window_tags: u32, + toggle_output_tags: u32, + toggle_window_tags: u32, + spawn_tagmask: u32, + focus_previous_tags, + send_to_previous_tags, }; const XkbBinding = struct { @@ -94,7 +102,7 @@ const XkbBinding = struct { } // context.wm.window_manager_v1.manageDirty(); }, - .fullscreen => { + .toggle_fullscreen => { const seat = context.wm.seats.first() orelse return; const window = seat.focused orelse return; window.pending_manage.fullscreen = !window.fullscreen; @@ -110,6 +118,38 @@ const XkbBinding = struct { // TODO: Disabled while I'm working with river within river :P // _ = std.process.Child.init(&.{"killall river"}, std.heap.c_allocator); }, + .set_output_tags => |tags| { + // TODO: Support multiple outputs + const output = context.wm.outputs.first() orelse return; + output.pending_manage.tags = tags; + context.wm.river_window_manager_v1.manageDirty(); + }, + .set_window_tags => |tags| { + const seat = context.wm.seats.first() orelse return; + // TODO: I don't think pending_focus should ever be set at this point? + // const window = seat.pending_manage.pending_focus orelse seat.focused; + const window = seat.focused orelse return; + window.pending_manage.tags = tags; + context.wm.river_window_manager_v1.manageDirty(); + }, + .toggle_output_tags => |tags| { + const output = context.wm.outputs.first() orelse return; + const old_tags = output.pending_manage.tags orelse output.tags; + output.pending_manage.tags = old_tags ^ tags; + context.wm.river_window_manager_v1.manageDirty(); + }, + .toggle_window_tags => |tags| { + const seat = context.wm.seats.first() orelse return; + // TODO: I don't think pending_focus should ever be set at this point? + // const window = seat.pending_manage.pending_focus orelse seat.focused; + const window = seat.focused orelse return; + const old_tags = window.pending_manage.tags orelse window.tags; + window.pending_manage.tags = old_tags ^ tags; + context.wm.river_window_manager_v1.manageDirty(); + }, + .spawn_tagmask, .focus_previous_tags, .send_to_previous_tags => { + @panic("Unimplemented"); + }, } } };