diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-08-27 09:02:43 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-08-27 09:03:21 +0200 |
| commit | 8a7392dea729d3ed49a8bf8eee25906c4fd616ac (patch) | |
| tree | 09e0b2fa96c60a2e0c8b0cae9e631bd2dc66f52f /src/wl/shm/pool.zig | |
| parent | c217e7ec5cddfc002c4582fb5d52727aee843a7d (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/wl/shm/pool.zig')
| -rw-r--r-- | src/wl/shm/pool.zig | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/wl/shm/pool.zig b/src/wl/shm/pool.zig index dc30d1b..1f42a17 100644 --- a/src/wl/shm/pool.zig +++ b/src/wl/shm/pool.zig @@ -1,5 +1,10 @@ +const std = @import("std"); const wayland = @import("../../root.zig"); -const Format = @import("root.zig").Format; +const wl = wayland.wl; +const Format = wl.Shm.Format; +const AnonymousFile = wl.Shm.AnonymousFile; + +const Self = @This(); pub const Events = wayland.EventSet(@This(), .{}); pub const Requests = union(enum) { @@ -7,3 +12,33 @@ pub const Requests = union(enum) { destroy: struct {}, resize: struct { u32 }, }; + +handle: wayland.Object.Ref, +file: AnonymousFile, +buffer: []u8, + +pub fn init( + self: *Self, + ctx: *const wayland.Context, + size: usize, +) !void { + var file = try AnonymousFile.init_random(); + errdefer file.close(); + try file.truncate(size); + + self.* = .{ + .handle = try ctx.display.registry.add_object( + ctx.allocator, + wayland.Object.from_self(self), + ), + .file = file, + .buffer = try file.mmap(), + }; +} + +pub fn deinit(self: *Self, ctx: *const wayland.Context) void { + self.file.close(); + std.posix.munmap(@alignCast(self.buffer)); + ctx.display.registry.disable_object(self.handle); + self.* = undefined; +} |