From 4d379a272c2875b26a25bca3fe3c1f161b614954 Mon Sep 17 00:00:00 2001 From: Ben Buhse Date: Sun, 8 Feb 2026 15:11:03 -0600 Subject: [PATCH] Change many "orelse return" sections to log.err Beansprout will still continue gracefully, but I added handling so that they'll log errors so we should have some record of something beind wrong. --- README.md | 12 +++++++----- src/Output.zig | 5 ++--- src/Seat.zig | 15 ++++++++++++--- src/XkbBindings.zig | 20 ++++++++++++++++---- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ab852cd..08abbe7 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,13 @@ SPDX-License-Identifier: GPL-3.0-or-later These are in rough order of my priority, though no promises I do them in this order. -- [ ] Switch all structs to idiomatic Zig init/deinit pattern (init returns value, caller decides stack/heap) -- [ ] Implement runtime log levels -- [ ] Support per-host config using properties +- [ ] Support per-host config using properties (maybe also per-output?) +- [ ] Add input configuration, i.e. pointer acceleration and that type of thing - [ ] Support a basic bar +- [ ] Implement runtime log levels - [ ] Support starting programs at WM launch - [ ] Support overriding config location -- [ ] Add support for multimedia/brightness keys -- [ ] Make "orelse return" bits into errors; handle gracefully +- [ ] Add support for multimedia/brightness keys (this might not be neccesary) - [ ] Support multiple seats - [ ] Support clipping floating windows on edge of/between outputs - [x] Support changeable primary ratio @@ -25,3 +24,6 @@ These are in rough order of my priority, though no promises I do them in this or - [x] Support multiple outputs - [x] Support floating windows - [x] Support wallpapers +- [x] Make "orelse return" bits into errors; handle gracefully +- [ ] Switch all structs to idiomatic Zig init/deinit pattern (init returns value, caller decides stack/heap) + - I'm not sure I really need this diff --git a/src/Output.zig b/src/Output.zig index bad1c0c..69cc10b 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -295,7 +295,7 @@ fn wallpaperLayerSurfaceListener(layer_surface: *zwlr.LayerSurfaceV1, event: zwl output.configured = true; output.renderWallpaper() catch |err| { - fatal("Wallpaper render failed: E{}", .{err}); + log.err("Wallpaper render failed: {}", .{err}); }; }, .closed => { @@ -334,7 +334,7 @@ pub fn renderWallpaper(output: *Output) !void { return; } // Scale our loaded image and then copy it into the Buffer's pixman.Image - const wallpaper_image = context.wallpaper_image orelse return; + const wallpaper_image = context.wallpaper_image orelse return error.MissingWallpaperImage; const image = wallpaper_image.image; const image_data = image.getData(); const image_width = image.getWidth(); @@ -559,7 +559,6 @@ fn calculatePrimaryStackLayout(output: *Output) void { const std = @import("std"); const assert = std.debug.assert; -const fatal = std.process.fatal; const mem = std.mem; const DoublyLinkedList = std.DoublyLinkedList; diff --git a/src/Seat.zig b/src/Seat.zig index 77be600..3402d56 100644 --- a/src/Seat.zig +++ b/src/Seat.zig @@ -106,7 +106,10 @@ fn seatListener(river_seat_v1: *river.SeatV1, event: river.SeatV1.Event, seat: * // river_window_v1 needs to be optional because ev.window is optional fn setWindowFocus(seat: *Seat, river_window_v1: ?*river.WindowV1) void { const wv1 = river_window_v1 orelse return; - const window: *Window = @ptrCast(@alignCast(wv1.getUserData() orelse return)); + const window: *Window = @ptrCast(@alignCast(wv1.getUserData() orelse { + log.err("river_window_v1 has no user data", .{}); + return; + })); seat.pending_manage.window = .{ .window = window }; } @@ -201,7 +204,10 @@ pub fn manage(seat: *Seat) void { switch (seat.pointer_op) { .none => {}, .move => |op| { - const output = op.window.output orelse return; + const output = op.window.output orelse { + log.err("window has no output during move operation", .{}); + return; + }; const min_x = output.x; const max_x = output.x + output.width - @as(i32, op.window.float_width); const min_y = output.y; @@ -242,7 +248,10 @@ pub fn manage(seat: *Seat) void { } // Clamp position to output bounds - const output = op.window.output orelse return; + const output = op.window.output orelse { + log.err("window has no output during resize operation", .{}); + return; + }; new_x = std.math.clamp(new_x, output.x, @max(output.x, output.x + output.width - new_width)); new_y = std.math.clamp(new_y, output.y, @max(output.y, output.y + output.height - new_height)); diff --git a/src/XkbBindings.zig b/src/XkbBindings.zig index 48f2847..7b3bb61 100644 --- a/src/XkbBindings.zig +++ b/src/XkbBindings.zig @@ -118,7 +118,10 @@ const XkbBinding = struct { if (current_focus.floating) return; // Get the first tiled window to try zoom with - const output = current_focus.output orelse return; + const output = current_focus.output orelse { + log.err("focused window has no output during zoom", .{}); + return; + }; const first_tiled: *Window = blk: { var it = output.windows.iterator(.forward); while (it.next()) |window| { @@ -333,7 +336,10 @@ 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 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); @@ -351,7 +357,10 @@ 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 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; @@ -373,7 +382,10 @@ const XkbBinding = struct { fn swapWindow(context: *Context, comptime direction: enum { next, prev }) void { const seat = context.wm.seats.first() orelse return; const window = seat.focused_window orelse return; - const output = window.output orelse return; + const output = window.output orelse { + log.err("focused window has no output during swap", .{}); + return; + }; const target = switch (direction) { .next => output.nextWindow(window), .prev => output.prevWindow(window),