diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-08-27 20:21:34 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-08-27 20:21:34 +0200 |
| commit | f0f2124949056e3008416dcd089766a2ef69a08b (patch) | |
| tree | 7e8f674fda0c5af7f30671e9dd088f7ec7d35e5e /src/wl/buffer.zig | |
| parent | 8a7392dea729d3ed49a8bf8eee25906c4fd616ac (diff) | |
add wl.buffer and wl.surface
Diffstat (limited to 'src/wl/buffer.zig')
| -rw-r--r-- | src/wl/buffer.zig | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/wl/buffer.zig b/src/wl/buffer.zig new file mode 100644 index 0000000..6dd83be --- /dev/null +++ b/src/wl/buffer.zig @@ -0,0 +1,51 @@ +const std = @import("std"); +const wayland = @import("../root.zig"); +const wl = wayland.wl; + +pub fn Buffer(fmt: wl.Shm.Format) type { + return struct { + const Self = @This(); + + pub const Request = union(enum) { + destroy: void, + }; + + pub const Events = wayland.EventSet(Self, .{}); + + handle: wayland.Object.Ref, + data: []wl.Shm.Format.Pixel(fmt), + width: usize, + height: usize, + + pub fn init( + self: *Self, + ctx: *const wayland.Context, + width: usize, + height: usize, + data: []u8, + ) !void { + self.* = .{ + .handle = try ctx.display.registry.add_object( + ctx.allocator, + wayland.Object.from_self(self), + ), + .data = @alignCast(@ptrCast(data)), + .width = width, + .height = height, + }; + } + + pub fn format( + self: *const Self, + comptime f: []const u8, + options: std.fmt.FormatOptions, + writer: anytype, + ) !void { + _ = f; + _ = options; + + try writer.print("wl.buffer<{s}> {{ {}x{} }}", .{@tagName(fmt), self.width, self.height}); + } + }; +} + |