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/root.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/root.zig')
| -rw-r--r-- | src/wl/shm/root.zig | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/wl/shm/root.zig b/src/wl/shm/root.zig index 2d24aca..fd96727 100644 --- a/src/wl/shm/root.zig +++ b/src/wl/shm/root.zig @@ -4,12 +4,13 @@ const wl = wayland.wl; pub const Pool = @import("pool.zig"); pub const Format = @import("format.zig").Format; +pub const AnonymousFile = @import("anonymous-file.zig"); const Self = @This(); pub const Events = wayland.EventSet(Self, .{ announce_format }); -pub const Requests = union(enum) { - create_pool: struct { u32, wayland.types.Fd, u32 }, +pub const Request = union(enum) { + create_pool: struct { wayland.Object.Ref, wayland.types.Fd, u32 }, }; pub var instances: std.ArrayListUnmanaged(*Self) = .empty; @@ -19,7 +20,7 @@ formats: std.EnumSet(Format) = .initEmpty(), pub fn init( self: *Self, - ctx: *wayland.Context, + ctx: *const wayland.Context, ) !void { self.* = .{ .handle = try ctx.display.registry.add_object( @@ -29,7 +30,7 @@ pub fn init( }; } -fn announce_format(self: * Self, ctx: *wayland.Context, fmt: Format) void { +fn announce_format(self: * Self, ctx: *const wayland.Context, fmt: Format) void { _ = ctx; self.formats.insert(fmt); } @@ -40,7 +41,7 @@ pub const handler: wl.Registry.GlobalHandler = .{ .handler = register, }; -fn register(ctx: *wayland.Context) ?wayland.Object.Ref { +fn register(ctx: *const wayland.Context) ?wayland.Object.Ref { const shm = ctx.allocator.create(Self) catch return null; shm.init(ctx) catch return null; @@ -48,6 +49,20 @@ fn register(ctx: *wayland.Context) ?wayland.Object.Ref { return shm.handle; } +pub fn create_pool(self: *Self, ctx: *const wayland.Context, size: usize) !*Pool { + const pool = try ctx.allocator.create(Pool); + errdefer ctx.allocator.destroy(pool); + try pool.init(ctx, size); + + try ctx.display.request(self, .{ .create_pool = .{ + pool.handle, + .{ .fd = pool.file.fd }, + @truncate(size) + } }); + + return pool; +} + pub fn format( self: *const Self, comptime fmt: []const u8, |