Begin work to add wallpaper support to beansprout

Added pixman and zigimg dependencies
Set up in build.zig, added to both exe and exe_check

Add new protocols:
     river-layer-shell-v1
     wlr-layer-shell-unstable-v1
     xdg-shell (dep of wlr-layer-shell-unstable-v1)

Update Context.zig to hold wl_output, wl_shm, and a WallpaperImage
Also re-ordered all of its fields into alphabetical order
Context.create() now takes a Context.Options struct so that it takes
     one arg instead of many smaller args.

Added new WallpaperImage.zig, but it's not yet actually used
This commit is contained in:
Ben Buhse 2026-02-06 16:37:33 -06:00
commit fb8817ebf9
No known key found for this signature in database
GPG key ID: 7916ACFCD38FD0B4
7 changed files with 718 additions and 26 deletions

60
src/WallpaperImage.zig Normal file
View file

@ -0,0 +1,60 @@
// SPDX-FileCopyrightText: 2026 Ben Buhse <me@benbuhse.email>
//
// SPDX-License-Identifier: GPL-3.0-or-later
const WallpaperImage = @This();
image: *pixman.Image,
pixels: std.ArrayList(u32),
// TODO: Make image_path nullable, if null, do a single color with a single_pixel_buffer instead(?)
pub fn create(image_path: []const u8) !*WallpaperImage {
var wallpaper_image = try utils.allocator.create(WallpaperImage);
errdefer utils.allocator.destroy(wallpaper_image);
var read_buf: [zigimg.io.DEFAULT_BUFFER_SIZE]u8 = undefined;
var image = try zigimg.Image.fromFilePath(utils.allocator, image_path, &read_buf);
defer image.deinit(utils.allocator);
// We don't want to deal with all the possible formats,
// so let's just convert to one we can use with pixman.
if (image.pixelFormat() != .rgba32) {
try image.convert(utils.allocator, .rgba32);
}
log.debug("image loaded ({}x{})", .{ image.width, image.height });
const pixels = image.pixels.rgba32;
// We have to manually convert to argb --
// It's only guaranteed that Wayland compositors will have xrgb and argb support but zigimg doesn't have either of those.
wallpaper_image.pixels = try std.ArrayList(u32).initCapacity(utils.allocator, pixels.len);
errdefer wallpaper_image.pixels.deinit(utils.allocator);
for (0..pixels.len) |i| {
const a: u32 = @intCast(pixels[i].a);
const r: u32 = @intCast(pixels[i].r);
const g: u32 = @intCast(pixels[i].g);
const b: u32 = @intCast(pixels[i].b);
const new_val: u32 = (a << 24) + (r << 16) + (g << 8) + b;
try wallpaper_image.pixels.append(utils.allocator, new_val);
}
wallpaper_image.image = pixman.Image.createBits(.a8r8g8b8, @intCast(image.width), @intCast(image.height), @ptrCast(@alignCast(wallpaper_image.pixels.items.ptr)), @intCast(image.width * image.pixelFormat().pixelStride())) orelse return error.FailedToCreatePixmanImage;
return wallpaper_image;
}
pub fn destroy(wallpaper_image: *WallpaperImage) void {
_ = wallpaper_image.image.unref();
wallpaper_image.pixels.deinit(utils.allocator);
utils.allocator.destroy(wallpaper_image);
}
const std = @import("std");
const pixman = @import("pixman");
const zigimg = @import("zigimg");
const utils = @import("utils.zig");
const log = std.log.scoped(.WallpaperImage);