From ed0ec55697b11fa54ff661bc6c250398a096f85a Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 27 Aug 2025 20:34:57 +0200 Subject: update Object.Ref to be a struct --- src/wl/registry.zig | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/wl/registry.zig') diff --git a/src/wl/registry.zig b/src/wl/registry.zig index 0939d17..2c15c67 100644 --- a/src/wl/registry.zig +++ b/src/wl/registry.zig @@ -12,7 +12,7 @@ pub const Events = wayland.EventSet(Self, .{ }); pub const Request = union(enum) { - bind: struct { u32, []const u8, u32, u32 }, + bind: struct { u32, []const u8, u32, wayland.Object.Ref }, }; pub const GlobalHandler = struct { @@ -33,13 +33,13 @@ pub fn init( ) !void { self.* = .{ .handlers = handlers, - .handle = 2, + .handle = .registry, }; try self.objects.append(allocator, null); try self.objects.append(allocator, wayland.Object.from_self(display)); try self.objects.append(allocator, wayland.Object.from_self(self)); - display.handle = 1; + display.handle = .display; try display.request(display, .{ .get_registry = .{ self.handle } }); } @@ -56,26 +56,26 @@ pub fn add_object( for (self.objects.items[1..], 1..) |obj, index| { if (obj == null) { self.objects.items[index] = object; - return index; + return .{ .id = @truncate(index) }; } } try self.objects.append(allocator, object); - return self.objects.items.len - 1; + return .{ .id = @truncate(self.objects.items.len - 1) }; } -pub fn disable_object(self: *Self, id: usize) void { - if (self.objects.items[id]) |*object| { +pub fn disable_object(self: *Self, handle: wayland.Object.Ref) void { + if (self.objects.items[handle.id]) |*object| { object.disable(); } } -pub fn release_object(self: *Self, id: u32) void { - self.objects.items[id] = null; +pub fn release_object(self: *Self, handle: wayland.Object.Ref) void { + self.objects.items[handle.id] = null; } -pub fn get(self: *Self, handle: usize) ?*wayland.Object { - if (self.objects.items[handle]) |*objects| { +pub fn get_by_id(self: *Self, id: u32) ?*wayland.Object { + if (self.objects.items[id]) |*objects| { return objects; } return null; @@ -96,7 +96,7 @@ fn global( name, interface, version, - @truncate(object_ref), + object_ref, } }); } } -- cgit v1.2.3-70-g09d2