aboutsummaryrefslogtreecommitdiff
path: root/src/wl/shm/root.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-08-30 15:49:18 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2025-08-30 15:49:18 +0200
commita46436e58beaaa322c082af5e886f96fd31d7a08 (patch)
tree05a05b149c2f18cb0562aef94fe41bd5aaad9fbc /src/wl/shm/root.zig
parent4feb8c7dab2b0a3492b8248ee12c3f0a475106f1 (diff)
Use mix-in design for interface abstraction.HEADmaster
Diffstat (limited to 'src/wl/shm/root.zig')
-rw-r--r--src/wl/shm/root.zig44
1 files changed, 16 insertions, 28 deletions
diff --git a/src/wl/shm/root.zig b/src/wl/shm/root.zig
index 741c7df..46388ad 100644
--- a/src/wl/shm/root.zig
+++ b/src/wl/shm/root.zig
@@ -13,46 +13,34 @@ pub const Request = union(enum) {
create_pool: struct { wayland.Object.Ref, wayland.types.Fd, u32 },
};
-pub var instances: std.ArrayListUnmanaged(*Self) = .empty;
-
-handle: wayland.Object.Ref,
+handle: wayland.Object.Ref = .null,
+init: wayland.Object.interface.Init(Self) = .{},
formats: std.EnumSet(Format) = .initEmpty(),
-pub fn init(
- self: *Self,
- ctx: wayland.Context,
-) !void {
- self.* = .{
- .handle = try ctx.display.registry.add_object(
- ctx.allocator,
- wayland.Object.from_self(self),
- ),
- };
-}
-
-fn announce_format(self: * Self, ctx: wayland.Context, fmt: Format) void {
- _ = ctx;
- self.formats.insert(fmt);
-}
-
+pub var globals: wayland.Object.interface.Global(Self) = .init;
pub const handler: wl.Registry.GlobalHandler = .{
.interface = "wl_shm",
.version = 1,
- .handler = register,
+ .handler = globals.register,
};
-fn register(ctx: wayland.Context) ?wayland.Object.Ref {
- const shm = ctx.allocator.create(Self) catch return null;
- shm.init(ctx) catch return null;
-
- instances.append(ctx.allocator, shm) catch return null;
- return shm.handle;
+fn announce_format(self: * Self, ctx: wayland.Context, fmt: Format) void {
+ _ = ctx;
+ self.formats.insert(fmt);
}
pub fn create_pool(self: *Self, ctx: wayland.Context, size: usize) !*Pool {
const pool = try ctx.allocator.create(Pool);
errdefer ctx.allocator.destroy(pool);
- try pool.init(ctx, size);
+
+ var file = try AnonymousFile.init_random();
+ errdefer file.close();
+ try file.truncate(size);
+
+ try pool.init.with(ctx, .{
+ .file = file,
+ .buffer = try file.mmap(),
+ });
try ctx.display.request(self, .{ .create_pool = .{
pool.handle,