diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-08-24 07:08:31 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-08-24 07:08:31 +0200 |
| commit | e66af367ddc2a17e8218efd37ddabd3a6b7557a4 (patch) | |
| tree | f363c1661902760be57da31f937ff842e560b44e /src/wl/shm/root.zig | |
| parent | c2e723ca28321e09fbf58f396cb9e98591344a7e (diff) | |
Add wl.shm
Diffstat (limited to 'src/wl/shm/root.zig')
| -rw-r--r-- | src/wl/shm/root.zig | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/wl/shm/root.zig b/src/wl/shm/root.zig new file mode 100644 index 0000000..2d24aca --- /dev/null +++ b/src/wl/shm/root.zig @@ -0,0 +1,69 @@ +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("}}", .{}); +} |