aboutsummaryrefslogtreecommitdiff
path: root/src/wl/compositor.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-08-22 20:52:30 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2025-08-22 20:52:30 +0200
commit07c3f2e8f82c55ed191f72fa5e9f3935b1913f98 (patch)
tree48b4ce0e9029efeb9da6f6f95f4ae798d14df14d /src/wl/compositor.zig
parent956ecb061b1862a4b632c8d5d6b6fa4318e1f640 (diff)
add first sketch of wl.compositor
Diffstat (limited to 'src/wl/compositor.zig')
-rw-r--r--src/wl/compositor.zig54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/wl/compositor.zig b/src/wl/compositor.zig
new file mode 100644
index 0000000..6951446
--- /dev/null
+++ b/src/wl/compositor.zig
@@ -0,0 +1,54 @@
+const std = @import("std");
+const wayland = @import("../root.zig");
+const wl = wayland.wl;
+
+const Self = @This();
+
+pub const Events = wayland.EventSet(Self, .{});
+pub const Requests = union(enum) {
+ create_surface: struct { wayland.Object.Ref },
+ create_region: struct { wayland.Object.Ref },
+};
+
+handle: wayland.Object.Ref,
+
+pub var instances: std.ArrayListUnmanaged(*Self) = .empty;
+
+pub const handler: wl.Registry.GlobalHandler = .{
+ .interface = "wl_compositor",
+ .version = 6,
+ .handler = register,
+};
+
+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 register(ctx: *wayland.Context) ?wayland.Object.Ref {
+ const compositor = ctx.allocator.create(Self) catch return null;
+ compositor.init(ctx) catch return null;
+
+ instances.append(ctx.allocator, compositor) catch return null;
+ return compositor.handle;
+}
+
+pub fn format(
+ self: *const Self,
+ comptime fmt: []const u8,
+ options: std.fmt.FormatOptions,
+ writer: anytype,
+) !void {
+ _ = self;
+ _ = fmt;
+ _ = options;
+
+ try writer.print("wl.compositor", .{});
+}