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; 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 var instances: std.ArrayListUnmanaged(*Self) = .empty; handle: wayland.Object.Ref, formats: std.EnumSet(Format) = .initEmpty(), pub fn init( self: *Self, ctx: *wayland.Context, ) !void { self.* = .{ .handle = try ctx.display.registry.add_object( ctx.allocator, wayland.Object.from_self(self), ), }; } fn announce_format(self: * Self, ctx: *wayland.Context, fmt: Format) void { _ = ctx; self.formats.insert(fmt); } pub const handler: wl.Registry.GlobalHandler = .{ .interface = "wl_shm", .version = 1, .handler = register, }; fn register(ctx: *wayland.Context) ?wayland.Object.Ref { const shm = ctx.allocator.create(Self) catch return null; shm.init(ctx) catch return null; instances.append(ctx.allocator, shm) catch return null; return shm.handle; } 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("}}", .{}); }