From 33e1de2710fe44512440e0e6055578d67dab330c Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 18 Aug 2025 17:45:13 +0200 Subject: First sketch of wayland interface **WARNING** this implementation is not working properly yet. --- src/object.zig | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/object.zig (limited to 'src/object.zig') diff --git a/src/object.zig b/src/object.zig new file mode 100644 index 0000000..0751859 --- /dev/null +++ b/src/object.zig @@ -0,0 +1,41 @@ +const std = @import("std"); +const wayland = @import("root.zig"); + +const Self = @This(); + +const VTable = struct { + on_event: *const fn (ptr: *anyopaque, ctx: *wayland.Context, opcode: u16, args: []const u8) void, +}; + +id: ?u32 = null, +ptr: ?*anyopaque, +vtable: VTable, + +pub inline fn on_event(self: *Self, ctx: *wayland.Context, opcode: u16, args: []const u8) !void { + if (self.ptr) |ptr| { + self.vtable.on_event(ptr, ctx, opcode, args); + } else { + return error.UseAfterRelease; + } +} + +pub inline fn from_self(ptr: anytype) Self { + return .{ + .ptr = ptr, + .vtable = VTable{ + .on_event = @TypeOf(ptr.*).Events.on_event, + }, + }; +} + +pub fn format( + self: *const Self, + comptime fmt: []const u8, + options: std.fmt.FormatOptions, + writer: anytype, +) !void { + _ = fmt; + _ = options; + + try writer.print("Object {{ {?} }}", .{self.id}); +} -- cgit v1.2.3-70-g09d2