~novakane/rivercarro

8e8afa8bc6db47a43c8ec07856098a14b4fa2c2c — Hugo Machet 1 year, 1 month ago 662618c
Update to zig 0.11
6 files changed, 73 insertions(+), 74 deletions(-)

M .build.yml
M README.md
M build.zig
M common/flags.zig
M deps/zig-wayland
M src/main.zig
M .build.yml => .build.yml +6 -6
@@ 27,22 27,22 @@ sources:
tasks:
  - install_deps: |
      cd wayland
      git checkout 1.21.0
      git checkout 1.22.0
      meson setup build -Ddocumentation=false -Dtests=false --prefix /usr
      sudo ninja -C build install
      cd ..

      cd wlroots
      git checkout 0.16.1
      git checkout 0.16.2
      meson setup build --auto-features=enabled -Drenderers=gles2 -Dexamples=false \
            -Dwerror=false -Db_ndebug=false -Dxwayland=disabled --prefix /usr
      sudo ninja -C build/ install
      cd ..

      wget https://ziglang.org/download/0.10.0/zig-linux-x86_64-0.10.0.tar.xz
      tar -xvf zig-linux-x86_64-0.10.0.tar.xz 1>/dev/null
      sudo mv zig-linux-x86_64-0.10.0/zig /usr/bin/
      sudo mv zig-linux-x86_64-0.10.0/lib /usr/lib/zig
      wget https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.10.0.tar.xz
      tar -xvf zig-linux-x86_64-0.11.0.tar.xz 1>/dev/null
      sudo mv zig-linux-x86_64-0.11.0/zig /usr/bin/
      sudo mv zig-linux-x86_64-0.11.0/lib /usr/lib/zig

      cd river
      sudo zig build --prefix /usr

M README.md => README.md +2 -2
@@ 16,7 16,7 @@ a look at some others great community contributions like [stacktile] or [kile].

## Building

Same requirements as **[river]**, use [zig] 0.10, if **[river]** and
Same requirements as **[river]**, use [zig] 0.11, if **[river]** and
_rivertile_ works on your machine you shouldn't have any problems.

Init submodules:


@@ 25,7 25,7 @@ Init submodules:

Build, `e.g.`

    zig build --prefix ~/.local
    zig build -Doptimize=ReleaseSafe --prefix ~/.local

## Usage


M build.zig => build.zig +22 -29
@@ 5,7 5,7 @@ const assert = std.debug.assert;
const fs = std.fs;
const mem = std.mem;

const ScanProtocolsStep = @import("deps/zig-wayland/build.zig").ScanProtocolsStep;
const Scanner = @import("deps/zig-wayland/build.zig").Scanner;

/// While a rivercarro release is in development, this string should contain
/// the version in development with the "-dev" suffix.  When a release is


@@ 16,19 16,19 @@ const version = "0.3.0-dev";

pub fn build(b: *Builder) !void {
    const target = b.standardTargetOptions(.{});
    const mode = b.standardReleaseOptions();
    const optimize = b.standardOptimizeOption(.{});

    const full_version = blk: {
        if (mem.endsWith(u8, version, "-dev")) {
            var ret: u8 = undefined;

            const git_describe_long = b.execAllowFail(
                &[_][]const u8{ "git", "-C", b.build_root, "describe", "--long" },
                &[_][]const u8{ "git", "-C", b.build_root.path orelse ".", "describe", "--long" },
                &ret,
                .Inherit,
            ) catch break :blk version;

            var it = mem.split(u8, mem.trim(u8, git_describe_long, &std.ascii.spaces), "-");
            var it = mem.split(u8, mem.trim(u8, git_describe_long, &std.ascii.whitespace), "-");
            _ = it.next().?; // previous tag
            const commit_count = it.next().?;
            const commit_hash = it.next().?;


@@ 45,42 45,35 @@ pub fn build(b: *Builder) !void {
        }
    };

    const scanner = ScanProtocolsStep.create(b);
    scanner.addProtocolPath("protocol/river-layout-v3.xml");
    const scanner = Scanner.create(b, .{});

    const exe = b.addExecutable("rivercarro", "src/main.zig");
    exe.setTarget(target);
    exe.setBuildMode(mode);
    const wayland = b.createModule(.{ .source_file = scanner.result });
    const flags = b.createModule(.{ .source_file = .{ .path = "common/flags.zig" } });

    const options = b.addOptions();
    options.addOption([]const u8, "version", full_version);
    exe.addOptions("build_options", options);

    exe.step.dependOn(&scanner.step);

    exe.addPackagePath("flags", "common/flags.zig");
    scanner.addCustomProtocol("protocol/river-layout-v3.xml");

    scanner.generate("wl_output", 4);
    scanner.generate("river_layout_manager_v3", 2);

    exe.addPackage(.{
        .name = "wayland",
        .source = .{ .generated = &scanner.result },
    const exe = b.addExecutable(.{
        .name = "rivercarro",
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });

    exe.addModule("wayland", wayland);
    exe.addModule("flags", flags);

    const options = b.addOptions();
    options.addOption([]const u8, "version", full_version);
    exe.addOptions("build_options", options);

    exe.linkLibC();
    exe.linkSystemLibrary("wayland-client");

    scanner.addCSource(exe);

    exe.install();
    b.installArtifact(exe);
    b.installFile("doc/rivercarro.1", "share/man/man1/rivercarro.1");

    const run_cmd = exe.run();
    run_cmd.step.dependOn(b.getInstallStep());
    if (b.args) |args| {
        run_cmd.addArgs(args);
    }

    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);
}

M common/flags.zig => common/flags.zig +13 -4
@@ 41,14 41,14 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type {
                    const field: std.builtin.Type.StructField = switch (flag.kind) {
                        .boolean => .{
                            .name = flag.name,
                            .field_type = bool,
                            .type = bool,
                            .default_value = &false,
                            .is_comptime = false,
                            .alignment = @alignOf(bool),
                        },
                        .arg => .{
                            .name = flag.name,
                            .field_type = ?[:0]const u8,
                            .type = ?[:0]const u8,
                            .default_value = &@as(?[:0]const u8, null),
                            .is_comptime = false,
                            .alignment = @alignOf(?[:0]const u8),


@@ 70,8 70,13 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type {

            var i: usize = 0;
            outer: while (i < args.len) : (i += 1) {
                const arg = switch (Arg) {
                    [*:0]const u8 => mem.sliceTo(args[i], 0),
                    [:0]const u8 => args[i],
                    else => unreachable,
                };
                inline for (flags) |flag| {
                    if (mem.eql(u8, "-" ++ flag.name, mem.span(args[i]))) {
                    if (mem.eql(u8, "-" ++ flag.name, arg)) {
                        switch (flag.kind) {
                            .boolean => @field(result_flags, flag.name) = true,
                            .arg => {


@@ 81,7 86,11 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type {
                                        "' requires an argument but none was provided!", .{});
                                    return error.MissingFlagArgument;
                                }
                                @field(result_flags, flag.name) = mem.span(args[i]);
                                @field(result_flags, flag.name) = switch (Arg) {
                                    [*:0]const u8 => mem.sliceTo(args[i], 0),
                                    [:0]const u8 => args[i],
                                    else => unreachable,
                                };
                            },
                        }
                        continue :outer;

M deps/zig-wayland => deps/zig-wayland +1 -1
@@ 1,1 1,1 @@
Subproject commit 71d21959b4671a848f1d198f6bb919f54d541f41
Subproject commit b9c6fcb8cab3a85c5583ef371055cb589b1e7b18

M src/main.zig => src/main.zig +29 -32
@@ 62,7 62,7 @@ const usage =
const Command = enum {
    @"inner-gaps",
    @"outer-gaps",
    @"gaps",
    gaps,
    @"main-location",
    @"main-count",
    @"main-ratio",


@@ 138,12 138,12 @@ const Output = struct {
                            return;
                        };
                        switch (raw_arg[0]) {
                            '+' => output.cfg.inner_gaps +|= @intCast(u31, arg),
                            '+' => output.cfg.inner_gaps +|= @intCast(arg),
                            '-' => {
                                const res = output.cfg.inner_gaps +| arg;
                                if (res >= 0) output.cfg.inner_gaps = @intCast(u31, res);
                                if (res >= 0) output.cfg.inner_gaps = @intCast(res);
                            },
                            else => output.cfg.inner_gaps = @intCast(u31, arg),
                            else => output.cfg.inner_gaps = @intCast(arg),
                        }
                    },
                    .@"outer-gaps" => {


@@ 152,33 152,33 @@ const Output = struct {
                            return;
                        };
                        switch (raw_arg[0]) {
                            '+' => output.cfg.outer_gaps +|= @intCast(u31, arg),
                            '+' => output.cfg.outer_gaps +|= @intCast(arg),
                            '-' => {
                                const res = output.cfg.outer_gaps +| arg;
                                if (res >= 0) output.cfg.outer_gaps = @intCast(u31, res);
                                if (res >= 0) output.cfg.outer_gaps = @intCast(res);
                            },
                            else => output.cfg.outer_gaps = @intCast(u31, arg),
                            else => output.cfg.outer_gaps = @intCast(arg),
                        }
                    },
                    .@"gaps" => {
                    .gaps => {
                        const arg = fmt.parseInt(i32, raw_arg, 10) catch |err| {
                            log.err("failed to parse argument: {}", .{err});
                            return;
                        };
                        switch (raw_arg[0]) {
                            '+' => {
                                output.cfg.inner_gaps +|= @intCast(u31, arg);
                                output.cfg.outer_gaps +|= @intCast(u31, arg);
                                output.cfg.inner_gaps +|= @intCast(arg);
                                output.cfg.outer_gaps +|= @intCast(arg);
                            },
                            '-' => {
                                const o = output.cfg.outer_gaps +| arg;
                                const i = output.cfg.inner_gaps +| arg;
                                if (i >= 0) output.cfg.inner_gaps = @intCast(u31, i);
                                if (o >= 0) output.cfg.outer_gaps = @intCast(u31, o);
                                if (i >= 0) output.cfg.inner_gaps = @intCast(i);
                                if (o >= 0) output.cfg.outer_gaps = @intCast(o);
                            },
                            else => {
                                output.cfg.inner_gaps = @intCast(u31, arg);
                                output.cfg.outer_gaps = @intCast(u31, arg);
                                output.cfg.inner_gaps = @intCast(arg);
                                output.cfg.outer_gaps = @intCast(arg);
                            },
                        }
                    },


@@ 194,13 194,13 @@ const Output = struct {
                            return;
                        };
                        switch (raw_arg[0]) {
                            '+' => output.cfg.main_count +|= @intCast(u31, arg),
                            '+' => output.cfg.main_count +|= @intCast(arg),
                            '-' => {
                                const res = output.cfg.main_count +| arg;
                                if (res >= 1) output.cfg.main_count = @intCast(u31, res);
                                if (res >= 1) output.cfg.main_count = @intCast(res);
                            },
                            else => {
                                if (arg >= 1) output.cfg.main_count = @intCast(u31, arg);
                                if (arg >= 1) output.cfg.main_count = @intCast(arg);
                            },
                        }
                    },


@@ 235,13 235,10 @@ const Output = struct {
            .layout_demand => |ev| {
                assert(ev.view_count > 0);

                const main_count = math.min(output.cfg.main_count, @truncate(u31, ev.view_count));
                const sec_count = @truncate(u31, ev.view_count) -| main_count;
                const main_count = @min(output.cfg.main_count, @as(u31, @truncate(ev.view_count)));
                const sec_count = @as(u31, @truncate(ev.view_count)) -| main_count;

                const only_one_view = blk: {
                    if (ev.view_count == 1 or output.cfg.main_location == .monocle) break :blk true;
                    break :blk false;
                };
                const only_one_view = ev.view_count == 1 or output.cfg.main_location == .monocle;

                // Don't add gaps if there is only one view.
                if (only_one_view and cfg.smart_gaps) {


@@ 253,17 250,17 @@ const Output = struct {
                }

                const usable_w = switch (output.cfg.main_location) {
                    .left, .right, .monocle => @floatToInt(
                    .left, .right, .monocle => @as(
                        u31,
                        @intToFloat(f64, ev.usable_width) * output.cfg.width_ratio,
                        @intFromFloat(@as(f64, @floatFromInt(ev.usable_width)) * output.cfg.width_ratio),
                    ) -| (2 *| cfg.outer_gaps),
                    .top, .bottom => @truncate(u31, ev.usable_height) -| (2 *| cfg.outer_gaps),
                    .top, .bottom => @as(u31, @truncate(ev.usable_height)) -| (2 *| cfg.outer_gaps),
                };
                const usable_h = switch (output.cfg.main_location) {
                    .left, .right, .monocle => @truncate(u31, ev.usable_height) -| (2 *| cfg.outer_gaps),
                    .top, .bottom => @floatToInt(
                    .left, .right, .monocle => @as(u31, @truncate(ev.usable_height)) -| (2 *| cfg.outer_gaps),
                    .top, .bottom => @as(
                        u31,
                        @intToFloat(f64, ev.usable_width) * output.cfg.width_ratio,
                        @intFromFloat(@as(f64, @floatFromInt(ev.usable_width)) * output.cfg.width_ratio),
                    ) -| (2 *| cfg.outer_gaps),
                };



@@ 285,7 282,7 @@ const Output = struct {
                    sec_h = usable_h;
                } else {
                    if (sec_count > 0) {
                        main_w = @floatToInt(u31, output.cfg.main_ratio * @intToFloat(f64, usable_w));
                        main_w = @as(u31, @intFromFloat(output.cfg.main_ratio * @as(f64, @floatFromInt(usable_w))));
                        main_h = usable_h / main_count;
                        main_h_rem = usable_h % main_count;



@@ 486,9 483,9 @@ fn registry_listener(registry: *wl.Registry, event: wl.Registry.Event, context: 
fn registry_event(context: *Context, registry: *wl.Registry, event: wl.Registry.Event) !void {
    switch (event) {
        .global => |ev| {
            if (std.cstr.cmp(ev.interface, river.LayoutManagerV3.getInterface().name) == 0) {
            if (mem.orderZ(u8, ev.interface, river.LayoutManagerV3.getInterface().name) == .eq) {
                context.layout_manager = try registry.bind(ev.name, river.LayoutManagerV3, 2);
            } else if (std.cstr.cmp(ev.interface, wl.Output.getInterface().name) == 0) {
            } else if (mem.orderZ(u8, ev.interface, wl.Output.getInterface().name) == .eq) {
                const wl_output = try registry.bind(ev.name, wl.Output, 4);
                errdefer wl_output.release();