From a46436e58beaaa322c082af5e886f96fd31d7a08 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Sat, 30 Aug 2025 15:49:18 +0200 Subject: Use mix-in design for interface abstraction. --- src/wl/compositor.zig | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) (limited to 'src/wl/compositor.zig') diff --git a/src/wl/compositor.zig b/src/wl/compositor.zig index 166430a..ed8ac6b 100644 --- a/src/wl/compositor.zig +++ b/src/wl/compositor.zig @@ -11,35 +11,15 @@ pub const Request = union(enum) { }; handle: wayland.Object.Ref, +init: wayland.Object.interface.Init(Self) = .{}, -pub var instances: std.ArrayListUnmanaged(*Self) = .empty; - +pub var globals: wayland.Object.interface.Global(Self) = .init; pub const handler: wl.Registry.GlobalHandler = .{ .interface = "wl_compositor", .version = 6, - .handler = register, + .handler = globals.register, }; -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 register(ctx: wayland.Context) ?wayland.Object.Ref { - const compositor = ctx.allocator.create(Self) catch return null; - compositor.init(ctx) catch return null; - - instances.append(ctx.allocator, compositor) catch return null; - return compositor.handle; -} - pub fn format( self: *const Self, comptime fmt: []const u8, @@ -60,7 +40,7 @@ pub fn create_surface( const surface = try ctx.allocator.create(wl.Surface); errdefer ctx.allocator.destroy(surface); - try surface.init(ctx); + try surface.init.default(ctx); try ctx.display.request(self, .{ .create_surface = .{ surface.handle } }); -- cgit v1.2.3-70-g09d2