diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-08-18 17:45:13 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-08-18 17:45:13 +0200 |
| commit | 33e1de2710fe44512440e0e6055578d67dab330c (patch) | |
| tree | df8198ac5147f466bba600ca06dc1a319099d185 /src/object.zig | |
First sketch of wayland interface
**WARNING** this implementation is not working properly yet.
Diffstat (limited to 'src/object.zig')
| -rw-r--r-- | src/object.zig | 41 |
1 files changed, 41 insertions, 0 deletions
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}); +} |