build: update to Zig 0.11.0

This commit is contained in:
Isaac Freund 2023-10-16 16:18:36 +02:00
parent 7f30c655c7
commit 2e586c7061
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
54 changed files with 333 additions and 363 deletions

View File

@ -39,11 +39,11 @@ tasks:
sudo ninja -C build/ install sudo ninja -C build/ install
cd .. cd ..
wget -nv https://ziglang.org/download/0.10.0/zig-linux-x86_64-0.10.0.tar.xz wget -nv https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz
# Remove a lot of useless lines from tar output. # Remove a lot of useless lines from tar output.
tar -xvf zig-linux-x86_64-0.10.0.tar.xz 1>/dev/null tar -xvf zig-linux-x86_64-0.11.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.11.0/zig /usr/bin/
sudo mv zig-linux-x86_64-0.10.0/lib /usr/lib/zig sudo mv zig-linux-x86_64-0.11.0/lib /usr/lib/zig
- build: | - build: |
cd river cd river
zig build zig build

View File

@ -37,11 +37,11 @@ tasks:
sudo ninja -C build/ install sudo ninja -C build/ install
cd .. cd ..
wget -nv https://ziglang.org/download/0.10.0/zig-linux-x86_64-0.10.0.tar.xz wget -nv https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz
# Remove a lot of useless lines from tar output. # Remove a lot of useless lines from tar output.
tar -xvf zig-linux-x86_64-0.10.0.tar.xz 1>/dev/null tar -xvf zig-linux-x86_64-0.11.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.11.0/zig /usr/bin/
sudo mv zig-linux-x86_64-0.10.0/lib /usr/lib/zig sudo mv zig-linux-x86_64-0.11.0/lib /usr/lib/zig
- build: | - build: |
cd river cd river
zig build zig build

View File

@ -41,11 +41,11 @@ tasks:
sudo ninja -C build/ install sudo ninja -C build/ install
cd .. cd ..
wget -nv https://ziglang.org/download/0.10.0/zig-freebsd-x86_64-0.10.0.tar.xz wget -nv https://ziglang.org/download/0.11.0/zig-freebsd-x86_64-0.11.0.tar.xz
# Remove a lot of useless lines from tar output. # Remove a lot of useless lines from tar output.
tar -xvf zig-freebsd-x86_64-0.10.0.tar.xz 1>/dev/null tar -xvf zig-freebsd-x86_64-0.11.0.tar.xz 1>/dev/null
sudo mv zig-freebsd-x86_64-0.10.0/zig /usr/bin/ sudo mv zig-freebsd-x86_64-0.11.0/zig /usr/bin/
sudo mv zig-freebsd-x86_64-0.10.0/lib /usr/lib/zig sudo mv zig-freebsd-x86_64-0.11.0/lib /usr/lib/zig
- build: | - build: |
cd river cd river
zig build zig build

1
.gitignore vendored
View File

@ -1,3 +1,2 @@
zig-cache/ zig-cache/
zig-out/ zig-out/
doc/*.[1-9]

View File

@ -35,7 +35,7 @@ To compile river first ensure that you have the following dependencies
installed. The "development" versions are required if applicable to your installed. The "development" versions are required if applicable to your
distribution. distribution.
- [zig](https://ziglang.org/download/) 0.10 - [zig](https://ziglang.org/download/) 0.11
- wayland - wayland
- wayland-protocols - wayland-protocols
- [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.16 - [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.16
@ -47,7 +47,7 @@ distribution.
Then run, for example: Then run, for example:
``` ```
zig build -Drelease-safe --prefix ~/.local install zig build -Doptimize=ReleaseSafe --prefix ~/.local install
``` ```
To enable experimental Xwayland support pass the `-Dxwayland` option as well. To enable experimental Xwayland support pass the `-Dxwayland` option as well.

230
build.zig
View File

@ -1,10 +1,10 @@
const std = @import("std"); const std = @import("std");
const assert = std.debug.assert; const assert = std.debug.assert;
const Build = std.Build;
const fs = std.fs; const fs = std.fs;
const mem = std.mem; const mem = std.mem;
const zbs = std.build;
const ScanProtocolsStep = @import("deps/zig-wayland/build.zig").ScanProtocolsStep; const Scanner = @import("deps/zig-wayland/build.zig").Scanner;
/// While a river release is in development, this string should contain the version in development /// While a river release is in development, this string should contain the version in development
/// with the "-dev" suffix. /// with the "-dev" suffix.
@ -12,9 +12,9 @@ const ScanProtocolsStep = @import("deps/zig-wayland/build.zig").ScanProtocolsSte
/// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added. /// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added.
const version = "0.3.0-dev"; const version = "0.3.0-dev";
pub fn build(b: *zbs.Builder) !void { pub fn build(b: *Build) !void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions(); const optimize = b.standardOptimizeOption(.{});
const strip = b.option(bool, "strip", "Omit debug information") orelse false; const strip = b.option(bool, "strip", "Omit debug information") orelse false;
const pie = b.option(bool, "pie", "Build a Position Independent Executable") orelse false; const pie = b.option(bool, "pie", "Build a Position Independent Executable") orelse false;
@ -24,7 +24,7 @@ pub fn build(b: *zbs.Builder) !void {
"man-pages", "man-pages",
"Set to true to build man pages. Requires scdoc. Defaults to true if scdoc is found.", "Set to true to build man pages. Requires scdoc. Defaults to true if scdoc is found.",
) orelse scdoc_found: { ) orelse scdoc_found: {
_ = b.findProgram(&[_][]const u8{"scdoc"}, &[_][]const u8{}) catch |err| switch (err) { _ = b.findProgram(&.{"scdoc"}, &.{}) catch |err| switch (err) {
error.FileNotFound => break :scdoc_found false, error.FileNotFound => break :scdoc_found false,
else => return err, else => return err,
}; };
@ -60,12 +60,12 @@ pub fn build(b: *zbs.Builder) !void {
var ret: u8 = undefined; var ret: u8 = undefined;
const git_describe_long = b.execAllowFail( const git_describe_long = b.execAllowFail(
&[_][]const u8{ "git", "-C", b.build_root, "describe", "--long" }, &.{ "git", "-C", b.build_root.path orelse ".", "describe", "--long" },
&ret, &ret,
.Inherit, .Inherit,
) catch break :blk version; ) 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 _ = it.next().?; // previous tag
const commit_count = it.next().?; const commit_count = it.next().?;
const commit_hash = it.next().?; const commit_hash = it.next().?;
@ -73,10 +73,7 @@ pub fn build(b: *zbs.Builder) !void {
assert(commit_hash[0] == 'g'); assert(commit_hash[0] == 'g');
// Follow semantic versioning, e.g. 0.2.0-dev.42+d1cf95b // Follow semantic versioning, e.g. 0.2.0-dev.42+d1cf95b
break :blk try std.fmt.allocPrintZ(b.allocator, version ++ ".{s}+{s}", .{ break :blk b.fmt(version ++ ".{s}+{s}", .{ commit_count, commit_hash[1..] });
commit_count,
commit_hash[1..],
});
} else { } else {
break :blk version; break :blk version;
} }
@ -86,17 +83,19 @@ pub fn build(b: *zbs.Builder) !void {
options.addOption(bool, "xwayland", xwayland); options.addOption(bool, "xwayland", xwayland);
options.addOption([]const u8, "version", full_version); options.addOption([]const u8, "version", full_version);
const scanner = ScanProtocolsStep.create(b); const scanner = Scanner.create(b, .{});
scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml"); scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml"); scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml");
scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.xml"); scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.xml");
scanner.addSystemProtocol("unstable/pointer-constraints/pointer-constraints-unstable-v1.xml"); scanner.addSystemProtocol("unstable/pointer-constraints/pointer-constraints-unstable-v1.xml");
scanner.addSystemProtocol("unstable/xdg-decoration/xdg-decoration-unstable-v1.xml"); scanner.addSystemProtocol("unstable/xdg-decoration/xdg-decoration-unstable-v1.xml");
scanner.addProtocolPath("protocol/river-control-unstable-v1.xml");
scanner.addProtocolPath("protocol/river-status-unstable-v1.xml"); scanner.addCustomProtocol("protocol/river-control-unstable-v1.xml");
scanner.addProtocolPath("protocol/river-layout-v3.xml"); scanner.addCustomProtocol("protocol/river-status-unstable-v1.xml");
scanner.addProtocolPath("protocol/wlr-layer-shell-unstable-v1.xml"); scanner.addCustomProtocol("protocol/river-layout-v3.xml");
scanner.addProtocolPath("protocol/wlr-output-power-management-unstable-v1.xml"); scanner.addCustomProtocol("protocol/wlr-layer-shell-unstable-v1.xml");
scanner.addCustomProtocol("protocol/wlr-output-power-management-unstable-v1.xml");
// These must be manually kept in sync with the versions wlroots supports // These must be manually kept in sync with the versions wlroots supports
// until wlroots gives the option to request a specific version. // until wlroots gives the option to request a specific version.
@ -120,72 +119,77 @@ pub fn build(b: *zbs.Builder) !void {
scanner.generate("zwlr_layer_shell_v1", 4); scanner.generate("zwlr_layer_shell_v1", 4);
scanner.generate("zwlr_output_power_manager_v1", 1); scanner.generate("zwlr_output_power_manager_v1", 1);
const wayland = b.createModule(.{ .source_file = scanner.result });
const xkbcommon = b.createModule(.{
.source_file = .{ .path = "deps/zig-xkbcommon/src/xkbcommon.zig" },
});
const pixman = b.createModule(.{
.source_file = .{ .path = "deps/zig-pixman/pixman.zig" },
});
const wlroots = b.createModule(.{
.source_file = .{ .path = "deps/zig-wlroots/src/wlroots.zig" },
.dependencies = &.{
.{ .name = "wayland", .module = wayland },
.{ .name = "xkbcommon", .module = xkbcommon },
.{ .name = "pixman", .module = pixman },
},
});
const flags = b.createModule(.{ .source_file = .{ .path = "common/flags.zig" } });
const globber = b.createModule(.{ .source_file = .{ .path = "common/globber.zig" } });
{ {
const river = b.addExecutable("river", "river/main.zig"); const river = b.addExecutable(.{
river.setTarget(target); .name = "river",
river.setBuildMode(mode); .root_source_file = .{ .path = "river/main.zig" },
.target = target,
.optimize = optimize,
});
river.addOptions("build_options", options); river.addOptions("build_options", options);
const wayland = zbs.Pkg{
.name = "wayland",
.source = .{ .generated = &scanner.result },
};
const xkbcommon = zbs.Pkg{
.name = "xkbcommon",
.source = .{ .path = "deps/zig-xkbcommon/src/xkbcommon.zig" },
};
const pixman = zbs.Pkg{
.name = "pixman",
.source = .{ .path = "deps/zig-pixman/pixman.zig" },
};
const wlroots = zbs.Pkg{
.name = "wlroots",
.source = .{ .path = "deps/zig-wlroots/src/wlroots.zig" },
.dependencies = &[_]zbs.Pkg{ wayland, xkbcommon, pixman },
};
river.step.dependOn(&scanner.step);
river.linkLibC(); river.linkLibC();
river.linkSystemLibrary("libevdev"); river.linkSystemLibrary("libevdev");
river.linkSystemLibrary("libinput"); river.linkSystemLibrary("libinput");
river.addPackage(wayland); river.addModule("wayland", wayland);
river.linkSystemLibrary("wayland-server"); river.linkSystemLibrary("wayland-server");
river.addPackage(xkbcommon); river.addModule("xkbcommon", xkbcommon);
river.linkSystemLibrary("xkbcommon"); river.linkSystemLibrary("xkbcommon");
river.addPackage(pixman); river.addModule("pixman", pixman);
river.linkSystemLibrary("pixman-1"); river.linkSystemLibrary("pixman-1");
river.addPackage(wlroots); river.addModule("wlroots", wlroots);
river.linkSystemLibrary("wlroots"); river.linkSystemLibrary("wlroots");
river.addPackagePath("flags", "common/flags.zig"); river.addModule("flags", flags);
river.addPackagePath("globber", "common/globber.zig"); river.addModule("globber", globber);
river.addCSourceFile("river/wlroots_log_wrapper.c", &[_][]const u8{ "-std=c99", "-O2" }); river.addCSourceFile(.{
.file = .{ .path = "river/wlroots_log_wrapper.c" },
.flags = &.{ "-std=c99", "-O2" },
});
// TODO: remove when zig issue #131 is implemented // TODO: remove when zig issue #131 is implemented
scanner.addCSource(river); scanner.addCSource(river);
river.strip = strip; river.strip = strip;
river.pie = pie; river.pie = pie;
river.install();
b.installArtifact(river);
} }
{ {
const riverctl = b.addExecutable("riverctl", "riverctl/main.zig"); const riverctl = b.addExecutable(.{
riverctl.setTarget(target); .name = "riverctl",
riverctl.setBuildMode(mode); .root_source_file = .{ .path = "riverctl/main.zig" },
.target = target,
.optimize = optimize,
});
riverctl.addOptions("build_options", options); riverctl.addOptions("build_options", options);
riverctl.step.dependOn(&scanner.step); riverctl.addModule("flags", flags);
riverctl.addPackagePath("flags", "common/flags.zig"); riverctl.addModule("wayland", wayland);
riverctl.addPackage(.{
.name = "wayland",
.source = .{ .generated = &scanner.result },
});
riverctl.linkLibC(); riverctl.linkLibC();
riverctl.linkSystemLibrary("wayland-client"); riverctl.linkSystemLibrary("wayland-client");
@ -193,21 +197,21 @@ pub fn build(b: *zbs.Builder) !void {
riverctl.strip = strip; riverctl.strip = strip;
riverctl.pie = pie; riverctl.pie = pie;
riverctl.install();
b.installArtifact(riverctl);
} }
{ {
const rivertile = b.addExecutable("rivertile", "rivertile/main.zig"); const rivertile = b.addExecutable(.{
rivertile.setTarget(target); .name = "rivertile",
rivertile.setBuildMode(mode); .root_source_file = .{ .path = "rivertile/main.zig" },
.target = target,
.optimize = optimize,
});
rivertile.addOptions("build_options", options); rivertile.addOptions("build_options", options);
rivertile.step.dependOn(&scanner.step); rivertile.addModule("flags", flags);
rivertile.addPackagePath("flags", "common/flags.zig"); rivertile.addModule("wayland", wayland);
rivertile.addPackage(.{
.name = "wayland",
.source = .{ .generated = &scanner.result },
});
rivertile.linkLibC(); rivertile.linkLibC();
rivertile.linkSystemLibrary("wayland-client"); rivertile.linkSystemLibrary("wayland-client");
@ -215,15 +219,13 @@ pub fn build(b: *zbs.Builder) !void {
rivertile.strip = strip; rivertile.strip = strip;
rivertile.pie = pie; rivertile.pie = pie;
rivertile.install();
b.installArtifact(rivertile);
} }
{ {
const file = try fs.path.join(b.allocator, &[_][]const u8{ b.cache_root, "river-protocols.pc" }); const wf = Build.Step.WriteFile.create(b);
const pkgconfig_file = try fs.cwd().createFile(file, .{}); const pc_file = wf.add("river-protocols.pc", b.fmt(
const writer = pkgconfig_file.writer();
try writer.print(
\\prefix={s} \\prefix={s}
\\datadir=${{prefix}}/share \\datadir=${{prefix}}/share
\\pkgdatadir=${{datadir}}/river-protocols \\pkgdatadir=${{datadir}}/river-protocols
@ -232,16 +234,23 @@ pub fn build(b: *zbs.Builder) !void {
\\URL: https://github.com/riverwm/river \\URL: https://github.com/riverwm/river
\\Description: protocol files for the river wayland compositor \\Description: protocol files for the river wayland compositor
\\Version: {s} \\Version: {s}
, .{ b.install_prefix, full_version }); , .{ b.install_prefix, full_version }));
defer pkgconfig_file.close();
b.installFile("protocol/river-layout-v3.xml", "share/river-protocols/river-layout-v3.xml"); b.installFile("protocol/river-layout-v3.xml", "share/river-protocols/river-layout-v3.xml");
b.installFile(file, "share/pkgconfig/river-protocols.pc"); b.getInstallStep().dependOn(&b.addInstallFile(pc_file, "share/pkgconfig/river-protocols.pc").step);
} }
if (man_pages) { if (man_pages) {
const scdoc_step = ScdocStep.create(b); inline for (.{ "river", "riverctl", "rivertile" }) |page| {
try scdoc_step.install(); // Workaround for https://github.com/ziglang/zig/issues/16369
// Even passing a buffer to std.Build.Step.Run appears to be racy and occasionally deadlocks.
const scdoc = b.addSystemCommand(&.{ "/bin/sh", "-c", "scdoc < doc/" ++ page ++ ".1.scd" });
// This makes the caching work for the Workaround, and the extra argument is ignored by /bin/sh.
scdoc.addFileArg(.{ .path = "doc/" ++ page ++ ".1.scd" });
const stdout = scdoc.captureStdOut();
b.getInstallStep().dependOn(&b.addInstallFile(stdout, "share/man/man1/" ++ page ++ ".1").step);
}
} }
if (bash_completion) { if (bash_completion) {
@ -257,65 +266,14 @@ pub fn build(b: *zbs.Builder) !void {
} }
{ {
const globber_test = b.addTest("common/globber.zig"); const globber_test = b.addTest(.{
globber_test.setTarget(target); .root_source_file = .{ .path = "common/globber.zig" },
globber_test.setBuildMode(mode); .target = target,
.optimize = optimize,
});
const run_globber_test = b.addRunArtifact(globber_test);
const test_step = b.step("test", "Run the tests"); const test_step = b.step("test", "Run the tests");
test_step.dependOn(&globber_test.step); test_step.dependOn(&run_globber_test.step);
} }
} }
const ScdocStep = struct {
const scd_paths = [_][]const u8{
"doc/river.1.scd",
"doc/riverctl.1.scd",
"doc/rivertile.1.scd",
};
builder: *zbs.Builder,
step: zbs.Step,
fn create(builder: *zbs.Builder) *ScdocStep {
const self = builder.allocator.create(ScdocStep) catch @panic("out of memory");
self.* = init(builder);
return self;
}
fn init(builder: *zbs.Builder) ScdocStep {
return ScdocStep{
.builder = builder,
.step = zbs.Step.init(.custom, "Generate man pages", builder.allocator, make),
};
}
fn make(step: *zbs.Step) !void {
const self = @fieldParentPtr(ScdocStep, "step", step);
for (scd_paths) |path| {
const command = try std.fmt.allocPrint(
self.builder.allocator,
"scdoc < {s} > {s}",
.{ path, path[0..(path.len - 4)] },
);
_ = try self.builder.exec(&[_][]const u8{ "sh", "-c", command });
}
}
fn install(self: *ScdocStep) !void {
self.builder.getInstallStep().dependOn(&self.step);
for (scd_paths) |path| {
const path_no_ext = path[0..(path.len - 4)];
const basename_no_ext = fs.path.basename(path_no_ext);
const section = path_no_ext[(path_no_ext.len - 1)..];
const output = try std.fmt.allocPrint(
self.builder.allocator,
"share/man/man{s}/{s}",
.{ section, basename_no_ext },
);
self.builder.installFile(path_no_ext, output);
}
}
};

View File

@ -41,14 +41,14 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type {
const field: std.builtin.Type.StructField = switch (flag.kind) { const field: std.builtin.Type.StructField = switch (flag.kind) {
.boolean => .{ .boolean => .{
.name = flag.name, .name = flag.name,
.field_type = bool, .type = bool,
.default_value = &false, .default_value = &false,
.is_comptime = false, .is_comptime = false,
.alignment = @alignOf(bool), .alignment = @alignOf(bool),
}, },
.arg => .{ .arg => .{
.name = flag.name, .name = flag.name,
.field_type = ?[:0]const u8, .type = ?[:0]const u8,
.default_value = &@as(?[:0]const u8, null), .default_value = &@as(?[:0]const u8, null),
.is_comptime = false, .is_comptime = false,
.alignment = @alignOf(?[:0]const u8), .alignment = @alignOf(?[:0]const u8),
@ -70,8 +70,13 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type {
var i: usize = 0; var i: usize = 0;
outer: while (i < args.len) : (i += 1) { 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| { inline for (flags) |flag| {
if (mem.eql(u8, "-" ++ flag.name, mem.span(args[i]))) { if (mem.eql(u8, "-" ++ flag.name, arg)) {
switch (flag.kind) { switch (flag.kind) {
.boolean => @field(result_flags, flag.name) = true, .boolean => @field(result_flags, flag.name) = true,
.arg => { .arg => {
@ -81,7 +86,11 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type {
"' requires an argument but none was provided!", .{}); "' requires an argument but none was provided!", .{});
return error.MissingFlagArgument; 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; continue :outer;

View File

@ -34,19 +34,19 @@ pub fn validate(glob: []const u8) error{InvalidGlob}!void {
test validate { test validate {
const testing = std.testing; const testing = std.testing;
_ = try validate("*"); try validate("*");
_ = try validate("a"); try validate("a");
_ = try validate("*a"); try validate("*a");
_ = try validate("a*"); try validate("a*");
_ = try validate("*a*"); try validate("*a*");
_ = try validate("ab"); try validate("ab");
_ = try validate("*ab"); try validate("*ab");
_ = try validate("ab*"); try validate("ab*");
_ = try validate("*ab*"); try validate("*ab*");
_ = try validate("abc"); try validate("abc");
_ = try validate("*abc"); try validate("*abc");
_ = try validate("abc*"); try validate("abc*");
_ = try validate("*abc*"); try validate("*abc*");
try testing.expectError(error.InvalidGlob, validate("")); try testing.expectError(error.InvalidGlob, validate(""));
try testing.expectError(error.InvalidGlob, validate("**")); try testing.expectError(error.InvalidGlob, validate("**"));
@ -165,8 +165,8 @@ pub fn order(a: []const u8, b: []const u8) std.math.Order {
return .lt; return .lt;
} }
const count_a = @as(u2, @boolToInt(a[0] == '*')) + @boolToInt(a[a.len - 1] == '*'); const count_a = @as(u2, @intFromBool(a[0] == '*')) + @intFromBool(a[a.len - 1] == '*');
const count_b = @as(u2, @boolToInt(b[0] == '*')) + @boolToInt(b[b.len - 1] == '*'); const count_b = @as(u2, @intFromBool(b[0] == '*')) + @intFromBool(b[b.len - 1] == '*');
if (count_a == 0 and count_b == 0) { if (count_a == 0 and count_b == 0) {
return .eq; return .eq;
@ -206,7 +206,7 @@ test order {
"a", "a",
}; };
for (descending) |a, i| { for (descending, 0..) |a, i| {
for (descending[i..]) |b| { for (descending[i..]) |b| {
try testing.expect(order(a, b) != .lt); try testing.expect(order(a, b) != .lt);
} }
@ -215,7 +215,7 @@ test order {
var ascending = descending; var ascending = descending;
mem.reverse([]const u8, &ascending); mem.reverse([]const u8, &ascending);
for (ascending) |a, i| { for (ascending, 0..) |a, i| {
for (ascending[i..]) |b| { for (ascending[i..]) |b| {
try testing.expect(order(a, b) != .gt); try testing.expect(order(a, b) != .gt);
} }

2
deps/zig-pixman vendored

@ -1 +1 @@
Subproject commit 4a49ba13eb9ebb0c0f991de924328e3d615bf283 Subproject commit b0a961079d80059ef56565e23c5f7a8b6a911196

2
deps/zig-wayland vendored

@ -1 +1 @@
Subproject commit e9484c814801b520cbe4ed719cceb4d0a59f1341 Subproject commit b9c6fcb8cab3a85c5583ef371055cb589b1e7b18

2
deps/zig-wlroots vendored

@ -1 +1 @@
Subproject commit c4cdb08505de19f6bfbf8e1825349b80c7696475 Subproject commit 021fb4bbae7ea3806344102763adb63bf194ca7c

2
deps/zig-xkbcommon vendored

@ -1 +1 @@
Subproject commit bfd1f97c277c32fddb77dee45979d2f472595d19 Subproject commit e93ceb0436c66a7e4c727fdb59020e889519e489

View File

@ -71,7 +71,7 @@ fn handleRequest(control: *zriver.ControlV1, request: zriver.ControlV1.Request,
switch (request) { switch (request) {
.destroy => control.destroy(), .destroy => control.destroy(),
.add_argument => |add_argument| { .add_argument => |add_argument| {
const owned_slice = util.gpa.dupeZ(u8, mem.span(add_argument.argument)) catch { const owned_slice = util.gpa.dupeZ(u8, mem.sliceTo(add_argument.argument, 0)) catch {
control.getClient().postNoMemory(); control.getClient().postNoMemory();
return; return;
}; };
@ -84,7 +84,7 @@ fn handleRequest(control: *zriver.ControlV1, request: zriver.ControlV1.Request,
}; };
}, },
.run_command => |run_command| { .run_command => |run_command| {
const seat = @intToPtr(*Seat, wlr.Seat.Client.fromWlSeat(run_command.seat).?.seat.data); const seat: *Seat = @ptrFromInt(wlr.Seat.Client.fromWlSeat(run_command.seat).?.seat.data);
const callback = zriver.CommandCallbackV1.create( const callback = zriver.CommandCallbackV1.create(
control.getClient(), control.getClient(),
@ -109,7 +109,7 @@ fn handleRequest(control: *zriver.ControlV1, request: zriver.ControlV1.Request,
callback.getClient().postNoMemory(); callback.getClient().postNoMemory();
return; return;
}, },
command.Error.Other => std.cstr.addNullByte(util.gpa, out.?) catch { command.Error.Other => util.gpa.dupeZ(u8, out.?) catch {
callback.getClient().postNoMemory(); callback.getClient().postNoMemory();
return; return;
}, },

View File

@ -287,8 +287,8 @@ pub fn setTheme(self: *Self, theme: ?[*:0]const u8, _size: ?u32) !void {
image.width * 4, image.width * 4,
image.width, image.width,
image.height, image.height,
@intCast(i32, image.hotspot_x), @intCast(image.hotspot_x),
@intCast(i32, image.hotspot_y), @intCast(image.hotspot_y),
); );
} }
@ -427,7 +427,7 @@ fn updateKeyboardFocus(self: Self, result: Root.AtResult) void {
/// Requires a call to Root.applyPending() /// Requires a call to Root.applyPending()
fn updateOutputFocus(self: Self, lx: f64, ly: f64) void { fn updateOutputFocus(self: Self, lx: f64, ly: f64) void {
if (server.root.output_layout.outputAt(lx, ly)) |wlr_output| { if (server.root.output_layout.outputAt(lx, ly)) |wlr_output| {
const output = @intToPtr(*Output, wlr_output.data); const output: *Output = @ptrFromInt(wlr_output.data);
self.seat.focusOutput(output); self.seat.focusOutput(output);
} }
} }
@ -712,8 +712,8 @@ pub fn startMove(cursor: *Self, view: *View) void {
const new_mode: Mode = .{ .move = .{ const new_mode: Mode = .{ .move = .{
.view = view, .view = view,
.offset_x = @floatToInt(i32, cursor.wlr_cursor.x) - view.current.box.x, .offset_x = @as(i32, @intFromFloat(cursor.wlr_cursor.x)) - view.current.box.x,
.offset_y = @floatToInt(i32, cursor.wlr_cursor.y) - view.current.box.y, .offset_y = @as(i32, @intFromFloat(cursor.wlr_cursor.y)) - view.current.box.y,
} }; } };
cursor.enterMode(new_mode, view, .move); cursor.enterMode(new_mode, view, .move);
} }
@ -733,8 +733,8 @@ pub fn startResize(cursor: *Self, view: *View, proposed_edges: ?wlr.Edges) void
}; };
const box = &view.current.box; const box = &view.current.box;
const lx = @floatToInt(i32, cursor.wlr_cursor.x); const lx: i32 = @intFromFloat(cursor.wlr_cursor.x);
const ly = @floatToInt(i32, cursor.wlr_cursor.y); const ly: i32 = @intFromFloat(cursor.wlr_cursor.y);
const offset_x = if (edges.left) lx - box.x else box.x + box.width - lx; const offset_x = if (edges.left) lx - box.x else box.x + box.width - lx;
const offset_y = if (edges.top) ly - box.y else box.y + box.height - ly; const offset_y = if (edges.top) ly - box.y else box.y + box.height - ly;
@ -756,13 +756,13 @@ fn computeEdges(cursor: *const Self, view: *const View) wlr.Edges {
var output_box: wlr.Box = undefined; var output_box: wlr.Box = undefined;
server.root.output_layout.getBox(view.current.output.?.wlr_output, &output_box); server.root.output_layout.getBox(view.current.output.?.wlr_output, &output_box);
const sx = @floatToInt(i32, cursor.wlr_cursor.x) - output_box.x - box.x; const sx = @as(i32, @intFromFloat(cursor.wlr_cursor.x)) - output_box.x - box.x;
const sy = @floatToInt(i32, cursor.wlr_cursor.y) - output_box.y - box.y; const sy = @as(i32, @intFromFloat(cursor.wlr_cursor.y)) - output_box.y - box.y;
var edges: wlr.Edges = .{}; var edges: wlr.Edges = .{};
if (box.width > min_handle_size * 2) { if (box.width > min_handle_size * 2) {
const handle = math.max(min_handle_size, @divFloor(box.width, 5)); const handle = @max(min_handle_size, @divFloor(box.width, 5));
if (sx < handle) { if (sx < handle) {
edges.left = true; edges.left = true;
} else if (sx > box.width - handle) { } else if (sx > box.width - handle) {
@ -771,7 +771,7 @@ fn computeEdges(cursor: *const Self, view: *const View) wlr.Edges {
} }
if (box.height > min_handle_size * 2) { if (box.height > min_handle_size * 2) {
const handle = math.max(min_handle_size, @divFloor(box.height, 5)); const handle = @max(min_handle_size, @divFloor(box.height, 5));
if (sy < handle) { if (sy < handle) {
edges.top = true; edges.top = true;
} else if (sy > box.height - handle) { } else if (sy > box.height - handle) {
@ -863,7 +863,7 @@ fn processMotion(self: *Self, device: *wlr.InputDevice, time: u32, delta_x: f64,
data.delta_y = dy - @trunc(dy); data.delta_y = dy - @trunc(dy);
if (tag == .move) { if (tag == .move) {
data.view.pending.move(@floatToInt(i32, dx), @floatToInt(i32, dy)); data.view.pending.move(@intFromFloat(dx), @intFromFloat(dy));
} else { } else {
// Modify width/height of the pending box, taking constraints into account // Modify width/height of the pending box, taking constraints into account
// The x/y coordinates of the view will be adjusted as needed in View.resizeCommit() // The x/y coordinates of the view will be adjusted as needed in View.resizeCommit()
@ -880,31 +880,31 @@ fn processMotion(self: *Self, device: *wlr.InputDevice, time: u32, delta_x: f64,
if (data.edges.left) { if (data.edges.left) {
var x1 = box.x; var x1 = box.x;
const x2 = box.x + box.width; const x2 = box.x + box.width;
x1 += @floatToInt(i32, dx); x1 += @intFromFloat(dx);
x1 = math.max(x1, border_width); x1 = @max(x1, border_width);
x1 = math.max(x1, x2 - constraints.max_width); x1 = @max(x1, x2 - constraints.max_width);
x1 = math.min(x1, x2 - constraints.min_width); x1 = @min(x1, x2 - constraints.min_width);
box.width = x2 - x1; box.width = x2 - x1;
} else if (data.edges.right) { } else if (data.edges.right) {
box.width += @floatToInt(i32, dx); box.width += @intFromFloat(dx);
box.width = math.max(box.width, constraints.min_width); box.width = @max(box.width, constraints.min_width);
box.width = math.min(box.width, constraints.max_width); box.width = @min(box.width, constraints.max_width);
box.width = math.min(box.width, output_width - border_width - box.x); box.width = @min(box.width, output_width - border_width - box.x);
} }
if (data.edges.top) { if (data.edges.top) {
var y1 = box.y; var y1 = box.y;
const y2 = box.y + box.height; const y2 = box.y + box.height;
y1 += @floatToInt(i32, dy); y1 += @intFromFloat(dy);
y1 = math.max(y1, border_width); y1 = @max(y1, border_width);
y1 = math.max(y1, y2 - constraints.max_height); y1 = @max(y1, y2 - constraints.max_height);
y1 = math.min(y1, y2 - constraints.min_height); y1 = @min(y1, y2 - constraints.min_height);
box.height = y2 - y1; box.height = y2 - y1;
} else if (data.edges.bottom) { } else if (data.edges.bottom) {
box.height += @floatToInt(i32, dy); box.height += @intFromFloat(dy);
box.height = math.max(box.height, constraints.min_height); box.height = @max(box.height, constraints.min_height);
box.height = math.min(box.height, constraints.max_height); box.height = @min(box.height, constraints.max_height);
box.height = math.min(box.height, output_height - border_width - box.y); box.height = @min(box.height, output_height - border_width - box.y);
} }
} }
@ -943,8 +943,9 @@ fn updateFocusFollowsCursorTarget(self: *Self) void {
// in order to avoid clashes with cursor warping on focus change. // in order to avoid clashes with cursor warping on focus change.
var output_layout_box: wlr.Box = undefined; var output_layout_box: wlr.Box = undefined;
server.root.output_layout.getBox(view.current.output.?.wlr_output, &output_layout_box); server.root.output_layout.getBox(view.current.output.?.wlr_output, &output_layout_box);
const cursor_ox = self.wlr_cursor.x - @intToFloat(f64, output_layout_box.x);
const cursor_oy = self.wlr_cursor.y - @intToFloat(f64, output_layout_box.y); const cursor_ox = self.wlr_cursor.x - @as(f64, @floatFromInt(output_layout_box.x));
const cursor_oy = self.wlr_cursor.y - @as(f64, @floatFromInt(output_layout_box.y));
if (view.current.box.containsPoint(cursor_ox, cursor_oy)) { if (view.current.box.containsPoint(cursor_ox, cursor_oy)) {
self.focus_follows_cursor_target = view; self.focus_follows_cursor_target = view;
} }
@ -981,7 +982,7 @@ pub fn updateState(self: *Self) void {
if (!self.hidden) { if (!self.hidden) {
var now: os.timespec = undefined; var now: os.timespec = undefined;
os.clock_gettime(os.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported"); os.clock_gettime(os.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
const msec = @intCast(u32, now.tv_sec * std.time.ms_per_s + const msec: u32 = @intCast(now.tv_sec * std.time.ms_per_s +
@divTrunc(now.tv_nsec, std.time.ns_per_ms)); @divTrunc(now.tv_nsec, std.time.ns_per_ms));
self.passthrough(msec); self.passthrough(msec);
} }
@ -998,20 +999,20 @@ pub fn updateState(self: *Self) void {
// Keep the cursor locked to the original offset from the edges of the view. // Keep the cursor locked to the original offset from the edges of the view.
const box = &data.view.current.box; const box = &data.view.current.box;
const new_x = blk: { const new_x: f64 = blk: {
if (mode == .move or data.edges.left) { if (mode == .move or data.edges.left) {
break :blk @intToFloat(f64, data.offset_x + box.x); break :blk @floatFromInt(data.offset_x + box.x);
} else if (data.edges.right) { } else if (data.edges.right) {
break :blk @intToFloat(f64, box.x + box.width - data.offset_x); break :blk @floatFromInt(box.x + box.width - data.offset_x);
} else { } else {
break :blk self.wlr_cursor.x; break :blk self.wlr_cursor.x;
} }
}; };
const new_y = blk: { const new_y: f64 = blk: {
if (mode == .move or data.edges.top) { if (mode == .move or data.edges.top) {
break :blk @intToFloat(f64, data.offset_y + box.y); break :blk @floatFromInt(data.offset_y + box.y);
} else if (data.edges.bottom) { } else if (data.edges.bottom) {
break :blk @intToFloat(f64, box.y + box.height - data.offset_y); break :blk @floatFromInt(box.y + box.height - data.offset_y);
} else { } else {
break :blk self.wlr_cursor.y; break :blk self.wlr_cursor.y;
} }
@ -1083,8 +1084,8 @@ fn warp(self: *Self) void {
(usable_layout_box.containsPoint(self.wlr_cursor.x, self.wlr_cursor.y) and (usable_layout_box.containsPoint(self.wlr_cursor.x, self.wlr_cursor.y) and
!target_box.containsPoint(self.wlr_cursor.x, self.wlr_cursor.y))) !target_box.containsPoint(self.wlr_cursor.x, self.wlr_cursor.y)))
{ {
const lx = @intToFloat(f64, target_box.x + @divTrunc(target_box.width, 2)); const lx: f64 = @floatFromInt(target_box.x + @divTrunc(target_box.width, 2));
const ly = @intToFloat(f64, target_box.y + @divTrunc(target_box.height, 2)); const ly: f64 = @floatFromInt(target_box.y + @divTrunc(target_box.height, 2));
if (!self.wlr_cursor.warp(null, lx, ly)) { if (!self.wlr_cursor.warp(null, lx, ly)) {
log.err("failed to warp cursor on focus change", .{}); log.err("failed to warp cursor on focus change", .{});
} }
@ -1094,7 +1095,7 @@ fn warp(self: *Self) void {
fn updateDragIcons(self: *Self) void { fn updateDragIcons(self: *Self) void {
var it = server.root.drag_icons.children.iterator(.forward); var it = server.root.drag_icons.children.iterator(.forward);
while (it.next()) |node| { while (it.next()) |node| {
const icon = @intToPtr(*DragIcon, node.data); const icon = @as(*DragIcon, @ptrFromInt(node.data));
if (icon.wlr_drag_icon.drag.seat != self.seat.wlr_seat) continue; if (icon.wlr_drag_icon.drag.seat != self.seat.wlr_seat) continue;
@ -1102,16 +1103,16 @@ fn updateDragIcons(self: *Self) void {
.keyboard => unreachable, .keyboard => unreachable,
.keyboard_pointer => { .keyboard_pointer => {
icon.tree.node.setPosition( icon.tree.node.setPosition(
@floatToInt(c_int, self.wlr_cursor.x), @intFromFloat(self.wlr_cursor.x),
@floatToInt(c_int, self.wlr_cursor.y), @intFromFloat(self.wlr_cursor.y),
); );
}, },
.keyboard_touch => { .keyboard_touch => {
const touch_id = icon.wlr_drag_icon.drag.touch_id; const touch_id = icon.wlr_drag_icon.drag.touch_id;
const point = self.touch_points.get(touch_id) orelse continue; const point = self.touch_points.get(touch_id) orelse continue;
icon.tree.node.setPosition( icon.tree.node.setPosition(
@floatToInt(c_int, point.lx), @intFromFloat(point.lx),
@floatToInt(c_int, point.ly), @intFromFloat(point.ly),
); );
}, },
} }

View File

@ -47,7 +47,7 @@ pub fn create(wlr_drag_icon: *wlr.Drag.Icon) error{OutOfMemory}!void {
.tree = tree, .tree = tree,
.surface = try tree.createSceneSubsurfaceTree(wlr_drag_icon.surface), .surface = try tree.createSceneSubsurfaceTree(wlr_drag_icon.surface),
}; };
tree.node.data = @ptrToInt(drag_icon); tree.node.data = @intFromPtr(drag_icon);
tree.node.setEnabled(wlr_drag_icon.mapped); tree.node.setEnabled(wlr_drag_icon.mapped);

View File

@ -89,7 +89,7 @@ fn handleForeignActivate(
) void { ) void {
const handle = @fieldParentPtr(ForeignToplevelHandle, "foreign_activate", listener); const handle = @fieldParentPtr(ForeignToplevelHandle, "foreign_activate", listener);
const view = @fieldParentPtr(View, "foreign_toplevel_handle", handle); const view = @fieldParentPtr(View, "foreign_toplevel_handle", handle);
const seat = @intToPtr(*Seat, event.seat.data); const seat: *Seat = @ptrFromInt(event.seat.data);
seat.focus(view); seat.focus(view);
server.root.applyPending(); server.root.applyPending();

View File

@ -281,10 +281,7 @@ pub fn deinit(self: *Self) void {
} }
pub fn apply(self: *Self, device: *InputDevice) void { pub fn apply(self: *Self, device: *InputDevice) void {
const libinput_device = @ptrCast( const libinput_device: *c.libinput_device = @ptrCast(device.wlr_device.getLibinputDevice() orelse return);
*c.libinput_device,
device.wlr_device.getLibinputDevice() orelse return,
);
log.debug("applying input configuration to device: {s}", .{device.identifier}); log.debug("applying input configuration to device: {s}", .{device.identifier});
if (self.event_state) |setting| setting.apply(libinput_device); if (self.event_state) |setting| setting.apply(libinput_device);
if (self.accel_profile) |setting| setting.apply(libinput_device); if (self.accel_profile) |setting| setting.apply(libinput_device);

View File

@ -57,13 +57,13 @@ pub fn init(device: *InputDevice, seat: *Seat, wlr_device: *wlr.InputDevice) !vo
device_type, device_type,
wlr_device.vendor, wlr_device.vendor,
wlr_device.product, wlr_device.product,
mem.trim(u8, mem.span(wlr_device.name), &ascii.spaces), mem.trim(u8, mem.sliceTo(wlr_device.name, 0), &ascii.whitespace),
}, },
); );
errdefer util.gpa.free(identifier); errdefer util.gpa.free(identifier);
for (identifier) |*char| { for (identifier) |*char| {
if (!ascii.isGraph(char.*)) { if (!ascii.isPrint(char.*) or ascii.isWhitespace(char.*)) {
char.* = '_'; char.* = '_';
} }
} }

View File

@ -145,7 +145,7 @@ fn handleNewVirtualKeyboard(
_: *wl.Listener(*wlr.VirtualKeyboardV1), _: *wl.Listener(*wlr.VirtualKeyboardV1),
virtual_keyboard: *wlr.VirtualKeyboardV1, virtual_keyboard: *wlr.VirtualKeyboardV1,
) void { ) void {
const seat = @intToPtr(*Seat, virtual_keyboard.seat.data); const seat: *Seat = @ptrFromInt(virtual_keyboard.seat.data);
seat.addDevice(&virtual_keyboard.keyboard.base); seat.addDevice(&virtual_keyboard.keyboard.base);
} }

View File

@ -47,7 +47,7 @@ pub fn init(self: *Self, seat: *Seat, wlr_device: *wlr.InputDevice) !void {
errdefer self.device.deinit(); errdefer self.device.deinit();
const wlr_keyboard = self.device.wlr_device.toKeyboard(); const wlr_keyboard = self.device.wlr_device.toKeyboard();
wlr_keyboard.data = @ptrToInt(self); wlr_keyboard.data = @intFromPtr(self);
// wlroots will log a more detailed error if this fails. // wlroots will log a more detailed error if this fails.
if (!wlr_keyboard.setKeymap(server.config.keymap)) return error.OutOfMemory; if (!wlr_keyboard.setKeymap(server.config.keymap)) return error.OutOfMemory;
@ -127,7 +127,7 @@ fn handleKey(listener: *wl.Listener(*wlr.Keyboard.event.Key), event: *wlr.Keyboa
} }
fn isModifier(keysym: xkb.Keysym) bool { fn isModifier(keysym: xkb.Keysym) bool {
return @enumToInt(keysym) >= xkb.Keysym.Shift_L and @enumToInt(keysym) <= xkb.Keysym.Hyper_R; return @intFromEnum(keysym) >= xkb.Keysym.Shift_L and @intFromEnum(keysym) <= xkb.Keysym.Hyper_R;
} }
fn handleModifiers(listener: *wl.Listener(*wlr.Keyboard), _: *wlr.Keyboard) void { fn handleModifiers(listener: *wl.Listener(*wlr.Keyboard), _: *wlr.Keyboard) void {
@ -144,12 +144,12 @@ fn handleModifiers(listener: *wl.Listener(*wlr.Keyboard), _: *wlr.Keyboard) void
/// Handle any builtin, harcoded compsitor mappings such as VT switching. /// Handle any builtin, harcoded compsitor mappings such as VT switching.
/// Returns true if the keysym was handled. /// Returns true if the keysym was handled.
fn handleBuiltinMapping(keysym: xkb.Keysym) bool { fn handleBuiltinMapping(keysym: xkb.Keysym) bool {
switch (@enumToInt(keysym)) { switch (@intFromEnum(keysym)) {
xkb.Keysym.XF86Switch_VT_1...xkb.Keysym.XF86Switch_VT_12 => { xkb.Keysym.XF86Switch_VT_1...xkb.Keysym.XF86Switch_VT_12 => {
log.debug("switch VT keysym received", .{}); log.debug("switch VT keysym received", .{});
if (server.backend.isMulti()) { if (server.backend.isMulti()) {
if (server.backend.getSession()) |session| { if (server.backend.getSession()) |session| {
const vt = @enumToInt(keysym) - xkb.Keysym.XF86Switch_VT_1 + 1; const vt = @intFromEnum(keysym) - xkb.Keysym.XF86Switch_VT_1 + 1;
const log_server = std.log.scoped(.server); const log_server = std.log.scoped(.server);
log_server.info("switching to VT {}", .{vt}); log_server.info("switching to VT {}", .{vt});
session.changeVt(vt) catch log_server.err("changing VT failed", .{}); session.changeVt(vt) catch log_server.err("changing VT failed", .{});

View File

@ -28,8 +28,8 @@ len: usize = 0,
pub fn add(self: *Self, new: u32) void { pub fn add(self: *Self, new: u32) void {
for (self.items[0..self.len]) |item| if (new == item) return; for (self.items[0..self.len]) |item| if (new == item) return;
comptime assert(@typeInfo(std.meta.fieldInfo(Self, .items).field_type).Array.len == comptime assert(@typeInfo(std.meta.fieldInfo(Self, .items).type).Array.len ==
@typeInfo(std.meta.fieldInfo(wlr.Keyboard, .keycodes).field_type).Array.len); @typeInfo(std.meta.fieldInfo(wlr.Keyboard, .keycodes).type).Array.len);
if (self.len == self.items.len) { if (self.len == self.items.len) {
log.err("KeycodeSet limit reached, code {d} omitted", .{new}); log.err("KeycodeSet limit reached, code {d} omitted", .{new});
@ -41,7 +41,7 @@ pub fn add(self: *Self, new: u32) void {
} }
pub fn remove(self: *Self, old: u32) bool { pub fn remove(self: *Self, old: u32) bool {
for (self.items[0..self.len]) |item, idx| if (old == item) { for (self.items[0..self.len], 0..) |item, idx| if (old == item) {
self.len -= 1; self.len -= 1;
if (self.len > 0) self.items[idx] = self.items[self.len]; if (self.len > 0) self.items[idx] = self.items[self.len];

View File

@ -43,7 +43,7 @@ commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit)
new_popup: wl.Listener(*wlr.XdgPopup) = wl.Listener(*wlr.XdgPopup).init(handleNewPopup), new_popup: wl.Listener(*wlr.XdgPopup) = wl.Listener(*wlr.XdgPopup).init(handleNewPopup),
pub fn create(wlr_layer_surface: *wlr.LayerSurfaceV1) error{OutOfMemory}!void { pub fn create(wlr_layer_surface: *wlr.LayerSurfaceV1) error{OutOfMemory}!void {
const output = @intToPtr(*Output, wlr_layer_surface.output.?.data); const output: *Output = @ptrFromInt(wlr_layer_surface.output.?.data);
const layer_surface = try util.gpa.create(LayerSurface); const layer_surface = try util.gpa.create(LayerSurface);
errdefer util.gpa.destroy(layer_surface); errdefer util.gpa.destroy(layer_surface);
@ -55,12 +55,12 @@ pub fn create(wlr_layer_surface: *wlr.LayerSurfaceV1) error{OutOfMemory}!void {
.scene_layer_surface = try layer_tree.createSceneLayerSurfaceV1(wlr_layer_surface), .scene_layer_surface = try layer_tree.createSceneLayerSurfaceV1(wlr_layer_surface),
.popup_tree = try output.layers.popups.createSceneTree(), .popup_tree = try output.layers.popups.createSceneTree(),
}; };
wlr_layer_surface.data = @ptrToInt(layer_surface); wlr_layer_surface.data = @intFromPtr(layer_surface);
try SceneNodeData.attach(&layer_surface.scene_layer_surface.tree.node, .{ .layer_surface = layer_surface }); try SceneNodeData.attach(&layer_surface.scene_layer_surface.tree.node, .{ .layer_surface = layer_surface });
try SceneNodeData.attach(&layer_surface.popup_tree.node, .{ .layer_surface = layer_surface }); try SceneNodeData.attach(&layer_surface.popup_tree.node, .{ .layer_surface = layer_surface });
wlr_layer_surface.surface.data = @ptrToInt(&layer_surface.scene_layer_surface.tree.node); wlr_layer_surface.surface.data = @intFromPtr(&layer_surface.scene_layer_surface.tree.node);
wlr_layer_surface.events.destroy.add(&layer_surface.destroy); wlr_layer_surface.events.destroy.add(&layer_surface.destroy);
wlr_layer_surface.events.map.add(&layer_surface.map); wlr_layer_surface.events.map.add(&layer_surface.map);
@ -131,7 +131,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
// If a surface is committed while it is not mapped, we must send a configure. // If a surface is committed while it is not mapped, we must send a configure.
// TODO: this mapped check is not correct as it will be true in the commit // TODO: this mapped check is not correct as it will be true in the commit
// that triggers the unmap as well. // that triggers the unmap as well.
if (!wlr_layer_surface.mapped or @bitCast(u32, wlr_layer_surface.current.committed) != 0) { if (!wlr_layer_surface.mapped or @as(u32, @bitCast(wlr_layer_surface.current.committed)) != 0) {
layer_surface.output.arrangeLayers(); layer_surface.output.arrangeLayers();
handleKeyboardInteractiveExclusive(layer_surface.output); handleKeyboardInteractiveExclusive(layer_surface.output);
server.root.applyPending(); server.root.applyPending();
@ -150,7 +150,7 @@ fn handleKeyboardInteractiveExclusive(output: *Output) void {
var it = tree.children.iterator(.reverse); var it = tree.children.iterator(.reverse);
while (it.next()) |node| { while (it.next()) |node| {
assert(node.type == .tree); assert(node.type == .tree);
if (@intToPtr(?*SceneNodeData, node.data)) |node_data| { if (@as(?*SceneNodeData, @ptrFromInt(node.data))) |node_data| {
const layer_surface = node_data.data.layer_surface; const layer_surface = node_data.data.layer_surface;
const wlr_layer_surface = layer_surface.wlr_layer_surface; const wlr_layer_surface = layer_surface.wlr_layer_surface;
if (wlr_layer_surface.mapped and if (wlr_layer_surface.mapped and

View File

@ -109,8 +109,8 @@ pub fn startLayoutDemand(self: *Self, views: u32) void {
self.layout.sendLayoutDemand( self.layout.sendLayoutDemand(
views, views,
@intCast(u32, self.output.usable_box.width), @intCast(self.output.usable_box.width),
@intCast(u32, self.output.usable_box.height), @intCast(self.output.usable_box.height),
self.output.pending.tags, self.output.pending.tags,
self.output.inflight.layout_demand.?.serial, self.output.inflight.layout_demand.?.serial,
); );
@ -138,8 +138,8 @@ fn handleRequest(layout: *river.LayoutV3, request: river.LayoutV3.Request, self:
layout_demand.pushViewDimensions( layout_demand.pushViewDimensions(
req.x, req.x,
req.y, req.y,
@intCast(u31, math.min(math.maxInt(u31), req.width)), @min(math.maxInt(u31), req.width),
@intCast(u31, math.min(math.maxInt(u31), req.height)), @min(math.maxInt(u31), req.height),
); );
} }
}, },

View File

@ -52,7 +52,7 @@ pub fn init(layout: *Layout, views: u32) !Self {
return Self{ return Self{
.serial = server.wl_server.nextSerial(), .serial = server.wl_server.nextSerial(),
.views = @intCast(i32, views), .views = @intCast(views),
.view_boxen = try util.gpa.alloc(wlr.Box, views), .view_boxen = try util.gpa.alloc(wlr.Box, views),
.timeout_timer = timeout_timer, .timeout_timer = timeout_timer,
}; };
@ -86,7 +86,7 @@ pub fn pushViewDimensions(self: *Self, x: i32, y: i32, width: u31, height: u31)
return; return;
} }
self.view_boxen[self.view_boxen.len - @intCast(usize, self.views)] = .{ self.view_boxen[self.view_boxen.len - @as(usize, @intCast(self.views))] = .{
.x = x, .x = x,
.y = y, .y = y,
.width = width, .width = width,
@ -114,7 +114,7 @@ pub fn apply(self: *Self, layout: *Layout) void {
if (self.views != 0) { if (self.views != 0) {
log.err( log.err(
"proposed dimension count ({}) does not match view count ({}), aborting layout demand", "proposed dimension count ({}) does not match view count ({}), aborting layout demand",
.{ -self.views + @intCast(i32, self.view_boxen.len), self.view_boxen.len }, .{ -self.views + @as(i32, @intCast(self.view_boxen.len)), self.view_boxen.len },
); );
layout.layout.postError( layout.layout.postError(
.count_mismatch, .count_mismatch,

View File

@ -68,7 +68,7 @@ fn handleRequest(
.get_layout => |req| { .get_layout => |req| {
// Ignore if the output is inert // Ignore if the output is inert
const wlr_output = wlr.Output.fromWlOutput(req.output) orelse return; const wlr_output = wlr.Output.fromWlOutput(req.output) orelse return;
const output = @intToPtr(*Output, wlr_output.data); const output: *Output = @ptrFromInt(wlr_output.data);
log.debug("bind layout '{s}' on output '{s}'", .{ req.namespace, output.wlr_output.name }); log.debug("bind layout '{s}' on output '{s}'", .{ req.namespace, output.wlr_output.name });
@ -77,7 +77,7 @@ fn handleRequest(
layout_manager.getVersion(), layout_manager.getVersion(),
req.id, req.id,
output, output,
mem.span(req.namespace), mem.sliceTo(req.namespace, 0),
) catch { ) catch {
layout_manager.getClient().postNoMemory(); layout_manager.getClient().postNoMemory();
log.err("out of memory", .{}); log.err("out of memory", .{});

View File

@ -43,7 +43,7 @@ pub fn create(wlr_lock_surface: *wlr.SessionLockSurfaceV1, lock: *wlr.SessionLoc
.wlr_lock_surface = wlr_lock_surface, .wlr_lock_surface = wlr_lock_surface,
.lock = lock, .lock = lock,
}; };
wlr_lock_surface.data = @ptrToInt(lock_surface); wlr_lock_surface.data = @intFromPtr(lock_surface);
const output = lock_surface.getOutput(); const output = lock_surface.getOutput();
const tree = try output.locked_content.createSceneSubsurfaceTree(wlr_lock_surface.surface); const tree = try output.locked_content.createSceneSubsurfaceTree(wlr_lock_surface.surface);
@ -51,7 +51,7 @@ pub fn create(wlr_lock_surface: *wlr.SessionLockSurfaceV1, lock: *wlr.SessionLoc
try SceneNodeData.attach(&tree.node, .{ .lock_surface = lock_surface }); try SceneNodeData.attach(&tree.node, .{ .lock_surface = lock_surface });
wlr_lock_surface.surface.data = @ptrToInt(&tree.node); wlr_lock_surface.surface.data = @intFromPtr(&tree.node);
wlr_lock_surface.output.events.mode.add(&lock_surface.output_mode); wlr_lock_surface.output.events.mode.add(&lock_surface.output_mode);
wlr_lock_surface.events.map.add(&lock_surface.map); wlr_lock_surface.events.map.add(&lock_surface.map);
@ -65,7 +65,7 @@ pub fn destroy(lock_surface: *LockSurface) void {
var surface_it = lock_surface.lock.surfaces.iterator(.forward); var surface_it = lock_surface.lock.surfaces.iterator(.forward);
const new_focus: Seat.FocusTarget = while (surface_it.next()) |surface| { const new_focus: Seat.FocusTarget = while (surface_it.next()) |surface| {
if (surface != lock_surface.wlr_lock_surface) if (surface != lock_surface.wlr_lock_surface)
break .{ .lock_surface = @intToPtr(*LockSurface, surface.data) }; break .{ .lock_surface = @ptrFromInt(surface.data) };
} else .none; } else .none;
var seat_it = server.input_manager.seats.first; var seat_it = server.input_manager.seats.first;
@ -86,7 +86,7 @@ pub fn destroy(lock_surface: *LockSurface) void {
} }
fn getOutput(lock_surface: *LockSurface) *Output { fn getOutput(lock_surface: *LockSurface) *Output {
return @intToPtr(*Output, lock_surface.wlr_lock_surface.output.data); return @ptrFromInt(lock_surface.wlr_lock_surface.output.data);
} }
fn handleOutputMode(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void { fn handleOutputMode(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
@ -95,7 +95,7 @@ fn handleOutputMode(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
var output_width: i32 = undefined; var output_width: i32 = undefined;
var output_height: i32 = undefined; var output_height: i32 = undefined;
lock_surface.getOutput().wlr_output.effectiveResolution(&output_width, &output_height); lock_surface.getOutput().wlr_output.effectiveResolution(&output_width, &output_height);
_ = lock_surface.wlr_lock_surface.configure(@intCast(u32, output_width), @intCast(u32, output_height)); _ = lock_surface.wlr_lock_surface.configure(@intCast(output_width), @intCast(output_height));
} }
fn handleMap(listener: *wl.Listener(void)) void { fn handleMap(listener: *wl.Listener(void)) void {

View File

@ -45,7 +45,7 @@ pub fn init(
) !Self { ) !Self {
const owned_args = try util.gpa.alloc([:0]u8, command_args.len); const owned_args = try util.gpa.alloc([:0]u8, command_args.len);
errdefer util.gpa.free(owned_args); errdefer util.gpa.free(owned_args);
for (command_args) |arg, i| { for (command_args, 0..) |arg, i| {
errdefer for (owned_args[0..i]) |a| util.gpa.free(a); errdefer for (owned_args[0..i]) |a| util.gpa.free(a);
owned_args[i] = try util.gpa.dupeZ(u8, arg); owned_args[i] = try util.gpa.dupeZ(u8, arg);
} }

View File

@ -257,7 +257,7 @@ pub fn create(wlr_output: *wlr.Output) !void {
}, },
.status = undefined, .status = undefined,
}; };
wlr_output.data = @ptrToInt(output); wlr_output.data = @intFromPtr(output);
output.pending.focus_stack.init(); output.pending.focus_stack.init();
output.pending.wm_stack.init(); output.pending.wm_stack.init();
@ -299,7 +299,7 @@ pub fn layerSurfaceTree(self: Self, layer: zwlr.LayerShellV1.Layer) *wlr.SceneTr
self.layers.top, self.layers.top,
self.layers.overlay, self.layers.overlay,
}; };
return trees[@intCast(usize, @enumToInt(layer))]; return trees[@intCast(@intFromEnum(layer))];
} }
/// Arrange all layer surfaces of this output and adjust the usable area. /// Arrange all layer surfaces of this output and adjust the usable area.
@ -336,7 +336,7 @@ fn sendLayerConfigures(
var it = tree.children.iterator(.forward); var it = tree.children.iterator(.forward);
while (it.next()) |node| { while (it.next()) |node| {
assert(node.type == .tree); assert(node.type == .tree);
if (@intToPtr(?*SceneNodeData, node.data)) |node_data| { if (@as(?*SceneNodeData, @ptrFromInt(node.data))) |node_data| {
const layer_surface = node_data.data.layer_surface; const layer_surface = node_data.data.layer_surface;
const exclusive = layer_surface.wlr_layer_surface.current.exclusive_zone > 0; const exclusive = layer_surface.wlr_layer_surface.current.exclusive_zone > 0;

View File

@ -47,7 +47,7 @@ set_region: wl.Listener(void) = wl.Listener(void).init(handleSetRegion),
node_destroy: wl.Listener(void) = wl.Listener(void).init(handleNodeDestroy), node_destroy: wl.Listener(void) = wl.Listener(void).init(handleNodeDestroy),
pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void { pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void {
const seat = @intToPtr(*Seat, wlr_constraint.seat.data); const seat: *Seat = @ptrFromInt(wlr_constraint.seat.data);
const constraint = try util.gpa.create(PointerConstraint); const constraint = try util.gpa.create(PointerConstraint);
errdefer util.gpa.destroy(constraint); errdefer util.gpa.destroy(constraint);
@ -55,7 +55,7 @@ pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void
constraint.* = .{ constraint.* = .{
.wlr_constraint = wlr_constraint, .wlr_constraint = wlr_constraint,
}; };
wlr_constraint.data = @ptrToInt(constraint); wlr_constraint.data = @intFromPtr(constraint);
wlr_constraint.events.destroy.add(&constraint.destroy); wlr_constraint.events.destroy.add(&constraint.destroy);
wlr_constraint.events.set_region.add(&constraint.set_region); wlr_constraint.events.set_region.add(&constraint.set_region);
@ -70,7 +70,7 @@ pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void
} }
pub fn maybeActivate(constraint: *PointerConstraint) void { pub fn maybeActivate(constraint: *PointerConstraint) void {
const seat = @intToPtr(*Seat, constraint.wlr_constraint.seat.data); const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
assert(seat.cursor.constraint == constraint); assert(seat.cursor.constraint == constraint);
assert(seat.wlr_seat.keyboard_state.focused_surface == constraint.wlr_constraint.surface); assert(seat.wlr_seat.keyboard_state.focused_surface == constraint.wlr_constraint.surface);
@ -82,8 +82,8 @@ pub fn maybeActivate(constraint: *PointerConstraint) void {
const result = server.root.at(seat.cursor.wlr_cursor.x, seat.cursor.wlr_cursor.y) orelse return; const result = server.root.at(seat.cursor.wlr_cursor.x, seat.cursor.wlr_cursor.y) orelse return;
if (result.surface != constraint.wlr_constraint.surface) return; if (result.surface != constraint.wlr_constraint.surface) return;
const sx = @floatToInt(i32, result.sx); const sx: i32 = @intFromFloat(result.sx);
const sy = @floatToInt(i32, result.sy); const sy: i32 = @intFromFloat(result.sy);
if (!constraint.wlr_constraint.region.containsPoint(sx, sy, null)) return; if (!constraint.wlr_constraint.region.containsPoint(sx, sy, null)) return;
assert(constraint.state == .inactive); assert(constraint.state == .inactive);
@ -103,7 +103,7 @@ pub fn maybeActivate(constraint: *PointerConstraint) void {
/// Called when the cursor position or content in the scene graph changes /// Called when the cursor position or content in the scene graph changes
pub fn updateState(constraint: *PointerConstraint) void { pub fn updateState(constraint: *PointerConstraint) void {
const seat = @intToPtr(*Seat, constraint.wlr_constraint.seat.data); const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
assert(seat.wlr_seat.keyboard_state.focused_surface == constraint.wlr_constraint.surface); assert(seat.wlr_seat.keyboard_state.focused_surface == constraint.wlr_constraint.surface);
@ -119,8 +119,8 @@ pub fn updateState(constraint: *PointerConstraint) void {
return; return;
} }
const warp_lx = @intToFloat(f64, lx) + constraint.state.active.sx; const warp_lx = @as(f64, @floatFromInt(lx)) + constraint.state.active.sx;
const warp_ly = @intToFloat(f64, ly) + constraint.state.active.sy; const warp_ly = @as(f64, @floatFromInt(ly)) + constraint.state.active.sy;
if (!seat.cursor.wlr_cursor.warp(null, warp_lx, warp_ly)) { if (!seat.cursor.wlr_cursor.warp(null, warp_lx, warp_ly)) {
log.info("deactivating pointer constraint, could not warp cursor", .{}); log.info("deactivating pointer constraint, could not warp cursor", .{});
constraint.deactivate(); constraint.deactivate();
@ -147,7 +147,7 @@ pub fn confine(constraint: *PointerConstraint, dx: *f64, dy: *f64) void {
} }
pub fn deactivate(constraint: *PointerConstraint) void { pub fn deactivate(constraint: *PointerConstraint) void {
const seat = @intToPtr(*Seat, constraint.wlr_constraint.seat.data); const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
assert(seat.cursor.constraint == constraint); assert(seat.cursor.constraint == constraint);
assert(constraint.state == .active); assert(constraint.state == .active);
@ -160,7 +160,7 @@ pub fn deactivate(constraint: *PointerConstraint) void {
} }
fn warpToHintIfSet(constraint: *PointerConstraint) void { fn warpToHintIfSet(constraint: *PointerConstraint) void {
const seat = @intToPtr(*Seat, constraint.wlr_constraint.seat.data); const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
if (constraint.wlr_constraint.current.committed.cursor_hint) { if (constraint.wlr_constraint.current.committed.cursor_hint) {
var lx: i32 = undefined; var lx: i32 = undefined;
@ -169,7 +169,7 @@ fn warpToHintIfSet(constraint: *PointerConstraint) void {
const sx = constraint.wlr_constraint.current.cursor_hint.x; const sx = constraint.wlr_constraint.current.cursor_hint.x;
const sy = constraint.wlr_constraint.current.cursor_hint.y; const sy = constraint.wlr_constraint.current.cursor_hint.y;
_ = seat.cursor.wlr_cursor.warp(null, @intToFloat(f64, lx) + sx, @intToFloat(f64, ly) + sy); _ = seat.cursor.wlr_cursor.warp(null, @as(f64, @floatFromInt(lx)) + sx, @as(f64, @floatFromInt(ly)) + sy);
_ = seat.wlr_seat.pointerWarp(sx, sy); _ = seat.wlr_seat.pointerWarp(sx, sy);
} }
} }
@ -183,7 +183,7 @@ fn handleNodeDestroy(listener: *wl.Listener(void)) void {
fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.PointerConstraintV1) void { fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.PointerConstraintV1) void {
const constraint = @fieldParentPtr(PointerConstraint, "destroy", listener); const constraint = @fieldParentPtr(PointerConstraint, "destroy", listener);
const seat = @intToPtr(*Seat, constraint.wlr_constraint.seat.data); const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
if (constraint.state == .active) { if (constraint.state == .active) {
// We can't simply call deactivate() here as it calls sendDeactivated(), // We can't simply call deactivate() here as it calls sendDeactivated(),
@ -205,12 +205,12 @@ fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.Point
fn handleSetRegion(listener: *wl.Listener(void)) void { fn handleSetRegion(listener: *wl.Listener(void)) void {
const constraint = @fieldParentPtr(PointerConstraint, "set_region", listener); const constraint = @fieldParentPtr(PointerConstraint, "set_region", listener);
const seat = @intToPtr(*Seat, constraint.wlr_constraint.seat.data); const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
switch (constraint.state) { switch (constraint.state) {
.active => |state| { .active => |state| {
const sx = @floatToInt(i32, state.sx); const sx: i32 = @intFromFloat(state.sx);
const sy = @floatToInt(i32, state.sy); const sy: i32 = @intFromFloat(state.sy);
if (!constraint.wlr_constraint.region.containsPoint(sx, sy, null)) { if (!constraint.wlr_constraint.region.containsPoint(sx, sy, null)) {
log.info("deactivating pointer constraint, region change left pointer outside constraint", .{}); log.info("deactivating pointer constraint, region change left pointer outside constraint", .{});
constraint.deactivate(); constraint.deactivate();

View File

@ -52,7 +52,7 @@ pub fn init(
const arena_allocator = arena.allocator(); const arena_allocator = arena.allocator();
const owned_args = try arena_allocator.alloc([:0]const u8, command_args.len); const owned_args = try arena_allocator.alloc([:0]const u8, command_args.len);
for (command_args) |arg, i| { for (command_args, 0..) |arg, i| {
owned_args[i] = try arena_allocator.dupeZ(u8, arg); owned_args[i] = try arena_allocator.dupeZ(u8, arg);
} }

View File

@ -312,7 +312,7 @@ pub fn deactivateOutput(root: *Self, output: *Output) void {
var it = tree.children.safeIterator(.forward); var it = tree.children.safeIterator(.forward);
while (it.next()) |scene_node| { while (it.next()) |scene_node| {
assert(scene_node.type == .tree); assert(scene_node.type == .tree);
if (@intToPtr(?*SceneNodeData, scene_node.data)) |node_data| { if (@as(?*SceneNodeData, @ptrFromInt(scene_node.data))) |node_data| {
node_data.data.layer_surface.wlr_layer_surface.destroy(); node_data.data.layer_surface.wlr_layer_surface.destroy();
} }
} }
@ -751,7 +751,7 @@ fn processOutputConfig(
var it = config.heads.iterator(.forward); var it = config.heads.iterator(.forward);
while (it.next()) |head| { while (it.next()) |head| {
const wlr_output = head.state.output; const wlr_output = head.state.output;
const output = @intToPtr(*Output, wlr_output.data); const output: *Output = @ptrFromInt(wlr_output.data);
var proposed_state = wlr.Output.State.init(); var proposed_state = wlr.Output.State.init();
head.state.apply(&proposed_state); head.state.apply(&proposed_state);

View File

@ -45,7 +45,7 @@ pub fn attach(node: *wlr.SceneNode, data: Data) error{OutOfMemory}!void {
.node = node, .node = node,
.data = data, .data = data,
}; };
node.data = @ptrToInt(scene_node_data); node.data = @intFromPtr(scene_node_data);
node.events.destroy.add(&scene_node_data.destroy); node.events.destroy.add(&scene_node_data.destroy);
} }
@ -53,7 +53,7 @@ pub fn attach(node: *wlr.SceneNode, data: Data) error{OutOfMemory}!void {
pub fn fromNode(node: *wlr.SceneNode) ?*SceneNodeData { pub fn fromNode(node: *wlr.SceneNode) ?*SceneNodeData {
var it: ?*wlr.SceneNode = node; var it: ?*wlr.SceneNode = node;
while (it) |n| : (it = n.parent) { while (it) |n| : (it = n.parent) {
if (@intToPtr(?*SceneNodeData, n.data)) |scene_node_data| { if (@as(?*SceneNodeData, @ptrFromInt(n.data))) |scene_node_data| {
return scene_node_data; return scene_node_data;
} }
} }
@ -62,7 +62,7 @@ pub fn fromNode(node: *wlr.SceneNode) ?*SceneNodeData {
pub fn fromSurface(surface: *wlr.Surface) ?*SceneNodeData { pub fn fromSurface(surface: *wlr.Surface) ?*SceneNodeData {
if (surface.getRootSurface()) |root_surface| { if (surface.getRootSurface()) |root_surface| {
if (@intToPtr(?*wlr.SceneNode, root_surface.data)) |node| { if (@as(?*wlr.SceneNode, @ptrFromInt(root_surface.data))) |node| {
return fromNode(node); return fromNode(node);
} }
} }

View File

@ -107,7 +107,7 @@ pub fn init(self: *Self, name: [*:0]const u8) !void {
.wlr_seat = try wlr.Seat.create(server.wl_server, name), .wlr_seat = try wlr.Seat.create(server.wl_server, name),
.mapping_repeat_timer = mapping_repeat_timer, .mapping_repeat_timer = mapping_repeat_timer,
}; };
self.wlr_seat.data = @ptrToInt(self); self.wlr_seat.data = @intFromPtr(self);
try self.cursor.init(self); try self.cursor.init(self);
@ -267,7 +267,8 @@ pub fn setFocusRaw(self: *Self, new_focus: FocusTarget) void {
if (self.cursor.constraint) |constraint| { if (self.cursor.constraint) |constraint| {
assert(constraint.wlr_constraint == wlr_constraint); assert(constraint.wlr_constraint == wlr_constraint);
} else { } else {
self.cursor.constraint = @intToPtr(*PointerConstraint, wlr_constraint.data); self.cursor.constraint = @ptrFromInt(wlr_constraint.data);
assert(self.cursor.constraint != null);
} }
} }
} }
@ -299,7 +300,7 @@ fn keyboardNotifyEnter(self: *Self, wlr_surface: *wlr.Surface) void {
.len = wlr_keyboard.num_keycodes, .len = wlr_keyboard.num_keycodes,
}; };
const keyboard = @intToPtr(*Keyboard, wlr_keyboard.data); const keyboard: *Keyboard = @ptrFromInt(wlr_keyboard.data);
keycodes.subtract(keyboard.eaten_keycodes); keycodes.subtract(keyboard.eaten_keycodes);
self.wlr_seat.keyboardNotifyEnter( self.wlr_seat.keyboardNotifyEnter(

View File

@ -214,7 +214,7 @@ fn handleNewToplevelDecoration(
_: *wl.Listener(*wlr.XdgToplevelDecorationV1), _: *wl.Listener(*wlr.XdgToplevelDecorationV1),
wlr_decoration: *wlr.XdgToplevelDecorationV1, wlr_decoration: *wlr.XdgToplevelDecorationV1,
) void { ) void {
const xdg_toplevel = @intToPtr(*XdgToplevel, wlr_decoration.surface.data); const xdg_toplevel: *XdgToplevel = @ptrFromInt(wlr_decoration.surface.data);
// TODO(wlroots): The next wlroots version will handle this for us // TODO(wlroots): The next wlroots version will handle this for us
if (xdg_toplevel.decoration != null) { if (xdg_toplevel.decoration != null) {
@ -236,7 +236,7 @@ fn handleNewLayerSurface(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_
.{ .{
wlr_layer_surface.namespace, wlr_layer_surface.namespace,
@tagName(wlr_layer_surface.current.layer), @tagName(wlr_layer_surface.current.layer),
@bitCast(u32, wlr_layer_surface.current.anchor), @as(u32, @bitCast(wlr_layer_surface.current.anchor)),
wlr_layer_surface.current.desired_width, wlr_layer_surface.current.desired_width,
wlr_layer_surface.current.desired_height, wlr_layer_surface.current.desired_height,
wlr_layer_surface.current.margin.top, wlr_layer_surface.current.margin.top,

View File

@ -69,7 +69,7 @@ fn handleRequest(
.get_river_output_status => |req| { .get_river_output_status => |req| {
// ignore if the output is inert // ignore if the output is inert
const wlr_output = wlr.Output.fromWlOutput(req.output) orelse return; const wlr_output = wlr.Output.fromWlOutput(req.output) orelse return;
const output = @intToPtr(*Output, wlr_output.data); const output: *Output = @ptrFromInt(wlr_output.data);
const resource = zriver.OutputStatusV1.create( const resource = zriver.OutputStatusV1.create(
status_manager.getClient(), status_manager.getClient(),
@ -86,7 +86,7 @@ fn handleRequest(
.get_river_seat_status => |req| { .get_river_seat_status => |req| {
// ignore if the seat is inert // ignore if the seat is inert
const wlr_seat = wlr.Seat.Client.fromWlSeat(req.seat) orelse return; const wlr_seat = wlr.Seat.Client.fromWlSeat(req.seat) orelse return;
const seat = @intToPtr(*Seat, wlr_seat.seat.data); const seat: *Seat = @ptrFromInt(wlr_seat.seat.data);
const node = util.gpa.create(std.SinglyLinkedList(SeatStatus).Node) catch { const node = util.gpa.create(std.SinglyLinkedList(SeatStatus).Node) catch {
status_manager.getClient().postNoMemory(); status_manager.getClient().postNoMemory();

View File

@ -30,7 +30,7 @@ pub fn init(
) !Self { ) !Self {
const owned_args = try util.gpa.alloc([:0]u8, command_args.len); const owned_args = try util.gpa.alloc([:0]u8, command_args.len);
errdefer util.gpa.free(owned_args); errdefer util.gpa.free(owned_args);
for (command_args) |arg, i| { for (command_args, 0..) |arg, i| {
errdefer for (owned_args[0..i]) |a| util.gpa.free(a); errdefer for (owned_args[0..i]) |a| util.gpa.free(a);
owned_args[i] = try util.gpa.dupeZ(u8, arg); owned_args[i] = try util.gpa.dupeZ(u8, arg);
} }

View File

@ -54,5 +54,5 @@ pub fn direction(self: Vector) ?wlr.OutputLayout.Direction {
/// Returns the length of the vector. /// Returns the length of the vector.
pub fn length(self: Vector) u31 { pub fn length(self: Vector) u31 {
return math.sqrt(@intCast(u31, (self.x *| self.x) +| (self.y *| self.y))); return math.sqrt(@as(u31, @intCast((self.x *| self.x) +| (self.y *| self.y))));
} }

View File

@ -88,15 +88,15 @@ pub const State = struct {
const max_x = output_width - state.box.width - border_width; const max_x = output_width - state.box.width - border_width;
state.box.x += delta_x; state.box.x += delta_x;
state.box.x = math.max(state.box.x, border_width); state.box.x = @max(state.box.x, border_width);
state.box.x = math.min(state.box.x, max_x); state.box.x = @min(state.box.x, max_x);
state.box.x = math.max(state.box.x, 0); state.box.x = @max(state.box.x, 0);
const max_y = output_height - state.box.height - border_width; const max_y = output_height - state.box.height - border_width;
state.box.y += delta_y; state.box.y += delta_y;
state.box.y = math.max(state.box.y, border_width); state.box.y = @max(state.box.y, border_width);
state.box.y = math.min(state.box.y, max_y); state.box.y = @min(state.box.y, max_y);
state.box.y = math.max(state.box.y, 0); state.box.y = @max(state.box.y, 0);
} }
pub fn clampToOutput(state: *State) void { pub fn clampToOutput(state: *State) void {
@ -107,8 +107,8 @@ pub const State = struct {
output.wlr_output.effectiveResolution(&output_width, &output_height); output.wlr_output.effectiveResolution(&output_width, &output_height);
const border_width = if (state.ssd) server.config.border_width else 0; const border_width = if (state.ssd) server.config.border_width else 0;
state.box.width = math.min(state.box.width, output_width - (2 * border_width)); state.box.width = @min(state.box.width, output_width - (2 * border_width));
state.box.height = math.min(state.box.height, output_height - (2 * border_width)); state.box.height = @min(state.box.height, output_height - (2 * border_width));
state.move(0, 0); state.move(0, 0);
} }
@ -504,8 +504,8 @@ pub fn map(view: *Self) !void {
if (server.input_manager.defaultSeat().focused_output) |output| { if (server.input_manager.defaultSeat().focused_output) |output| {
// Center the initial pending box on the output // Center the initial pending box on the output
view.pending.box.x = @divTrunc(math.max(0, output.usable_box.width - view.pending.box.width), 2); view.pending.box.x = @divTrunc(@max(0, output.usable_box.width - view.pending.box.width), 2);
view.pending.box.y = @divTrunc(math.max(0, output.usable_box.height - view.pending.box.height), 2); view.pending.box.y = @divTrunc(@max(0, output.usable_box.height - view.pending.box.height), 2);
view.pending.tags = blk: { view.pending.tags = blk: {
if (server.config.tag_rules.match(view)) |tags| break :blk tags; if (server.config.tag_rules.match(view)) |tags| break :blk tags;

View File

@ -34,7 +34,7 @@ request_mode: wl.Listener(*wlr.XdgToplevelDecorationV1) =
wl.Listener(*wlr.XdgToplevelDecorationV1).init(handleRequestMode), wl.Listener(*wlr.XdgToplevelDecorationV1).init(handleRequestMode),
pub fn init(wlr_decoration: *wlr.XdgToplevelDecorationV1) void { pub fn init(wlr_decoration: *wlr.XdgToplevelDecorationV1) void {
const xdg_toplevel = @intToPtr(*XdgToplevel, wlr_decoration.surface.data); const xdg_toplevel: *XdgToplevel = @ptrFromInt(wlr_decoration.surface.data);
xdg_toplevel.decoration = .{ .wlr_decoration = wlr_decoration }; xdg_toplevel.decoration = .{ .wlr_decoration = wlr_decoration };
const decoration = &xdg_toplevel.decoration.?; const decoration = &xdg_toplevel.decoration.?;
@ -64,7 +64,7 @@ fn handleDestroy(
_: *wlr.XdgToplevelDecorationV1, _: *wlr.XdgToplevelDecorationV1,
) void { ) void {
const decoration = @fieldParentPtr(XdgDecoration, "destroy", listener); const decoration = @fieldParentPtr(XdgDecoration, "destroy", listener);
const xdg_toplevel = @intToPtr(*XdgToplevel, decoration.wlr_decoration.surface.data); const xdg_toplevel: *XdgToplevel = @ptrFromInt(decoration.wlr_decoration.surface.data);
decoration.deinit(); decoration.deinit();
@ -78,7 +78,7 @@ fn handleRequestMode(
) void { ) void {
const decoration = @fieldParentPtr(XdgDecoration, "request_mode", listener); const decoration = @fieldParentPtr(XdgDecoration, "request_mode", listener);
const xdg_toplevel = @intToPtr(*XdgToplevel, decoration.wlr_decoration.surface.data); const xdg_toplevel: *XdgToplevel = @ptrFromInt(decoration.wlr_decoration.surface.data);
const view = xdg_toplevel.view; const view = xdg_toplevel.view;
const ssd = server.config.ssd_rules.match(xdg_toplevel.view) orelse const ssd = server.config.ssd_rules.match(xdg_toplevel.view) orelse

View File

@ -85,8 +85,8 @@ pub fn create(xdg_toplevel: *wlr.XdgToplevel) error{OutOfMemory}!void {
self.view = view; self.view = view;
xdg_toplevel.base.data = @ptrToInt(self); xdg_toplevel.base.data = @intFromPtr(self);
xdg_toplevel.base.surface.data = @ptrToInt(&view.tree.node); xdg_toplevel.base.surface.data = @intFromPtr(&view.tree.node);
// Add listeners that are active over the toplevel's entire lifetime // Add listeners that are active over the toplevel's entire lifetime
xdg_toplevel.base.events.destroy.add(&self.destroy); xdg_toplevel.base.events.destroy.add(&self.destroy);
@ -307,10 +307,10 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
{ {
const state = &self.xdg_toplevel.current; const state = &self.xdg_toplevel.current;
view.constraints = .{ view.constraints = .{
.min_width = @intCast(u31, math.max(state.min_width, 1)), .min_width = @max(state.min_width, 1),
.max_width = if (state.max_width > 0) @intCast(u31, state.max_width) else math.maxInt(u31), .max_width = if (state.max_width > 0) @intCast(state.max_width) else math.maxInt(u31),
.min_height = @intCast(u31, math.max(state.min_height, 1)), .min_height = @max(state.min_height, 1),
.max_height = if (state.max_height > 0) @intCast(u31, state.max_height) else math.maxInt(u31), .max_height = if (state.max_height > 0) @intCast(state.max_height) else math.maxInt(u31),
}; };
} }
@ -376,7 +376,7 @@ fn handleRequestMove(
event: *wlr.XdgToplevel.event.Move, event: *wlr.XdgToplevel.event.Move,
) void { ) void {
const self = @fieldParentPtr(Self, "request_move", listener); const self = @fieldParentPtr(Self, "request_move", listener);
const seat = @intToPtr(*Seat, event.seat.seat.data); const seat: *Seat = @ptrFromInt(event.seat.seat.data);
const view = self.view; const view = self.view;
if (view.current.output == null or view.pending.output == null) return; if (view.current.output == null or view.pending.output == null) return;
@ -389,7 +389,7 @@ fn handleRequestMove(
fn handleRequestResize(listener: *wl.Listener(*wlr.XdgToplevel.event.Resize), event: *wlr.XdgToplevel.event.Resize) void { fn handleRequestResize(listener: *wl.Listener(*wlr.XdgToplevel.event.Resize), event: *wlr.XdgToplevel.event.Resize) void {
const self = @fieldParentPtr(Self, "request_resize", listener); const self = @fieldParentPtr(Self, "request_resize", listener);
const seat = @intToPtr(*Seat, event.seat.seat.data); const seat: *Seat = @ptrFromInt(event.seat.seat.data);
const view = self.view; const view = self.view;
{ {

View File

@ -93,7 +93,7 @@ fn mapImpl(self: *Self) error{OutOfMemory}!void {
self.surface_tree = try server.root.layers.xwayland_override_redirect.createSceneSubsurfaceTree(surface); self.surface_tree = try server.root.layers.xwayland_override_redirect.createSceneSubsurfaceTree(surface);
try SceneNodeData.attach(&self.surface_tree.?.node, .{ .xwayland_override_redirect = self }); try SceneNodeData.attach(&self.surface_tree.?.node, .{ .xwayland_override_redirect = self });
surface.data = @ptrToInt(&self.surface_tree.?.node); surface.data = @intFromPtr(&self.surface_tree.?.node);
self.surface_tree.?.node.setPosition(self.xwayland_surface.x, self.xwayland_surface.y); self.surface_tree.?.node.setPosition(self.xwayland_surface.x, self.xwayland_surface.y);

View File

@ -102,10 +102,10 @@ pub fn configure(self: Self) bool {
} }
self.xwayland_surface.configure( self.xwayland_surface.configure(
@intCast(i16, inflight.box.x + output_box.x), @intCast(inflight.box.x + output_box.x),
@intCast(i16, inflight.box.y + output_box.y), @intCast(inflight.box.y + output_box.y),
@intCast(u16, inflight.box.width), @intCast(inflight.box.width),
@intCast(u16, inflight.box.height), @intCast(inflight.box.height),
); );
self.setActivated(inflight.focus != 0); self.setActivated(inflight.focus != 0);
@ -165,7 +165,7 @@ pub fn handleMap(listener: *wl.Listener(*wlr.XwaylandSurface), xwayland_surface:
const view = self.view; const view = self.view;
const surface = xwayland_surface.surface.?; const surface = xwayland_surface.surface.?;
surface.data = @ptrToInt(&view.tree.node); surface.data = @intFromPtr(&view.tree.node);
// Add listeners that are only active while mapped // Add listeners that are only active while mapped
xwayland_surface.events.set_title.add(&self.set_title); xwayland_surface.events.set_title.add(&self.set_title);

View File

@ -108,12 +108,12 @@ fn parseRgba(string: []const u8) ![4]f32 {
const b = try fmt.parseInt(u8, string[6..8], 16); const b = try fmt.parseInt(u8, string[6..8], 16);
const a = if (string.len == 10) try fmt.parseInt(u8, string[8..10], 16) else 255; const a = if (string.len == 10) try fmt.parseInt(u8, string[8..10], 16) else 255;
const alpha = @intToFloat(f32, a) / 255.0; const alpha = @as(f32, @floatFromInt(a)) / 255.0;
return [4]f32{ return [4]f32{
@intToFloat(f32, r) / 255.0 * alpha, @as(f32, @floatFromInt(r)) / 255.0 * alpha,
@intToFloat(f32, g) / 255.0 * alpha, @as(f32, @floatFromInt(g)) / 255.0 * alpha,
@intToFloat(f32, b) / 255.0 * alpha, @as(f32, @floatFromInt(b)) / 255.0 * alpha,
alpha, alpha,
}; };
} }

View File

@ -43,7 +43,7 @@ pub fn declareMode(
const owned_name = try util.gpa.dupeZ(u8, new_mode_name); const owned_name = try util.gpa.dupeZ(u8, new_mode_name);
const id = @intCast(u32, config.modes.items.len); const id: u32 = @intCast(config.modes.items.len);
config.mode_to_id.putAssumeCapacityNoClobber(owned_name, id); config.mode_to_id.putAssumeCapacityNoClobber(owned_name, id);
config.modes.appendAssumeCapacity(.{ .name = owned_name }); config.modes.appendAssumeCapacity(.{ .name = owned_name });
} }

View File

@ -55,7 +55,7 @@ pub fn listInputs(
}); });
} }
out.* = input_list.toOwnedSlice(); out.* = try input_list.toOwnedSlice();
} }
pub fn listInputConfigs( pub fn listInputConfigs(
@ -68,7 +68,7 @@ pub fn listInputConfigs(
var input_list = std.ArrayList(u8).init(util.gpa); var input_list = std.ArrayList(u8).init(util.gpa);
const writer = input_list.writer(); const writer = input_list.writer();
for (server.input_manager.configs.items) |*input_config, i| { for (server.input_manager.configs.items, 0..) |*input_config, i| {
if (i > 0) try input_list.appendSlice("\n"); if (i > 0) try input_list.appendSlice("\n");
try writer.print("{s}\n", .{input_config.identifier}); try writer.print("{s}\n", .{input_config.identifier});
@ -119,7 +119,7 @@ pub fn listInputConfigs(
} }
} }
out.* = input_list.toOwnedSlice(); out.* = try input_list.toOwnedSlice();
} }
pub fn input( pub fn input(
@ -197,7 +197,7 @@ pub fn input(
} else if (mem.eql(u8, "scroll-button", args[2])) { } else if (mem.eql(u8, "scroll-button", args[2])) {
const ret = c.libevdev_event_code_from_name(c.EV_KEY, args[3].ptr); const ret = c.libevdev_event_code_from_name(c.EV_KEY, args[3].ptr);
if (ret < 1) return Error.InvalidButton; if (ret < 1) return Error.InvalidButton;
input_config.scroll_button = InputConfig.ScrollButton{ .button = @intCast(u32, ret) }; input_config.scroll_button = InputConfig.ScrollButton{ .button = @intCast(ret) };
} else { } else {
return Error.UnknownCommand; return Error.UnknownCommand;
} }

View File

@ -200,7 +200,7 @@ fn mappingExists(
keysym: xkb.Keysym, keysym: xkb.Keysym,
release: bool, release: bool,
) ?usize { ) ?usize {
for (mappings.items) |mapping, i| { for (mappings.items, 0..) |mapping, i| {
if (meta.eql(mapping.modifiers, modifiers) and if (meta.eql(mapping.modifiers, modifiers) and
mapping.keysym == keysym and mapping.options.release == release) mapping.keysym == keysym and mapping.options.release == release)
{ {
@ -217,7 +217,7 @@ fn switchMappingExists(
switch_type: Switch.Type, switch_type: Switch.Type,
switch_state: Switch.State, switch_state: Switch.State,
) ?usize { ) ?usize {
for (switch_mappings.items) |mapping, i| { for (switch_mappings.items, 0..) |mapping, i| {
if (mapping.switch_type == switch_type and meta.eql(mapping.switch_state, switch_state)) { if (mapping.switch_type == switch_type and meta.eql(mapping.switch_state, switch_state)) {
return i; return i;
} }
@ -232,7 +232,7 @@ fn pointerMappingExists(
modifiers: wlr.Keyboard.ModifierMask, modifiers: wlr.Keyboard.ModifierMask,
event_code: u32, event_code: u32,
) ?usize { ) ?usize {
for (pointer_mappings.items) |mapping, i| { for (pointer_mappings.items, 0..) |mapping, i| {
if (meta.eql(mapping.modifiers, modifiers) and mapping.event_code == event_code) { if (meta.eql(mapping.modifiers, modifiers) and mapping.event_code == event_code) {
return i; return i;
} }
@ -248,7 +248,7 @@ fn parseEventCode(name: [:0]const u8, out: *?[]const u8) !u32 {
return Error.Other; return Error.Other;
} }
return @intCast(u32, event_code); return @intCast(event_code);
} }
fn parseKeysym(name: [:0]const u8, out: *?[]const u8) !xkb.Keysym { fn parseKeysym(name: [:0]const u8, out: *?[]const u8) !xkb.Keysym {

View File

@ -104,7 +104,7 @@ pub fn resize(
// up against an output edge. // up against an output edge.
const diff_width = prev_width - view.pending.box.width; const diff_width = prev_width - view.pending.box.width;
// Do not grow bigger than the output // Do not grow bigger than the output
view.pending.box.width = math.min( view.pending.box.width = @min(
view.pending.box.width, view.pending.box.width,
output_width - 2 * server.config.border_width, output_width - 2 * server.config.border_width,
); );
@ -116,7 +116,7 @@ pub fn resize(
view.applyConstraints(&view.pending.box); view.applyConstraints(&view.pending.box);
const diff_height = prev_height - view.pending.box.height; const diff_height = prev_height - view.pending.box.height;
// Do not grow bigger than the output // Do not grow bigger than the output
view.pending.box.height = math.min( view.pending.box.height = @min(
view.pending.box.height, view.pending.box.height,
output_height - 2 * server.config.border_width, output_height - 2 * server.config.border_width,
); );

View File

@ -109,15 +109,15 @@ fn getOutput(seat: *Seat, str: []const u8) !?*Output {
const wlr_output = server.root.output_layout.adjacentOutput( const wlr_output = server.root.output_layout.adjacentOutput(
direction, direction,
seat.focused_output.?.wlr_output, seat.focused_output.?.wlr_output,
@intToFloat(f64, focus_box.x + @divTrunc(focus_box.width, 2)), @floatFromInt(focus_box.x + @divTrunc(focus_box.width, 2)),
@intToFloat(f64, focus_box.y + @divTrunc(focus_box.height, 2)), @floatFromInt(focus_box.y + @divTrunc(focus_box.height, 2)),
) orelse return null; ) orelse return null;
return @intToPtr(*Output, wlr_output.data); return @as(*Output, @ptrFromInt(wlr_output.data));
} else { } else {
// Check if an output matches by name // Check if an output matches by name
var it = server.root.active_outputs.iterator(.forward); var it = server.root.active_outputs.iterator(.forward);
while (it.next()) |output| { while (it.next()) |output| {
if (mem.eql(u8, mem.span(output.wlr_output.name), str)) { if (mem.eql(u8, mem.sliceTo(output.wlr_output.name, 0), str)) {
return output; return output;
} }
} }

View File

@ -157,8 +157,8 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!
var buffer = std.ArrayList(u8).init(util.gpa); var buffer = std.ArrayList(u8).init(util.gpa);
const writer = buffer.writer(); const writer = buffer.writer();
try fmt.formatBuf("title", .{ .width = title_column_max, .alignment = .Left }, writer); try fmt.formatBuf("title", .{ .width = title_column_max, .alignment = .left }, writer);
try fmt.formatBuf("app-id", .{ .width = app_id_column_max, .alignment = .Left }, writer); try fmt.formatBuf("app-id", .{ .width = app_id_column_max, .alignment = .left }, writer);
try writer.writeAll("action\n"); try writer.writeAll("action\n");
switch (list) { switch (list) {
@ -169,8 +169,8 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!
else => unreachable, else => unreachable,
}; };
for (rules) |rule| { for (rules) |rule| {
try fmt.formatBuf(rule.title_glob, .{ .width = title_column_max, .alignment = .Left }, writer); try fmt.formatBuf(rule.title_glob, .{ .width = title_column_max, .alignment = .left }, writer);
try fmt.formatBuf(rule.app_id_glob, .{ .width = app_id_column_max, .alignment = .Left }, writer); try fmt.formatBuf(rule.app_id_glob, .{ .width = app_id_column_max, .alignment = .left }, writer);
try writer.print("{s}\n", .{switch (list) { try writer.print("{s}\n", .{switch (list) {
.float => if (rule.value) "float" else "no-float", .float => if (rule.value) "float" else "no-float",
.ssd => if (rule.value) "ssd" else "csd", .ssd => if (rule.value) "ssd" else "csd",
@ -181,12 +181,12 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!
.tag => { .tag => {
const rules = server.config.tag_rules.rules.items; const rules = server.config.tag_rules.rules.items;
for (rules) |rule| { for (rules) |rule| {
try fmt.formatBuf(rule.title_glob, .{ .width = title_column_max, .alignment = .Left }, writer); try fmt.formatBuf(rule.title_glob, .{ .width = title_column_max, .alignment = .left }, writer);
try fmt.formatBuf(rule.app_id_glob, .{ .width = app_id_column_max, .alignment = .Left }, writer); try fmt.formatBuf(rule.app_id_glob, .{ .width = app_id_column_max, .alignment = .left }, writer);
try writer.print("{b}\n", .{rule.value}); try writer.print("{b}\n", .{rule.value});
} }
}, },
} }
out.* = buffer.toOwnedSlice(); out.* = try buffer.toOwnedSlice();
} }

View File

@ -175,7 +175,7 @@ pub fn log(
comptime format: []const u8, comptime format: []const u8,
args: anytype, args: anytype,
) void { ) void {
if (@enumToInt(level) > @enumToInt(runtime_log_level)) return; if (@intFromEnum(level) > @intFromEnum(runtime_log_level)) return;
const scope_prefix = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): "; const scope_prefix = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";

View File

@ -50,7 +50,7 @@ pub fn RuleList(comptime T: type) type {
} }
pub fn add(list: *Self, rule: Rule) error{OutOfMemory}!void { pub fn add(list: *Self, rule: Rule) error{OutOfMemory}!void {
const index = for (list.rules.items) |*existing, i| { const index = for (list.rules.items, 0..) |*existing, i| {
if (mem.eql(u8, rule.app_id_glob, existing.app_id_glob) and if (mem.eql(u8, rule.app_id_glob, existing.app_id_glob) and
mem.eql(u8, rule.title_glob, existing.title_glob)) mem.eql(u8, rule.title_glob, existing.title_glob))
{ {
@ -83,7 +83,7 @@ pub fn RuleList(comptime T: type) type {
} }
pub fn del(list: *Self, rule: struct { app_id_glob: []const u8, title_glob: []const u8 }) void { pub fn del(list: *Self, rule: struct { app_id_glob: []const u8, title_glob: []const u8 }) void {
for (list.rules.items) |existing, i| { for (list.rules.items, 0..) |existing, i| {
if (mem.eql(u8, rule.app_id_glob, existing.app_id_glob) and if (mem.eql(u8, rule.app_id_glob, existing.app_id_glob) and
mem.eql(u8, rule.title_glob, existing.title_glob)) mem.eql(u8, rule.title_glob, existing.title_glob))
{ {

View File

@ -1,6 +1,7 @@
#include <assert.h> #include <assert.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>

View File

@ -110,10 +110,10 @@ fn _main() !void {
fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, globals: *Globals) void { fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, globals: *Globals) void {
switch (event) { switch (event) {
.global => |global| { .global => |global| {
if (std.cstr.cmp(global.interface, wl.Seat.getInterface().name) == 0) { if (mem.orderZ(u8, global.interface, wl.Seat.getInterface().name) == .eq) {
assert(globals.seat == null); // TODO: support multiple seats assert(globals.seat == null); // TODO: support multiple seats
globals.seat = registry.bind(global.name, wl.Seat, 1) catch @panic("out of memory"); globals.seat = registry.bind(global.name, wl.Seat, 1) catch @panic("out of memory");
} else if (std.cstr.cmp(global.interface, zriver.ControlV1.getInterface().name) == 0) { } else if (mem.orderZ(u8, global.interface, zriver.ControlV1.getInterface().name) == .eq) {
globals.control = registry.bind(global.name, zriver.ControlV1, 1) catch @panic("out of memory"); globals.control = registry.bind(global.name, zriver.ControlV1, 1) catch @panic("out of memory");
} }
}, },
@ -132,7 +132,7 @@ fn callbackListener(_: *zriver.CommandCallbackV1, event: zriver.CommandCallbackV
}, },
.failure => |failure| { .failure => |failure| {
// A small hack to provide usage text when river reports an unknown command. // A small hack to provide usage text when river reports an unknown command.
if (std.cstr.cmp(failure.failure_message, "unknown command") == 0) { if (mem.orderZ(u8, failure.failure_message, "unknown command") == .eq) {
std.log.err("unknown command", .{}); std.log.err("unknown command", .{});
io.getStdErr().writeAll(usage) catch {}; io.getStdErr().writeAll(usage) catch {};
os.exit(1); os.exit(1);

View File

@ -170,13 +170,13 @@ const Output = struct {
return; return;
}; };
switch (raw_arg[0]) { switch (raw_arg[0]) {
'+' => output.main_count +|= @intCast(u31, arg), '+' => output.main_count +|= @intCast(arg),
'-' => { '-' => {
const result = output.main_count +| arg; const result = output.main_count +| arg;
if (result >= 1) output.main_count = @intCast(u31, result); if (result >= 1) output.main_count = @intCast(result);
}, },
else => { else => {
if (arg >= 1) output.main_count = @intCast(u31, arg); if (arg >= 1) output.main_count = @intCast(arg);
}, },
} }
}, },
@ -198,16 +198,16 @@ const Output = struct {
.layout_demand => |ev| { .layout_demand => |ev| {
assert(ev.view_count > 0); assert(ev.view_count > 0);
const main_count = math.min(output.main_count, @truncate(u31, ev.view_count)); const main_count = @min(output.main_count, ev.view_count);
const secondary_count = @truncate(u31, ev.view_count) -| main_count; const secondary_count = saturatingCast(u31, ev.view_count) -| main_count;
const usable_width = switch (output.main_location) { const usable_width = switch (output.main_location) {
.left, .right => @truncate(u31, ev.usable_width) -| (2 *| outer_padding), .left, .right => saturatingCast(u31, ev.usable_width) -| (2 *| outer_padding),
.top, .bottom => @truncate(u31, ev.usable_height) -| (2 *| outer_padding), .top, .bottom => saturatingCast(u31, ev.usable_height) -| (2 *| outer_padding),
}; };
const usable_height = switch (output.main_location) { const usable_height = switch (output.main_location) {
.left, .right => @truncate(u31, ev.usable_height) -| (2 *| outer_padding), .left, .right => saturatingCast(u31, ev.usable_height) -| (2 *| outer_padding),
.top, .bottom => @truncate(u31, ev.usable_width) -| (2 *| outer_padding), .top, .bottom => saturatingCast(u31, ev.usable_width) -| (2 *| outer_padding),
}; };
// to make things pixel-perfect, we make the first main and first secondary // to make things pixel-perfect, we make the first main and first secondary
@ -221,7 +221,7 @@ const Output = struct {
var secondary_height_rem: u31 = undefined; var secondary_height_rem: u31 = undefined;
if (secondary_count > 0) { if (secondary_count > 0) {
main_width = @floatToInt(u31, output.main_ratio * @intToFloat(f64, usable_width)); main_width = @intFromFloat(output.main_ratio * @as(f64, @floatFromInt(usable_width)));
main_height = usable_height / main_count; main_height = usable_height / main_count;
main_height_rem = usable_height % main_count; main_height_rem = usable_height % main_count;
@ -382,9 +382,9 @@ pub fn main() !void {
fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, context: *Context) void { fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, context: *Context) void {
switch (event) { switch (event) {
.global => |global| { .global => |global| {
if (std.cstr.cmp(global.interface, river.LayoutManagerV3.getInterface().name) == 0) { if (mem.orderZ(u8, global.interface, river.LayoutManagerV3.getInterface().name) == .eq) {
context.layout_manager = registry.bind(global.name, river.LayoutManagerV3, 1) catch return; context.layout_manager = registry.bind(global.name, river.LayoutManagerV3, 1) catch return;
} else if (std.cstr.cmp(global.interface, wl.Output.getInterface().name) == 0) { } else if (mem.orderZ(u8, global.interface, wl.Output.getInterface().name) == .eq) {
context.addOutput(registry, global.name) catch |err| fatal("failed to bind output: {}", .{err}); context.addOutput(registry, global.name) catch |err| fatal("failed to bind output: {}", .{err});
} }
}, },
@ -413,3 +413,7 @@ fn fatalPrintUsage(comptime format: []const u8, args: anytype) noreturn {
std.io.getStdErr().writeAll(usage) catch {}; std.io.getStdErr().writeAll(usage) catch {};
os.exit(1); os.exit(1);
} }
fn saturatingCast(comptime T: type, x: anytype) T {
return @intCast(math.clamp(x, math.minInt(T), math.maxInt(T)));
}