From 4feb8c7dab2b0a3492b8248ee12c3f0a475106f1 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Fri, 29 Aug 2025 18:21:48 +0200 Subject: Use wayland.Context instead of *const wayland.Context --- src/event-set.zig | 4 ++-- src/main.zig | 10 +++++----- src/object.zig | 4 ++-- src/wl/buffer.zig | 2 +- src/wl/callback.zig | 6 +++--- src/wl/compositor.zig | 6 +++--- src/wl/display.zig | 16 ++++++++-------- src/wl/output/root.zig | 16 ++++++++-------- src/wl/registry.zig | 6 +++--- src/wl/shm/pool.zig | 6 +++--- src/wl/shm/root.zig | 8 ++++---- src/wl/surface.zig | 12 ++++++------ 12 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/event-set.zig b/src/event-set.zig index 0ff16f1..193e12d 100644 --- a/src/event-set.zig +++ b/src/event-set.zig @@ -3,7 +3,7 @@ const wayland = @import("root.zig"); pub fn EventSet(T: type, events: anytype) type { return struct { - pub fn on_event(ptr: *anyopaque, ctx: *const wayland.Context, opcode: u16, args: []const u8) void { + pub fn on_event(ptr: *anyopaque, ctx: wayland.Context, opcode: u16, args: []const u8) void { var offset: usize = 0; inline for (events, 0..) |event, index| { if (@TypeOf(event) != @TypeOf(null) and index == opcode) { @@ -66,7 +66,7 @@ test { a: u32 = 0, b: u32 = 0, - pub fn something(self: *@This(), _: *const wayland.Context, a: u32, b: u32) void { + pub fn something(self: *@This(), _: wayland.Context, a: u32, b: u32) void { self.a = a; self.b = b; } diff --git a/src/main.zig b/src/main.zig index f02a603..400df48 100644 --- a/src/main.zig +++ b/src/main.zig @@ -44,16 +44,16 @@ pub fn main() !void { log.debug("{}", .{shm}); } - const pool = try wl.Shm.instances.items[0].create_pool(&ctx, 800 * 600 * (wl.Shm.Format.argb8888).bytes_per_pixel()); - defer pool.deinit(&ctx); + const pool = try wl.Shm.instances.items[0].create_pool(ctx, 800 * 600 * (wl.Shm.Format.argb8888).bytes_per_pixel()); + defer pool.deinit(ctx); try display.roundtrip(allocator); - const buffer = try pool.create_buffer(&ctx, 0, 800, 600, .argb8888); + const buffer = try pool.create_buffer(ctx, 0, 800, 600, .argb8888); defer ctx.display.request(buffer, .{ .destroy = {} }) catch |e| log.err("error {}", .{e}); - const surface = try wl.Compositor.instances.items[0].create_surface(&ctx); - defer surface.deinit(&ctx); + const surface = try wl.Compositor.instances.items[0].create_surface(ctx); + defer surface.deinit(ctx); try display.roundtrip(allocator); diff --git a/src/object.zig b/src/object.zig index 5b7726e..7820674 100644 --- a/src/object.zig +++ b/src/object.zig @@ -18,7 +18,7 @@ pub const Ref = struct { const VTable = struct { on_event: *const fn ( ptr: *anyopaque, - ctx: *const wayland.Context, + ctx: wayland.Context, opcode: u16, args: []const u8, ) void, @@ -30,7 +30,7 @@ name: []const u8, pub inline fn on_event( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, opcode: u16, args: []const u8, ) !void { diff --git a/src/wl/buffer.zig b/src/wl/buffer.zig index 6dd83be..fe69899 100644 --- a/src/wl/buffer.zig +++ b/src/wl/buffer.zig @@ -19,7 +19,7 @@ pub fn Buffer(fmt: wl.Shm.Format) type { pub fn init( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, width: usize, height: usize, data: []u8, diff --git a/src/wl/callback.zig b/src/wl/callback.zig index 24927b4..ad2d192 100644 --- a/src/wl/callback.zig +++ b/src/wl/callback.zig @@ -13,7 +13,7 @@ handle: wayland.Object.Ref, pub fn init( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, is_done: *bool, ) !void { self.is_done = is_done; @@ -25,11 +25,11 @@ pub fn init( } -pub fn deinit(self: *Self, ctx: *const wayland.Context) void { +pub fn deinit(self: *Self, ctx: wayland.Context) void { ctx.display.registry.disable_object(self.handle); } -fn done(self: *Self, ctx: *const wayland.Context, value: u32) void { +fn done(self: *Self, ctx: wayland.Context, value: u32) void { _ = value; _ = ctx; self.is_done.* = true; diff --git a/src/wl/compositor.zig b/src/wl/compositor.zig index ae8d15e..166430a 100644 --- a/src/wl/compositor.zig +++ b/src/wl/compositor.zig @@ -22,7 +22,7 @@ pub const handler: wl.Registry.GlobalHandler = .{ pub fn init( self: *Self, - ctx: *const wayland.Context + ctx: wayland.Context ) !void { self.* = .{ .handle = try ctx.display.registry.add_object( @@ -32,7 +32,7 @@ pub fn init( }; } -fn register(ctx: *const wayland.Context) ?wayland.Object.Ref { +fn register(ctx: wayland.Context) ?wayland.Object.Ref { const compositor = ctx.allocator.create(Self) catch return null; compositor.init(ctx) catch return null; @@ -55,7 +55,7 @@ pub fn format( pub fn create_surface( self: *Self, - ctx: *const wayland.Context + ctx: wayland.Context ) !*wl.Surface { const surface = try ctx.allocator.create(wl.Surface); errdefer ctx.allocator.destroy(surface); diff --git a/src/wl/display.zig b/src/wl/display.zig index d8b9e93..fed8bbd 100644 --- a/src/wl/display.zig +++ b/src/wl/display.zig @@ -164,7 +164,7 @@ pub fn request(self: *Self, object: anytype, args: @TypeOf(object.*).Request) !v return error.InvalidOpcode; } -fn read_event(self: *Self, ctx: *const wayland.Context) !void { +fn read_event(self: *Self, ctx: wayland.Context) !void { const endian = @import("builtin").target.cpu.arch.endian(); const reader = self.stream.reader(); @@ -192,7 +192,7 @@ fn read_event(self: *Self, ctx: *const wayland.Context) !void { } pub fn roundtrip(self: *Self, allocator: std.mem.Allocator) !void { - var context: wayland.Context = .{ + const context: wayland.Context = .{ .display = self, .allocator = allocator, }; @@ -200,21 +200,21 @@ pub fn roundtrip(self: *Self, allocator: std.mem.Allocator) !void { var done = false; var callback: wl.Callback = undefined; - try callback.init(&context, &done); - defer callback.deinit(&context); + try callback.init(context, &done); + defer callback.deinit(context); - errdefer self.read_event(&context) catch |e| { + errdefer self.read_event(context) catch |e| { log.err("cleanup error: {}", .{e}); }; while (!done) { - try self.read_event(&context); + try self.read_event(context); } } fn err( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, object: *wayland.Object, code: u32, message: []const u8, @@ -226,7 +226,7 @@ fn err( fn delete_id( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, id: u32, ) void { _ = ctx; diff --git a/src/wl/output/root.zig b/src/wl/output/root.zig index f4ca36d..61c1798 100644 --- a/src/wl/output/root.zig +++ b/src/wl/output/root.zig @@ -38,7 +38,7 @@ handle: wayland.Object.Ref, pub fn init( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, ) !void { self.* = .{ .handle = try ctx.display.registry.add_object( @@ -58,7 +58,7 @@ pub const handler: wl.Registry.GlobalHandler = .{ .handler = register, }; -fn register(ctx: *const wayland.Context) ?wayland.Object.Ref { +fn register(ctx: wayland.Context) ?wayland.Object.Ref { const output = ctx.allocator.create(Self) catch return null; output.init(ctx) catch return null; @@ -68,7 +68,7 @@ fn register(ctx: *const wayland.Context) ?wayland.Object.Ref { fn geometry( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, x: u32, y: u32, physical_width: u32, @@ -93,7 +93,7 @@ fn geometry( fn mode( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, flags: Mode.Kind, width: u32, height: u32, @@ -108,7 +108,7 @@ fn mode( }; } -fn done(self: *Self, ctx: *const wayland.Context) void { +fn done(self: *Self, ctx: wayland.Context) void { if (self.info) |info| { ctx.allocator.free(info.name); ctx.allocator.free(info.description); @@ -117,17 +117,17 @@ fn done(self: *Self, ctx: *const wayland.Context) void { self.info = self.staging; } -fn scale(self: *Self, ctx: *const wayland.Context, factor: u32) void { +fn scale(self: *Self, ctx: wayland.Context, factor: u32) void { _ = ctx; self.staging.scale = factor; } -fn name(self: *Self, ctx: *const wayland.Context, n: []const u8) !void { +fn name(self: *Self, ctx: wayland.Context, n: []const u8) !void { self.staging.name = try ctx.allocator.alloc(u8, n.len); @memcpy(@constCast(self.staging.name), n); } -fn description(self: *Self, ctx: *const wayland.Context, d: []const u8) !void { +fn description(self: *Self, ctx: wayland.Context, d: []const u8) !void { self.staging.description = try ctx.allocator.alloc(u8, d.len); @memcpy(@constCast(self.staging.description), d); } diff --git a/src/wl/registry.zig b/src/wl/registry.zig index 2c15c67..dedf89f 100644 --- a/src/wl/registry.zig +++ b/src/wl/registry.zig @@ -18,7 +18,7 @@ pub const Request = union(enum) { pub const GlobalHandler = struct { interface: []const u8, version: u32, - handler: *const fn (ctx: *const wayland.Context) ?wayland.Object.Ref, + handler: *const fn (ctx: wayland.Context) ?wayland.Object.Ref, }; objects: std.ArrayListUnmanaged(?wayland.Object) = .empty, @@ -83,7 +83,7 @@ pub fn get_by_id(self: *Self, id: u32) ?*wayland.Object { fn global( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, name: u32, interface: []const u8, version: u32, @@ -105,7 +105,7 @@ fn global( fn global_remove( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, name: u32, ) void { _ = self; diff --git a/src/wl/shm/pool.zig b/src/wl/shm/pool.zig index 40486d6..62b6c18 100644 --- a/src/wl/shm/pool.zig +++ b/src/wl/shm/pool.zig @@ -21,7 +21,7 @@ buffer: []u8, pub fn init( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, size: usize, ) !void { var file = try AnonymousFile.init_random(); @@ -38,7 +38,7 @@ pub fn init( }; } -pub fn deinit(self: *Self, ctx: *const wayland.Context) void { +pub fn deinit(self: *Self, ctx: wayland.Context) void { self.file.close(); std.posix.munmap(@alignCast(self.buffer)); ctx.display.registry.disable_object(self.handle); @@ -50,7 +50,7 @@ pub fn deinit(self: *Self, ctx: *const wayland.Context) void { pub fn create_buffer( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, offset: usize, width: usize, height: usize, diff --git a/src/wl/shm/root.zig b/src/wl/shm/root.zig index fd96727..741c7df 100644 --- a/src/wl/shm/root.zig +++ b/src/wl/shm/root.zig @@ -20,7 +20,7 @@ formats: std.EnumSet(Format) = .initEmpty(), pub fn init( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, ) !void { self.* = .{ .handle = try ctx.display.registry.add_object( @@ -30,7 +30,7 @@ pub fn init( }; } -fn announce_format(self: * Self, ctx: *const wayland.Context, fmt: Format) void { +fn announce_format(self: * Self, ctx: wayland.Context, fmt: Format) void { _ = ctx; self.formats.insert(fmt); } @@ -41,7 +41,7 @@ pub const handler: wl.Registry.GlobalHandler = .{ .handler = register, }; -fn register(ctx: *const wayland.Context) ?wayland.Object.Ref { +fn register(ctx: wayland.Context) ?wayland.Object.Ref { const shm = ctx.allocator.create(Self) catch return null; shm.init(ctx) catch return null; @@ -49,7 +49,7 @@ fn register(ctx: *const wayland.Context) ?wayland.Object.Ref { return shm.handle; } -pub fn create_pool(self: *Self, ctx: *const wayland.Context, size: usize) !*Pool { +pub fn create_pool(self: *Self, ctx: wayland.Context, size: usize) !*Pool { const pool = try ctx.allocator.create(Pool); errdefer ctx.allocator.destroy(pool); try pool.init(ctx, size); diff --git a/src/wl/surface.zig b/src/wl/surface.zig index 7b5116e..07cd80b 100644 --- a/src/wl/surface.zig +++ b/src/wl/surface.zig @@ -31,7 +31,7 @@ preferred_buffer_transform: wl.Output.Transform = .normal, pub fn init( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, ) !void { self.* = .{ .handle = try ctx.display.registry.add_object( @@ -43,14 +43,14 @@ pub fn init( pub fn deinit( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, ) void { ctx.display.registry.disable_object(self.handle); } fn enter( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, output: *wayland.Object, ) void { _ = self; @@ -61,7 +61,7 @@ fn enter( fn leave( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, output: *wayland.Object, ) void { _ = self; @@ -72,7 +72,7 @@ fn leave( fn preferred_buffer_scale_announced( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, factor: u32, ) void { _ = ctx; @@ -82,7 +82,7 @@ fn preferred_buffer_scale_announced( fn preferred_buffer_transform_announced( self: *Self, - ctx: *const wayland.Context, + ctx: wayland.Context, transform: wl.Output.Transform, ) void { _ = ctx; -- cgit v1.2.3-70-g09d2