const std = @import("std"); const wayland = @import("../../root.zig"); 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 Request = union(enum) { create_pool: struct { wayland.Object.Ref, wayland.types.Fd, u32 }, }; handle: wayland.Object.Ref = .null, init: wayland.Object.interface.Init(Self) = .{}, formats: std.EnumSet(Format) = .initEmpty(), pub var globals: wayland.Object.interface.Global(Self) = .init; pub const handler: wl.Registry.GlobalHandler = .{ .interface = "wl_shm", .version = 1, .handler = globals.register, }; fn announce_format(self: * Self, ctx: wayland.Context, fmt: Format) void { _ = ctx; self.formats.insert(fmt); } pub fn create_pool(self: *Self, ctx: wayland.Context, size: usize) !*Pool { const pool = try ctx.allocator.create(Pool); errdefer ctx.allocator.destroy(pool); var file = try AnonymousFile.init_random(); errdefer file.close(); try file.truncate(size); try pool.init.with(ctx, .{ .file = file, .buffer = try file.mmap(), }); 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, options: std.fmt.FormatOptions, writer: anytype, ) !void { _ = fmt; _ = options; try writer.print("wl.shm {{ ", .{}); { var iterator = self.formats.iterator(); while (iterator.next()) |f| { try writer.print("{s} ", .{@tagName(f)}); } } try writer.print("}}", .{}); }