From f0f2124949056e3008416dcd089766a2ef69a08b Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 27 Aug 2025 20:21:34 +0200 Subject: add wl.buffer and wl.surface --- src/wl/surface.zig | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/wl/surface.zig (limited to 'src/wl/surface.zig') diff --git a/src/wl/surface.zig b/src/wl/surface.zig new file mode 100644 index 0000000..7b5116e --- /dev/null +++ b/src/wl/surface.zig @@ -0,0 +1,105 @@ +const std = @import("std"); +const wayland = @import("../root.zig"); +const wl = wayland.wl; + +const Self = @This(); + +pub const Request = union(enum) { + destroy: void, + attach: struct { ?wayland.Object.Ref, u32, u32 }, + damage: struct { u32, u32, u32, u32 }, + frame: struct { wayland.Object.Ref }, + set_opaque_region: struct { ?wayland.Object.Ref }, + set_input_region: struct { ?wayland.Object.Ref }, + commit: void, + set_buffer_transform: struct { wl.Output.Format }, + set_buffer_scale: struct { u32 }, + damage_buffer: struct { u32, u32, u32, u32 }, + offset: struct { i32, i32 }, +}; + +pub const Events = wayland.EventSet(Self, .{ + enter, + leave, + preferred_buffer_scale_announced, + preferred_buffer_transform_announced, +}); + +handle: wayland.Object.Ref, +preferred_buffer_scale: u32 = 1, +preferred_buffer_transform: wl.Output.Transform = .normal, + +pub fn init( + self: *Self, + ctx: *const wayland.Context, +) !void { + self.* = .{ + .handle = try ctx.display.registry.add_object( + ctx.allocator, + wayland.Object.from_self(self), + ), + }; +} + +pub fn deinit( + self: *Self, + ctx: *const wayland.Context, +) void { + ctx.display.registry.disable_object(self.handle); +} + +fn enter( + self: *Self, + ctx: *const wayland.Context, + output: *wayland.Object, +) void { + _ = self; + _ = ctx; + _ = output; + // TODO: implement +} + +fn leave( + self: *Self, + ctx: *const wayland.Context, + output: *wayland.Object, +) void { + _ = self; + _ = ctx; + _ = output; + // TODO: implement +} + +fn preferred_buffer_scale_announced( + self: *Self, + ctx: *const wayland.Context, + factor: u32, +) void { + _ = ctx; + self.preferred_buffer_scale = factor; +} + + +fn preferred_buffer_transform_announced( + self: *Self, + ctx: *const wayland.Context, + transform: wl.Output.Transform, +) void { + _ = ctx; + self.preferred_buffer_transform = transform; +} + +pub fn format( + self: *const Self, + comptime fmt: []const u8, + options: std.fmt.FormatOptions, + writer: anytype, +) !void { + _ = fmt; + _ = options; + + try writer.print("wl.surface {{ preferred_scale = {}, preferred_transform = {s} }}", .{ + self.preferred_buffer_scale, + @tagName(self.preferred_buffer_transform), + }); +} -- cgit v1.2.3-70-g09d2