aboutsummaryrefslogtreecommitdiff
path: root/src/object.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-08-27 09:02:43 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2025-08-27 09:03:21 +0200
commit8a7392dea729d3ed49a8bf8eee25906c4fd616ac (patch)
tree09e0b2fa96c60a2e0c8b0cae9e631bd2dc66f52f /src/object.zig
parentc217e7ec5cddfc002c4582fb5d52727aee843a7d (diff)
Add ancillary data mechanism to send fds to compositor.
Currently we are just attaching the fds to the object id. In theory this is not a valid implementation, since if we have more than MAX_FD file descriptors this will not work. But since this wont be the case in basically all cases of the wayland protocol, we can just ignore that for now.
Diffstat (limited to 'src/object.zig')
-rw-r--r--src/object.zig22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/object.zig b/src/object.zig
index 14089c1..5502d3d 100644
--- a/src/object.zig
+++ b/src/object.zig
@@ -6,13 +6,24 @@ const Self = @This();
pub const Ref = usize;
const VTable = struct {
- on_event: *const fn (ptr: *anyopaque, ctx: *wayland.Context, opcode: u16, args: []const u8) void,
+ on_event: *const fn (
+ ptr: *anyopaque,
+ ctx: *const wayland.Context,
+ opcode: u16,
+ args: []const u8,
+ ) void,
};
ptr: ?*anyopaque,
vtable: VTable,
+name: []const u8,
-pub inline fn on_event(self: *Self, ctx: *wayland.Context, opcode: u16, args: []const u8) !void {
+pub inline fn on_event(
+ self: *Self,
+ ctx: *const wayland.Context,
+ opcode: u16,
+ args: []const u8,
+) !void {
if (self.ptr) |ptr| {
self.vtable.on_event(ptr, ctx, opcode, args);
} else {
@@ -21,11 +32,14 @@ pub inline fn on_event(self: *Self, ctx: *wayland.Context, opcode: u16, args: []
}
pub inline fn from_self(ptr: anytype) Self {
+ const T = @TypeOf(ptr.*);
+
return .{
.ptr = ptr,
.vtable = VTable{
- .on_event = @TypeOf(ptr.*).Events.on_event,
+ .on_event = T.Events.on_event,
},
+ .name = @typeName(T),
};
}
@@ -42,5 +56,5 @@ pub fn format(
_ = fmt;
_ = options;
- try writer.print("Object {{ {?} }}", .{self.ptr});
+ try writer.print("Object<{s}> {{ {?} }}", .{self.name, self.ptr});
}