Implement zoom keybind

This commit is contained in:
Ben Buhse 2026-01-30 21:09:02 -06:00
commit 4e02a07bf1
No known key found for this signature in database
GPG key ID: 7916ACFCD38FD0B4
3 changed files with 29 additions and 2 deletions

View file

@ -10,6 +10,7 @@ keybinds {
spawn mod4 t foot spawn mod4 t foot
focus_next mod4 j focus_next mod4 j
focus_prev mod4 k focus_prev mod4 k
zoom mod4 z
toggle_fullscreen mod4 f toggle_fullscreen mod4 f
close_window mod4+Shift q close_window mod4+Shift q
// Generates keybinds for keys 1-9 → tags 1<<0 through 1<<9 // Generates keybinds for keys 1-9 → tags 1<<0 through 1<<9

View file

@ -319,6 +319,9 @@ fn loadKeybindsChildBlock(config: *Config, parser: *kdl.Parser) !void {
.focus_prev => { .focus_prev => {
break :sw .focus_prev; break :sw .focus_prev;
}, },
.zoom => {
break :sw .zoom;
},
.toggle_fullscreen => { .toggle_fullscreen => {
break :sw .toggle_fullscreen; break :sw .toggle_fullscreen;
}, },

View file

@ -8,7 +8,7 @@ pub const Command = union(enum) {
spawn: []const []const u8, spawn: []const []const u8,
focus_next, focus_next,
focus_prev, focus_prev,
// zoom, // TODO zoom,
// ratio_up, // TODO // ratio_up, // TODO
// ratio_down, // TODO // ratio_down, // TODO
// reload_config, // TODO // reload_config, // TODO
@ -104,7 +104,29 @@ const XkbBinding = struct {
} else { } else {
seat.pending_manage.pending_focus = .clear_focus; seat.pending_manage.pending_focus = .clear_focus;
} }
// context.wm.window_manager_v1.manageDirty(); },
.zoom => {
const wm = context.wm;
const seat = wm.seats.first() orelse return;
const current_focus = if (seat.pending_manage.pending_focus) |pending_focus| blk: {
switch (pending_focus) {
.clear_focus => return,
.window => |window| break :blk window,
}
} else seat.focused orelse return;
const first_window: *Window = if (wm.windows.first()) |first| blk: {
if (current_focus == first) {
// Try get the second window instead
break :blk @fieldParentPtr("link", first.link.next orelse return);
} else {
seat.pending_manage.should_warp_pointer = true;
break :blk first;
}
} else {
// If current_focus is not null, we know that first_window *must not* be null.
unreachable;
};
current_focus.link.swapWith(&first_window.link);
}, },
.toggle_fullscreen => { .toggle_fullscreen => {
const seat = context.wm.seats.first() orelse return; const seat = context.wm.seats.first() orelse return;
@ -215,5 +237,6 @@ const xkbcommon = @import("xkbcommon");
const utils = @import("utils.zig"); const utils = @import("utils.zig");
const Context = @import("Context.zig"); const Context = @import("Context.zig");
const Seat = @import("Seat.zig"); const Seat = @import("Seat.zig");
const Window = @import("Window.zig");
const log = std.log.scoped(.XkbBindings); const log = std.log.scoped(.XkbBindings);