Authentication-Results: mail-a.sr.ht; dkim=pass header.d=disroot.org header.i=@disroot.org Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by mail-a.sr.ht (Postfix) with ESMTPS id 1F6E720910 for <~novakane/public-inbox@lists.sr.ht>; Sun, 19 Apr 2026 21:26:19 +0000 (UTC) Received: from mail01.disroot.lan (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id ECAEC2706B for <~novakane/public-inbox@lists.sr.ht>; Sun, 19 Apr 2026 23:26:18 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id OmryCbhHRPfO for <~novakane/public-inbox@lists.sr.ht>; Sun, 19 Apr 2026 23:26:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1776633978; bh=LyYzJ+gKbYCkCluDYEkuv7dj4+LSYNh9AMBCmdFysxo=; h=To:From:Date:Subject; b=FOdkgSUSh7hqYx13NUZgtzuVb9qKmQux/oUumKbcKJCS25uOIN7aeRBnMUeV0LoPh 6eAhvnGjUJDkM5+7225nIWpgRY7CZjPiOBpjDZaW8I7CMbav0FASEUcZbu42vP8pQt mw52d0gVgBW2J4NYChfWUIGge62MMdQEb1rztq5Y2gE6KJPh//RqxR/w+abpmpGTDs 7KG5BXIRSsb//XrltUSshBtz3LxpYThywyFNy2WIhLKdEG1DcChwRNyEQ8r5+EGso1 vhYDA4gl3/Ef1x5VgSXbEKjqmxvc1Yxvs/eyIlZaKA8fLueNAsDb8Uwo6NGxw+74XH v1S7aAZHAX3dw== Message-Id: To: <~novakane/public-inbox@lists.sr.ht> From: "tranzystorekk" Date: Sun, 19 Apr 2026 17:37:03 +0200 Subject: [PATCH zelbar] Update to zig 0.16 --- .gitignore | 1 + build.zig | 16 +++++++-------- build.zig.zon | 4 ++-- common/flags.zig | 49 ++++++++++++++++++++++++--------------------- src/Backend.zig | 26 ++++++++++++++---------- src/Bar.zig | 3 +-- src/decorations.zig | 2 +- src/event_loop.zig | 2 +- src/main.zig | 38 ++++++++++++++++++++--------------- 9 files changed, 76 insertions(+), 65 deletions(-) diff --git a/.gitignore b/.gitignore index 3b25ac4..09b8add 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .zig-cache/ zig-out/ +zig-pkg/ .valgrindrc diff --git a/build.zig b/build.zig index f7f81b2..797809c 100644 --- a/build.zig +++ b/build.zig @@ -25,7 +25,7 @@ pub fn build(b: *std.Build) !void { const git_describe_long = b.runAllowFail( &[_][]const u8{ "git", "-C", b.build_root.path orelse ".", "describe", "--long" }, &ret, - .Inherit, + .inherit, ) catch break :blk version; var it = mem.splitSequence(u8, mem.trim( @@ -79,19 +79,17 @@ pub fn build(b: *std.Build) !void { zelbar.root_module.addOptions("build_options", options); - zelbar.linkLibC(); - zelbar.root_module.addImport("wayland", wayland); - zelbar.linkSystemLibrary("wayland-client"); - zelbar.linkSystemLibrary("wayland-cursor"); + zelbar.root_module.linkSystemLibrary("wayland-client", .{}); + zelbar.root_module.linkSystemLibrary("wayland-cursor", .{}); zelbar.root_module.addImport("flags", flags); zelbar.root_module.addImport("pixman", pixman); - zelbar.linkSystemLibrary("pixman-1"); + zelbar.root_module.linkSystemLibrary("pixman-1", .{}); zelbar.root_module.addImport("fcft", fcft); - zelbar.linkSystemLibrary("fcft"); + zelbar.root_module.linkSystemLibrary("fcft", .{}); zelbar.pie = pie; @@ -107,8 +105,8 @@ pub fn build(b: *std.Build) !void { tests.root_module.addImport("wayland", wayland); tests.root_module.addImport("pixman", pixman); tests.root_module.addImport("fcft", fcft); - tests.linkSystemLibrary("pixman-1"); - tests.linkSystemLibrary("fcft"); + tests.root_module.linkSystemLibrary("pixman-1", .{}); + tests.root_module.linkSystemLibrary("fcft", .{}); const test_step = b.step("test", "Run all tests"); test_step.dependOn(&b.addRunArtifact(tests).step); } diff --git a/build.zig.zon b/build.zig.zon index 9b18d95..7f84a04 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -9,8 +9,8 @@ .hash = "pixman-0.3.0-LClMnz2VAAAs7QSCGwLimV5VUYx0JFnX5xWU6HwtMuDX", }, .@"zig-wayland" = .{ - .url = "https://codeberg.org/ifreund/zig-wayland/archive/v0.4.0.tar.gz", - .hash = "wayland-0.4.0-lQa1khbMAQAsLS2eBR7M5lofyEGPIbu2iFDmoz8lPC27", + .url = "https://codeberg.org/ifreund/zig-wayland/archive/4a150a04f76f7329e80280661355c04328369d1f.tar.gz", + .hash = "wayland-0.6.0-dev-lQa1krD8AQBlMqwuhAMJjPQKXvpRByZBxxqMVAZ7yzbG", }, .@"zig-fcft" = .{ .url = "https://git.sr.ht/~novakane/zig-fcft/archive/v3.0.0.tar.gz", diff --git a/common/flags.zig b/common/flags.zig index 79adde9..a1e5be8 100644 --- a/common/flags.zig +++ b/common/flags.zig @@ -36,32 +36,35 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type { flags: Flags, pub const Flags = flags_type: { - var fields: []const std.builtin.Type.StructField = &.{}; - for (flags) |flag| { - const field: std.builtin.Type.StructField = switch (flag.kind) { - .boolean => .{ - .name = flag.name, - .type = bool, - .default_value_ptr = &false, - .is_comptime = false, - .alignment = @alignOf(bool), + var field_names: [flags.len][]const u8 = undefined; + var field_types: [flags.len]type = undefined; + var field_attrs: [flags.len]std.builtin.Type.StructField.Attributes = undefined; + for (flags, 0..) |flag, i| { + field_names[i] = flag.name; + switch (flag.kind) { + .boolean => { + field_types[i] = bool; + field_attrs[i] = .{ + .@"align" = @alignOf(bool), + .default_value_ptr = &false, + }; }, - .arg => .{ - .name = flag.name, - .type = ?[:0]const u8, - .default_value_ptr = &@as(?[:0]const u8, null), - .is_comptime = false, - .alignment = @alignOf(?[:0]const u8), + .arg => { + field_types[i] = ?[:0]const u8; + field_attrs[i] = .{ + .@"align" = @alignOf(?[:0]const u8), + .default_value_ptr = &@as(?[:0]const u8, null), + }; }, - }; - fields = fields ++ [_]std.builtin.Type.StructField{field}; + } } - break :flags_type @Type(.{ .@"struct" = .{ - .layout = .auto, - .fields = fields, - .decls = &.{}, - .is_tuple = false, - } }); + break :flags_type @Struct( + .auto, + null, + &field_names, + &field_types, + &field_attrs, + ); }; }; diff --git a/src/Backend.zig b/src/Backend.zig index fd1936a..3401458 100644 --- a/src/Backend.zig +++ b/src/Backend.zig @@ -17,7 +17,7 @@ const std = @import("std"); const assert = std.debug.assert; const builtin = @import("builtin"); -const io = std.io; +const linux = std.os.linux; const mem = std.mem; const posix = std.posix; const fs = std.fs; @@ -98,9 +98,9 @@ const HotSpot = struct { } /// Write action in STDOUT. - fn act(hotspot: HotSpot) !void { + fn act(hotspot: HotSpot, io: std.Io) !void { var stdout_buffer: [stdout_buffer_size]u8 = undefined; - var bw = fs.File.stdout().writer(&stdout_buffer); + var bw = std.Io.File.stdout().writer(io, &stdout_buffer); var writer = &bw.interface; try writer.writeAll(hotspot.action); try writer.writeByte('\n'); @@ -111,6 +111,7 @@ const HotSpot = struct { // Pointers event code have been taken and adapted from // https://git.sr.ht/~leon_plickat/wayprompt, same license. const Seat = struct { + io: std.Io, wl_seat: *wl.Seat, id: u32, @@ -127,8 +128,9 @@ const Seat = struct { node: std.SinglyLinkedList.Node = .{}, - fn init(seat: *Seat, wl_seat: *wl.Seat, id: u32) !void { + fn init(seat: *Seat, io: std.Io, wl_seat: *wl.Seat, id: u32) !void { seat.* = .{ + .io = io, .wl_seat = wl_seat, .id = id, }; @@ -203,7 +205,7 @@ const Seat = struct { .released => { if (seat.press_hotspot == null) return; if (ctx.backend.surface.?.hotspot_from_point(seat.pointer_x, seat.pointer_y)) |hs| { - if (hs == seat.press_hotspot.?) hs.act() catch {}; + if (hs == seat.press_hotspot.?) hs.act(seat.io) catch {}; } seat.press_hotspot = null; }, @@ -294,7 +296,7 @@ const Surface = struct { wl_surface: *wl.Surface = undefined, layer_surface: *zwlr.LayerSurfaceV1 = undefined, - hotspots: std.ArrayListUnmanaged(HotSpot) = .{}, + hotspots: std.ArrayList(HotSpot) = .empty, frame_callback: ?*wl.Callback = null, /// True if we requested a frame callback. @@ -565,13 +567,13 @@ pub const Buffer = struct { .linux, .freebsd => try posix.memfd_createZ("zelbar-shm-buffer-pool", std.os.linux.MFD.CLOEXEC), else => @compileError("target OS not supported"), }; - defer posix.close(fd); - try posix.ftruncate(fd, size); + defer _ = linux.close(fd); + _ = linux.ftruncate(fd, size); // mmap the memory file, to be used by the pximan image. const data = mem.bytesAsSlice( u8, - try posix.mmap(null, size, posix.PROT.READ | posix.PROT.WRITE, .{ .TYPE = .SHARED }, fd, 0), + try posix.mmap(null, size, .{ .READ = true, .WRITE = true }, .{ .TYPE = .SHARED }, fd, 0), ); errdefer posix.munmap(data); @@ -620,6 +622,7 @@ pub const Buffer = struct { } }; +io: std.Io = undefined, display: *wl.Display = undefined, registry: *wl.Registry = undefined, @@ -637,8 +640,9 @@ req_output: *Output = undefined, surface: ?Surface = null, pool: BufferPool = .{}, -pub fn init(backend: *Backend) !bool { +pub fn init(backend: *Backend, io: std.Io) !bool { backend.* = .{ + .io = io, .display = wl.Display.connect(null) catch { ctx.fatal(.backend, "failed to connect to Wayland compositor", .{}); }, @@ -802,7 +806,7 @@ fn registry_event(backend: *Backend, registry: *wl.Registry, event: wl.Registry. const seat = try ctx.gpa.create(Seat); errdefer ctx.gpa.destroy(seat); - try seat.init(wl_seat, ev.name); + try seat.init(backend.io, wl_seat, ev.name); backend.seats.prepend(&seat.node); } else if (mem.orderZ(u8, ev.interface, zwlr.LayerShellV1.interface.name) == .eq) { // Version 3 required for layer_shell.destroy(); diff --git a/src/Bar.zig b/src/Bar.zig index 9180842..883db9d 100644 --- a/src/Bar.zig +++ b/src/Bar.zig @@ -64,7 +64,7 @@ font: *fcft.Font = undefined, req_width: bool = false, /// Raw input received from STDIN. -input: std.ArrayListUnmanaged(u8) = .{}, +input: std.ArrayList(u8) = .empty, pub fn new(config: Config) !Bar { return Bar{ @@ -89,7 +89,6 @@ pub fn render(bar: *Bar, buffer: *Buffer, surface_w: u16, h: u16) !void { bar.config.border.check_size(w, h) catch |err| switch (err) { error.BordersGreaterHeight => ctx.fatal(.bar, "borders greater than bar height({d})", .{h}), error.BordersGreaterWidth => ctx.fatal(.bar, "borders greater than bar width({d})", .{w}), - else => return err, }; // Starting position of the bar in the output. diff --git a/src/decorations.zig b/src/decorations.zig index a4f753d..8a24765 100644 --- a/src/decorations.zig +++ b/src/decorations.zig @@ -142,7 +142,7 @@ pub fn parse_rgba(s: []const u8) !pixman.Color { } /// Check if the color use the right format: "0xRRGGBB" or "0xRRGGBBAA". -pub fn check_rgba(comptime scope: @Type(.enum_literal), s: []const u8) void { +pub fn check_rgba(comptime scope: @EnumLiteral(), s: []const u8) void { if (s.len != 8 and s.len != 10) { ctx.fatal(scope, "color must be '0xRRGGBB' or '0xRRGGBBAA': {s}", .{s}); } diff --git a/src/event_loop.zig b/src/event_loop.zig index 2a70b8e..a97d195 100644 --- a/src/event_loop.zig +++ b/src/event_loop.zig @@ -91,6 +91,6 @@ pub fn run() !void { ctx.backend.flush_wayland_and_prepare_read(); } -fn handle_sig(_: c_int) callconv(.c) void { +fn handle_sig(_: posix.SIG) callconv(.c) void { ctx.initialized = false; } diff --git a/src/main.zig b/src/main.zig index 592ebbf..50b966e 100644 --- a/src/main.zig +++ b/src/main.zig @@ -16,10 +16,9 @@ const std = @import("std"); const fmt = std.fmt; -const io = std.io; +const linux = std.os.linux; const mem = std.mem; const posix = std.posix; -const fs = std.fs; const build_options = @import("build_options"); const fcft = @import("fcft"); @@ -71,12 +70,12 @@ const Context = struct { pub fn fatal( _: Context, - comptime scope: @Type(.enum_literal), + comptime scope: @EnumLiteral(), comptime format: []const u8, args: anytype, ) noreturn { std.log.scoped(scope).err(format, args); - posix.exit(1); + linux.exit(1); } }; @@ -87,7 +86,14 @@ const background: []const u8 = "0xf9f9fa"; const foreground: []const u8 = "0x202325"; const line: []const u8 = "0x9e2f59"; -pub fn main() anyerror!void { +pub fn main(init: std.process.Init) anyerror!void { + const io = init.io; + const argv = try init.minimal.args.toSlice(init.arena.allocator()); + + var stderr_buffer: [1024]u8 = undefined; + var stderr_writer = std.Io.File.stderr().writer(io, &stderr_buffer); + const stderr = &stderr_writer.interface; + // Default configuration changed by cli options. var default_cfg: Bar.Config = .{}; try default_cfg.colors.putNoClobber(context.gpa, .bg, background); @@ -95,7 +101,7 @@ pub fn main() anyerror!void { try default_cfg.colors.putNoClobber(context.gpa, .line, line); // Parse cli options. - const result = flags.parser([*:0]const u8, &.{ + const result = flags.parser([:0]const u8, &.{ .{ .name = "h", .kind = .boolean }, .{ .name = "version", .kind = .boolean }, .{ .name = "o", .kind = .arg }, @@ -111,23 +117,23 @@ pub fn main() anyerror!void { .{ .name = "bc", .kind = .arg }, .{ .name = "lh", .kind = .arg }, .{ .name = "lc", .kind = .arg }, - }).parse(std.os.argv[1..]) catch { - try fs.File.stderr().writeAll(usage); - posix.exit(1); + }).parse(argv[1..]) catch { + try stderr.writeAll(usage); + linux.exit(1); }; if (result.args.len != 0) { log.err("unknown option '{s}'", .{result.args[0]}); - fs.File.stderr().writeAll(usage) catch {}; - posix.exit(1); + stderr.writeAll(usage) catch {}; + linux.exit(1); } if (result.flags.h) { - try fs.File.stderr().writeAll(usage); - posix.exit(0); + try stderr.writeAll(usage); + linux.exit(0); } if (result.flags.version) { - try fs.File.stderr().writeAll(build_options.version ++ "\n"); - posix.exit(0); + try stderr.writeAll(build_options.version ++ "\n"); + linux.exit(0); } if (result.flags.o) |raw| default_cfg.output_name = raw; if (result.flags.btm) default_cfg.location = .bottom; @@ -205,7 +211,7 @@ pub fn main() anyerror!void { defer fcft.fini(); context.bar = try Bar.new(default_cfg); - context.initialized = try context.backend.init(); + context.initialized = try context.backend.init(io); defer context.deinit(); try event_loop.run(); base-commit: b1f1fe4a7f30332fbe6bffeaea77ef292c0f1932 -- 2.53.0