Add layer shell support and fix floating windows

Now, I actually save the river-layer-shell-v1 and keep track of the
non-exclusive area. The layout calculation uses the usable area instead
of the entire output's geometry.

I removed boundary clamping for the floating windows because it was a
bit janky when hitting the edges. I'll probably add it back at some
point. I also made windows default to 75% of the usable area instead of
keeping their tiled size so that maximized windows look decent when
floating for the first time. Finally, since I removed the clamping, I
added a center_float keybind to center a floating window. If you're
cycling through focused windows and one isn't on the screen, you can use
the center_float bind to get the window visible again.

Replaced all divTrunc with divFloor to be consistent. I think they
should all be positive, anyways, so they'd be the same, but I like just
having one.
This commit is contained in:
Ben Buhse 2026-02-14 11:29:00 -06:00
commit 5c427234d7
No known key found for this signature in database
GPG key ID: 7916ACFCD38FD0B4
9 changed files with 108 additions and 71 deletions

View file

@ -41,6 +41,9 @@ pub const Command = union(enum) {
resize_width: i32,
resize_height: i32,
// Center floating window on its output
center_float,
// Swap window position in stack
swap_next,
swap_prev,
@ -237,6 +240,7 @@ const XkbBinding = struct {
.move_right => |pixels| moveFloatingWindow(context, pixels, 0),
.resize_width => |delta| resizeFloatingWindow(context, delta, 0),
.resize_height => |delta| resizeFloatingWindow(context, 0, delta),
.center_float => centerFloatingWindow(context),
.swap_next => swapWindow(context, .next),
.swap_prev => swapWindow(context, .prev),
}
@ -336,18 +340,9 @@ const XkbBinding = struct {
const seat = context.wm.seats.first() orelse return;
const window = seat.focused_window orelse return;
if (!window.floating) return;
const output = window.output orelse {
log.err("focused floating window has no output during move", .{});
return;
};
const min_x = output.x;
const max_x = output.x + output.width - @as(i32, window.float_width);
const min_y = output.y;
const max_y = output.y + output.height - @as(i32, window.float_height);
window.float_x = std.math.clamp(window.float_x + dx, min_x, @max(min_x, max_x));
window.float_y = std.math.clamp(window.float_y + dy, min_y, @max(min_y, max_y));
window.float_x += dx;
window.float_y += dy;
window.pending_render.x = window.float_x;
window.pending_render.y = window.float_y;
context.wm.river_window_manager_v1.manageDirty();
@ -357,25 +352,27 @@ const XkbBinding = struct {
const seat = context.wm.seats.first() orelse return;
const window = seat.focused_window orelse return;
if (!window.floating) return;
const output = window.output orelse {
log.err("focused floating window has no output during resize", .{});
return;
};
const new_width: i32 = @as(i32, window.float_width) + dw;
const new_height: i32 = @as(i32, window.float_height) + dh;
window.float_width = @intCast(@max(50, new_width));
window.float_height = @intCast(@max(50, new_height));
// Clamp position to keep window on screen after resize
const max_x = output.x + output.width - @as(i32, window.float_width);
const max_y = output.y + output.height - @as(i32, window.float_height);
window.float_x = std.math.clamp(window.float_x, output.x, @max(output.x, max_x));
window.float_y = std.math.clamp(window.float_y, output.y, @max(output.y, max_y));
window.pending_manage.width = window.float_width;
window.pending_manage.height = window.float_height;
context.wm.river_window_manager_v1.manageDirty();
}
fn centerFloatingWindow(context: *Context) void {
const seat = context.wm.seats.first() orelse return;
const window = seat.focused_window orelse return;
if (!window.floating) return;
const output = window.output orelse return;
window.float_x = output.usable_x + @divFloor(output.usable_width, 2) - @divFloor(window.float_width, 2);
window.float_y = output.usable_y + @divFloor(output.usable_height, 2) - @divFloor(window.float_height, 2);
window.pending_render.x = window.float_x;
window.pending_render.y = window.float_y;
window.river_window_v1.proposeDimensions(window.float_width, window.float_height);
context.wm.river_window_manager_v1.manageDirty();
}