Fix crash when wallpaper_image_path is missing

This makes the WM run fine even if wallpaper_image fails to load for any
other reason. Right now, it's still just a black background. At some
point, I plan to add the ability to also just set a color as a
background but that's a fairly low priority.
This commit is contained in:
Ben Buhse 2026-02-07 17:56:05 -06:00
commit 00835cea08
No known key found for this signature in database
GPG key ID: 7916ACFCD38FD0B4
4 changed files with 28 additions and 6 deletions

View file

@ -208,6 +208,11 @@ fn wlOutputListener(_: *wl.Output, event: wl.Output.Event, output: *Output) void
}
fn initWallpaperLayerSurface(output: *Output) !void {
if (output.context.wallpaper_image == null) {
// No wallpaper image, so we don't need any surfaces
return;
}
if (output.wl_surface) |_| {
log.warn("Skipping adding a second wallpaper surface to {s}", .{output.name orelse "some output"});
return;
@ -319,16 +324,17 @@ fn renderWallpaper(output: *Output) !void {
if (width == 0 or height == 0 or scale == 0) {
return;
}
const buffer: *Buffer = try context.buffer_pool.nextBuffer(context.wl_shm, width * scale, height * scale);
// Scale our loaded image and then copy it into the Buffer's pixman.Image
const image = context.wallpaper_image.image;
const wallpaper_image = context.wallpaper_image orelse return;
const image = wallpaper_image.image;
const image_data = image.getData();
const image_width = image.getWidth();
const image_height = image.getHeight();
const image_stride = image.getStride();
const image_format = image.getFormat();
const buffer: *Buffer = try context.buffer_pool.nextBuffer(context.wl_shm, width * scale, height * scale);
const pix = pixman.Image.createBitsNoClear(image_format, image_width, image_height, image_data, image_stride);
if (pix == null) {
log.err("failed to copy the background image for rendering", .{});