code: update to zig 0.8.0

This commit is contained in:
Isaac Freund 2021-05-23 13:35:37 +02:00
parent ca4abd261f
commit c0a2286847
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
22 changed files with 90 additions and 90 deletions

3
.gitignore vendored
View file

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

View file

@ -48,14 +48,12 @@ pub fn build(b: *zbs.Builder) !void {
const examples = b.option(bool, "examples", "Set to true to build examples") orelse false;
// This logic must match std.build.resolveInstallPrefix()
const prefix = b.install_prefix orelse if (b.dest_dir) |_| "/usr" else b.cache_root;
const rel_config_path = if (mem.eql(u8, try fs.path.resolve(b.allocator, &[_][]const u8{prefix}), "/usr"))
const rel_config_path = if (mem.eql(u8, try fs.path.resolve(b.allocator, &[_][]const u8{b.install_prefix}), "/usr"))
"../etc/river/init"
else
"etc/river/init";
b.installFile("example/init", rel_config_path);
const abs_config_path = try fs.path.resolve(b.allocator, &[_][]const u8{ prefix, rel_config_path });
const abs_config_path = try fs.path.resolve(b.allocator, &[_][]const u8{ b.install_prefix, rel_config_path });
assert(fs.path.isAbsolute(abs_config_path));
const scanner = ScanProtocolsStep.create(b);
@ -226,7 +224,7 @@ const ScdocStep = struct {
for (scd_paths) |path| {
const command = try std.fmt.allocPrint(
self.builder.allocator,
"scdoc < {} > {}",
"scdoc < {s} > {s}",
.{ path, path[0..(path.len - 4)] },
);
_ = try self.builder.exec(&[_][]const u8{ "sh", "-c", command });
@ -243,7 +241,7 @@ const ScdocStep = struct {
const output = try std.fmt.allocPrint(
self.builder.allocator,
"share/man/man{}/{}",
"share/man/man{s}/{s}",
.{ section, basename_no_ext },
);

2
deps/zig-wayland vendored

@ -1 +1 @@
Subproject commit a453b26a078b94b19ac5e0d40407e241fcd1b6af
Subproject commit a8e1efcfd34ac798f19d8a62ebe3bb368c17f585

2
deps/zig-wlroots vendored

@ -1 +1 @@
Subproject commit 6c62568adfe92a1852566b7d091e99f4b28cbabb
Subproject commit d6444e7a8d43750e2d4ce0cb76483ff968848cb1

2
deps/zig-xkbcommon vendored

@ -1 +1 @@
Subproject commit 9e4d41fe9414094db31c873c2ad9cadcd8999cf6
Subproject commit 10cdca686dacb91d6cfe37f1839b6aedfb53cc4c

View file

@ -112,8 +112,8 @@ pub fn init() !Self {
}
pub fn deinit(self: *Self) void {
var it = self.mode_to_id.iterator();
while (it.next()) |e| util.gpa.free(e.key);
var it = self.mode_to_id.keyIterator();
while (it.next()) |key| util.gpa.free(key.*);
self.mode_to_id.deinit();
for (self.modes.items) |mode| mode.deinit();

View file

@ -77,8 +77,8 @@ fn handleRequest(control: *zriver.ControlV1, request: zriver.ControlV1.Request,
return;
};
const entry = self.args_map.getEntry(.{ .client = control.getClient(), .id = control.getId() }).?;
entry.value.append(util.gpa, owned_slice) catch {
const args = self.args_map.getPtr(.{ .client = control.getClient(), .id = control.getId() }).?;
args.append(util.gpa, owned_slice) catch {
control.getClient().postNoMemory();
util.gpa.free(owned_slice);
return;
@ -96,16 +96,15 @@ fn handleRequest(control: *zriver.ControlV1, request: zriver.ControlV1.Request,
return;
};
const entry = self.args_map.getEntry(.{ .client = control.getClient(), .id = control.getId() }).?;
const args = self.args_map.getPtr(.{ .client = control.getClient(), .id = control.getId() }).?;
defer {
for (entry.value.items) |arg| util.gpa.free(arg);
entry.value.items.len = 0;
for (args.items) |arg| util.gpa.free(arg);
args.items.len = 0;
}
const args = entry.value.items;
var out: ?[]const u8 = null;
defer if (out) |s| util.gpa.free(s);
command.run(util.gpa, seat, args, &out) catch |err| {
command.run(util.gpa, seat, args.items, &out) catch |err| {
const failure_message = switch (err) {
command.Error.OutOfMemory => {
callback.getClient().postNoMemory();
@ -137,9 +136,9 @@ fn handleRequest(control: *zriver.ControlV1, request: zriver.ControlV1.Request,
/// Remove the resource from the hash map and free all stored args
fn handleDestroy(control: *zriver.ControlV1, self: *Self) void {
var list = self.args_map.remove(
var args = self.args_map.fetchRemove(
.{ .client = control.getClient(), .id = control.getId() },
).?.value;
for (list.items) |arg| util.gpa.free(arg);
list.deinit(util.gpa);
for (args.items) |arg| util.gpa.free(arg);
args.deinit(util.gpa);
}

View file

@ -149,7 +149,7 @@ pub fn setTheme(self: *Self, theme: ?[*:0]const u8, _size: ?u32) !void {
while (it) |node| : (it = node.next) {
const wlr_output = node.data.wlr_output;
self.xcursor_manager.load(wlr_output.scale) catch
log.err("failed to load xcursor theme '{}' at scale {}", .{ theme, wlr_output.scale });
log.err("failed to load xcursor theme '{s}' at scale {}", .{ theme, wlr_output.scale });
}
// If this cursor belongs to the default seat, set the xcursor environment
@ -162,7 +162,7 @@ pub fn setTheme(self: *Self, theme: ?[*:0]const u8, _size: ?u32) !void {
if (build_options.xwayland) {
self.xcursor_manager.load(1) catch {
log.err("failed to load xcursor theme '{}' at scale 1", .{theme});
log.err("failed to load xcursor theme '{s}' at scale 1", .{theme});
return;
};
const wlr_xcursor = self.xcursor_manager.getXcursor("left_ptr", 1).?;
@ -525,8 +525,8 @@ fn surfaceAtFilter(view: *View, filter_tags: u32) bool {
}
/// Enter move or resize mode
pub fn enterMode(self: *Self, mode: @TagType(Mode), view: *View) void {
log.debug("enter {} mode", .{@tagName(mode)});
pub fn enterMode(self: *Self, mode: std.meta.Tag((Mode)), view: *View) void {
log.debug("enter {s} mode", .{@tagName(mode)});
self.seat.focus(view);
@ -575,7 +575,7 @@ pub fn enterMode(self: *Self, mode: @TagType(Mode), view: *View) void {
fn leaveMode(self: *Self, event: *wlr.Pointer.event.Button) void {
std.debug.assert(self.mode != .passthrough);
log.debug("leave {} mode", .{@tagName(self.mode)});
log.debug("leave {s} mode", .{@tagName(self.mode)});
// If we were in down mode, we need pass along the release event
if (self.mode == .down)

View file

@ -74,7 +74,7 @@ pub fn init(self: *Self, output: *Output, wlr_layer_surface: *wlr.LayerSurfaceV1
fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *wlr.LayerSurfaceV1) void {
const self = @fieldParentPtr(Self, "destroy", listener);
log.debug("layer surface '{}' destroyed", .{self.wlr_layer_surface.namespace});
log.debug("layer surface '{s}' destroyed", .{self.wlr_layer_surface.namespace});
// Remove listeners active the entire lifetime of the layer surface
self.destroy.link.remove();
@ -90,7 +90,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface:
fn handleMap(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *wlr.LayerSurfaceV1) void {
const self = @fieldParentPtr(Self, "map", listener);
log.debug("layer surface '{}' mapped", .{wlr_layer_surface.namespace});
log.debug("layer surface '{s}' mapped", .{wlr_layer_surface.namespace});
// Add listeners that are only active while mapped
wlr_layer_surface.surface.events.commit.add(&self.commit);
@ -104,7 +104,7 @@ fn handleMap(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *wl
fn handleUnmap(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *wlr.LayerSurfaceV1) void {
const self = @fieldParentPtr(Self, "unmap", listener);
log.debug("layer surface '{}' unmapped", .{self.wlr_layer_surface.namespace});
log.debug("layer surface '{s}' unmapped", .{self.wlr_layer_surface.namespace});
// remove listeners only active while the layer surface is mapped
self.commit.link.remove();

View file

@ -99,8 +99,8 @@ fn handleRequestInert(layout: *river.LayoutV2, request: river.LayoutV2.Request,
/// Send a layout demand to the client
pub fn startLayoutDemand(self: *Self, views: u32) void {
log.debug(
"starting layout demand '{}' on output '{}'",
.{ self.namespace, self.output.wlr_output.name },
"starting layout demand '{s}' on output '{s}'",
.{ self.namespace, mem.sliceTo(&self.output.wlr_output.name, 0) },
);
std.debug.assert(self.output.layout_demand == null);
@ -137,8 +137,8 @@ fn handleRequest(layout: *river.LayoutV2, request: river.LayoutV2.Request, self:
// to the layout demand matching the serial.
.push_view_dimensions => |req| {
log.debug(
"layout '{}' on output '{}' pushed view dimensions: {} {} {} {}",
.{ self.namespace, self.output.wlr_output.name, req.x, req.y, req.width, req.height },
"layout '{s}' on output '{s}' pushed view dimensions: {} {} {} {}",
.{ self.namespace, mem.sliceTo(&self.output.wlr_output.name, 0), req.x, req.y, req.width, req.height },
);
if (self.output.layout_demand) |*layout_demand| {
@ -154,8 +154,8 @@ fn handleRequest(layout: *river.LayoutV2, request: river.LayoutV2.Request, self:
// of the layout demand matching the serial as done.
.commit => |req| {
log.debug(
"layout '{}' on output '{}' commited",
.{ self.namespace, self.output.wlr_output.name },
"layout '{s}' on output '{s}' commited",
.{ self.namespace, mem.sliceTo(&self.output.wlr_output.name, 0) },
);
if (self.output.layout_demand) |*layout_demand| {
@ -170,8 +170,8 @@ fn handleRequest(layout: *river.LayoutV2, request: river.LayoutV2.Request, self:
fn handleDestroy(layout: *river.LayoutV2, self: *Self) void {
log.debug(
"destroying layout '{}' on output '{}'",
.{ self.namespace, self.output.wlr_output.name },
"destroying layout '{s}' on output '{s}'",
.{ self.namespace, mem.sliceTo(&self.output.wlr_output.name, 0) },
);
// Remove layout from the list

View file

@ -18,6 +18,7 @@
const Self = @This();
const std = @import("std");
const mem = std.mem;
const wlr = @import("wlroots");
const wayland = @import("wayland");
const wl = wayland.server.wl;
@ -69,8 +70,8 @@ pub fn deinit(self: *const Self) void {
/// All further responses to the event will simply be ignored.
fn handleTimeout(layout: *Layout) callconv(.C) c_int {
log.notice(
"layout demand for layout '{}' on output '{}' timed out",
.{ layout.namespace, layout.output.wlr_output.name },
"layout demand for layout '{s}' on output '{s}' timed out",
.{ layout.namespace, mem.sliceTo(&layout.output.wlr_output.name, 0) },
);
layout.output.layout_demand.?.deinit();
layout.output.layout_demand = null;

View file

@ -67,7 +67,7 @@ fn handleRequest(layout_manager: *river.LayoutManagerV2, request: river.LayoutMa
const wlr_output = wlr.Output.fromWlOutput(req.output) orelse return;
const output = @intToPtr(*Output, wlr_output.data);
log.debug("bind layout '{}' on output '{}'", .{ req.namespace, output.wlr_output.name });
log.debug("bind layout '{s}' on output '{s}'", .{ req.namespace, mem.sliceTo(&output.wlr_output.name, 0) });
Layout.create(
layout_manager.getClient(),

View file

@ -304,7 +304,7 @@ fn arrangeLayer(
// should only ever be encountered very rarely and matches the
// behavior of other compositors.
std.log.scoped(.layer_shell).warn(
"margins of layer surface '{}' are too large to be reasonably handled. Closing.",
"margins of layer surface '{s}' are too large to be reasonably handled. Closing.",
.{layer_surface.wlr_layer_surface.namespace},
);
layer_surface.wlr_layer_surface.close();
@ -333,7 +333,7 @@ fn arrangeLayer(
if (vertical_margin_size >= bounds.height) {
// TODO find a better solution, see explanation above
std.log.scoped(.layer_shell).warn(
"margins of layer surface '{}' are too large to be reasonably handled. Closing.",
"margins of layer surface '{s}' are too large to be reasonably handled. Closing.",
.{layer_surface.wlr_layer_surface.namespace},
);
layer_surface.wlr_layer_surface.close();
@ -419,7 +419,7 @@ fn arrangeLayer(
fn handleDestroy(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void {
const self = @fieldParentPtr(Self, "destroy", listener);
std.log.scoped(.server).debug("output '{}' destroyed", .{self.wlr_output.name});
std.log.scoped(.server).debug("output '{s}' destroyed", .{mem.sliceTo(&self.wlr_output.name, 0)});
// Remove the destroyed output from root if it wasn't already removed
server.root.removeOutput(self);
@ -482,7 +482,7 @@ pub fn getEffectiveResolution(self: *Self) struct { width: u32, height: u32 } {
fn setTitle(self: Self) void {
var buf: ["river - ".len + self.wlr_output.name.len + 1]u8 = undefined;
const title = fmt.bufPrintZ(&buf, "river - {}", .{mem.spanZ(&self.wlr_output.name)}) catch unreachable;
const title = fmt.bufPrintZ(&buf, "river - {s}", .{mem.sliceTo(&self.wlr_output.name, 0)}) catch unreachable;
if (self.wlr_output.isWl()) {
self.wlr_output.wlSetTitle(title);
} else if (wlr.config.has_x11_backend and self.wlr_output.isX11()) {

View file

@ -19,6 +19,7 @@ const Self = @This();
const build_options = @import("build_options");
const std = @import("std");
const mem = std.mem;
const assert = std.debug.assert;
const wlr = @import("wlroots");
const wl = @import("wayland").server.wl;
@ -128,7 +129,7 @@ pub fn deinit(self: *Self) void {
fn handleNewOutput(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void {
const self = @fieldParentPtr(Self, "new_output", listener);
std.log.scoped(.output_manager).debug("new output {}", .{wlr_output.name});
std.log.scoped(.output_manager).debug("new output {s}", .{mem.sliceTo(&wlr_output.name, 0)});
const node = util.gpa.create(std.TailQueue(Output).Node) catch {
wlr_output.destroy();
@ -475,7 +476,7 @@ fn applyOutputConfig(self: *Self, config: *wlr.OutputConfigurationV1) bool {
// Since we have done a successful test commit, this will only fail
// due to error in the output's backend implementation.
output.wlr_output.commit() catch
std.log.scoped(.output_manager).err("output commit failed for {}", .{output.wlr_output.name});
std.log.scoped(.output_manager).err("output commit failed for {s}", .{mem.sliceTo(&output.wlr_output.name, 0)});
if (output.wlr_output.enabled) {
// Moves the output if it is already in the layout
@ -514,8 +515,8 @@ fn testOutputConfig(config: *wlr.OutputConfigurationV1, rollback: bool) bool {
if (too_small) {
std.log.scoped(.output_manager).info(
"The requested output resolution {}x{} scaled with {} for {} would be too small.",
.{ width, height, scale, wlr_output.name },
"The requested output resolution {}x{} scaled with {} for {s} would be too small.",
.{ width, height, scale, mem.sliceTo(&wlr_output.name, 0) },
);
}
@ -586,11 +587,12 @@ fn handlePowerManagerSetMode(
const log_text = if (enable) "Enabling" else "Disabling";
std.log.scoped(.output_manager).debug(
"{} dpms for output {}",
.{ log_text, event.output.name },
"{s} dpms for output {s}",
.{ log_text, mem.sliceTo(&event.output.name, 0) },
);
event.output.enable(enable);
event.output.commit() catch
std.log.scoped(.server).err("output commit failed for {}", .{event.output.name});
event.output.commit() catch {
std.log.scoped(.server).err("output commit failed for {s}", .{mem.sliceTo(&event.output.name, 0)});
};
}

View file

@ -319,13 +319,14 @@ pub fn handleMapping(
command.Error.Other => out.?,
else => command.errToMsg(err),
};
std.log.scoped(.command).err("{}: {}", .{ args[0], failure_message });
std.log.scoped(.command).err("{s}: {s}", .{ args[0], failure_message });
return true;
};
if (out) |s| {
const stdout = std.io.getStdOut().outStream();
stdout.print("{}", .{s}) catch
|err| std.log.scoped(.command).err("{}: write to stdout failed {}", .{ args[0], err });
const stdout = std.io.getStdOut().writer();
stdout.print("{s}", .{s}) catch |err| {
std.log.scoped(.command).err("{s}: write to stdout failed {}", .{ args[0], err });
};
}
return true;
}

View file

@ -19,6 +19,7 @@ const Self = @This();
const build_options = @import("build_options");
const std = @import("std");
const mem = std.mem;
const wlr = @import("wlroots");
const wl = @import("wayland").server.wl;
@ -188,7 +189,7 @@ fn handleNewLayerSurface(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_
const self = @fieldParentPtr(Self, "new_layer_surface", listener);
log.debug(
"New layer surface: namespace {}, layer {}, anchor {}, size {}x{}, margin ({},{},{},{}), exclusive_zone {}",
"New layer surface: namespace {s}, layer {}, anchor {}, size {}x{}, margin ({},{},{},{}), exclusive_zone {}",
.{
wlr_layer_surface.namespace,
wlr_layer_surface.client_pending.layer,
@ -208,13 +209,13 @@ fn handleNewLayerSurface(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_
if (wlr_layer_surface.output == null) {
const output = self.input_manager.defaultSeat().focused_output;
if (output == &self.root.noop_output) {
log.err("no output available for layer surface '{}'", .{wlr_layer_surface.namespace});
log.err("no output available for layer surface '{s}'", .{wlr_layer_surface.namespace});
wlr_layer_surface.close();
return;
}
log.debug("new layer surface had null output, assigning it to output '{}'", .{
output.wlr_output.name,
log.debug("new layer surface had null output, assigning it to output '{s}'", .{
mem.sliceTo(&output.wlr_output.name, 0),
});
wlr_layer_surface.output = output.wlr_output;
}
@ -241,7 +242,7 @@ fn handleNewXwaylandSurface(listener: *wl.Listener(*wlr.XwaylandSurface), wlr_xw
}
log.debug(
"new xwayland surface: title '{}', class '{}'",
"new xwayland surface: title '{s}', class '{s}'",
.{ wlr_xwayland_surface.title, wlr_xwayland_surface.class },
);

View file

@ -446,7 +446,7 @@ pub fn shouldTrackConfigure(self: Self) bool {
pub fn map(self: *Self) void {
self.pending.target_opacity = server.config.opacity.unfocused;
log.debug("view '{}' mapped", .{self.getTitle()});
log.debug("view '{s}' mapped", .{self.getTitle()});
if (self.foreign_toplevel_handle == null) {
self.foreign_toplevel_handle = wlr.ForeignToplevelHandleV1.create(
@ -487,7 +487,7 @@ pub fn map(self: *Self) void {
/// Called by the impl when the surface will no longer be displayed
pub fn unmap(self: *Self) void {
log.debug("view '{}' unmapped", .{self.getTitle()});
log.debug("view '{s}' unmapped", .{self.getTitle()});
self.destroying = true;
if (self.saved_buffers.items.len == 0) self.saveBuffers();
@ -558,7 +558,7 @@ fn killOpacityTimer(self: *Self) void {
fn armOpacityTimer(self: *Self) void {
const delta_t = server.config.opacity.delta_t;
self.opacity_timer.?.timerUpdate(delta_t) catch |err| {
log.err("failed to update opacity timer: {}", .{err});
log.err("failed to update opacity timer: {s}", .{err});
self.killOpacityTimer();
};
}
@ -577,7 +577,7 @@ fn handleOpacityTimer(self: *Self) callconv(.C) c_int {
fn attachOpacityTimer(self: *Self) void {
const event_loop = server.wl_server.getEventLoop();
self.opacity_timer = event_loop.addTimer(*Self, handleOpacityTimer, self) catch {
log.err("failed to create opacity timer for view '{}'", .{self.getTitle()});
log.err("failed to create opacity timer for view '{s}'", .{self.getTitle()});
return;
};
self.armOpacityTimer();

View file

@ -45,7 +45,7 @@ pub fn enterMode(
const mode_id = server.config.mode_to_id.get(target_mode) orelse {
out.* = try std.fmt.allocPrint(
allocator,
"cannot enter non-existant mode '{}'",
"cannot enter non-existant mode '{s}'",
.{target_mode},
);
return Error.Other;

View file

@ -85,7 +85,7 @@ pub fn mapPointer(
else {
out.* = try std.fmt.allocPrint(
allocator,
"invalid pointer action {}, must be move-view or resize-view",
"invalid pointer action {s}, must be move-view or resize-view",
.{args[4]},
);
return Error.Other;
@ -110,7 +110,7 @@ fn modeNameToId(allocator: *std.mem.Allocator, seat: *Seat, mode_name: []const u
return config.mode_to_id.get(mode_name) orelse {
out.* = try std.fmt.allocPrint(
allocator,
"cannot add/remove mapping to/from non-existant mode '{}'",
"cannot add/remove mapping to/from non-existant mode '{s}'",
.{mode_name},
);
return Error.Other;
@ -153,7 +153,7 @@ fn parseEventCode(allocator: *std.mem.Allocator, event_code_str: []const u8, out
defer allocator.free(event_code_name);
const ret = c.libevdev_event_code_from_name(c.EV_KEY, event_code_name);
if (ret < 1) {
out.* = try std.fmt.allocPrint(allocator, "unknown button {}", .{event_code_str});
out.* = try std.fmt.allocPrint(allocator, "unknown button {s}", .{event_code_str});
return Error.Other;
}
@ -165,7 +165,7 @@ fn parseKeysym(allocator: *std.mem.Allocator, keysym_str: []const u8, out: *?[]c
defer allocator.free(keysym_name);
const keysym = xkb.Keysym.fromName(keysym_name, .case_insensitive);
if (keysym == .NoSymbol) {
out.* = try std.fmt.allocPrint(allocator, "invalid keysym '{}'", .{keysym_str});
out.* = try std.fmt.allocPrint(allocator, "invalid keysym '{s}'", .{keysym_str});
return Error.Other;
}
return keysym;
@ -195,11 +195,7 @@ fn parseModifiers(
continue :outer;
}
}
out.* = try std.fmt.allocPrint(
allocator,
"invalid modifier '{}'",
.{mod_name},
);
out.* = try std.fmt.allocPrint(allocator, "invalid modifier '{s}'", .{mod_name});
return Error.Other;
}
return modifiers;

View file

@ -52,7 +52,7 @@ pub fn main() anyerror!void {
_ = it.nextPosix();
while (it.nextPosix()) |arg| {
if (std.mem.eql(u8, arg, "-h")) {
const stdout = std.io.getStdOut().outStream();
const stdout = std.io.getStdOut().writer();
try stdout.print(usage, .{});
os.exit(0);
} else if (std.mem.eql(u8, arg, "-c")) {
@ -67,13 +67,13 @@ pub fn main() anyerror!void {
} else if (std.mem.eql(u8, arg, "-l")) {
if (it.nextPosix()) |level_str| {
const log_level = std.fmt.parseInt(u3, level_str, 10) catch
printErrorExit("Error: invalid log level '{}'", .{level_str});
printErrorExit("Error: invalid log level '{s}'", .{level_str});
level = @intToEnum(std.log.Level, log_level);
} else {
printErrorExit("Error: flag '-l' requires exactly one argument", .{});
}
} else {
const stderr = std.io.getStdErr().outStream();
const stderr = std.io.getStdErr().writer();
try stderr.print(usage, .{});
os.exit(1);
}
@ -99,7 +99,7 @@ pub fn main() anyerror!void {
// Run the child in a new process group so that we can send SIGTERM to all
// descendants on exit.
const child_pgid = if (startup_command) |cmd| blk: {
std.log.info("running startup command '{}'", .{cmd});
std.log.info("running startup command '{s}'", .{cmd});
const child_args = [_:null]?[*:0]const u8{ "/bin/sh", "-c", cmd, null };
const pid = try os.fork();
if (pid == 0) {
@ -112,7 +112,7 @@ pub fn main() anyerror!void {
break :blk pid;
} else null;
defer if (child_pgid) |pgid|
os.kill(-pgid, os.SIGTERM) catch |e| std.log.err("failed to kill startup process: {}", .{e});
os.kill(-pgid, os.SIGTERM) catch |e| std.log.err("failed to kill startup process: {s}", .{e});
std.log.info("running server", .{});
@ -122,7 +122,7 @@ pub fn main() anyerror!void {
}
fn printErrorExit(comptime format: []const u8, args: anytype) noreturn {
const stderr = std.io.getStdErr().outStream();
const stderr = std.io.getStdErr().writer();
stderr.print(format ++ "\n", args) catch os.exit(1);
os.exit(1);
}
@ -138,11 +138,11 @@ fn testConfigPath(comptime fmt: []const u8, args: anytype) std.fmt.AllocPrintErr
fn getStartupCommand() std.fmt.AllocPrintError!?[:0]const u8 {
if (os.getenv("XDG_CONFIG_HOME")) |xdg_config_home| {
if (try testConfigPath("{}/river/init", .{xdg_config_home})) |path| {
if (try testConfigPath("{s}/river/init", .{xdg_config_home})) |path| {
return path;
}
} else if (os.getenv("HOME")) |home| {
if (try testConfigPath("{}/.config/river/init", .{home})) |path| {
if (try testConfigPath("{s}/.config/river/init", .{home})) |path| {
return path;
}
}

View file

@ -17,6 +17,7 @@
const build_options = @import("build_options");
const std = @import("std");
const mem = std.mem;
const os = std.os;
const wlr = @import("wlroots");
const wl = @import("wayland").server.wl;
@ -159,7 +160,7 @@ pub fn renderOutput(output: *Output) void {
// TODO: handle failure
output.wlr_output.commit() catch
log.err("output commit failed for {}", .{output.wlr_output.name});
log.err("output commit failed for {s}", .{mem.sliceTo(&output.wlr_output.name, 0)});
}
fn renderFilter(view: *View, filter_tags: u32) bool {

View file

@ -92,17 +92,17 @@ fn callbackListener(callback: *zriver.CommandCallbackV1, event: zriver.CommandCa
switch (event) {
.success => |success| {
if (mem.len(success.output) > 0) {
const stdout = std.io.getStdOut().outStream();
stdout.print("{}\n", .{success.output}) catch @panic("failed to write to stdout");
const stdout = std.io.getStdOut().writer();
stdout.print("{s}\n", .{success.output}) catch @panic("failed to write to stdout");
}
os.exit(0);
},
.failure => |failure| printErrorExit("Error: {}\n", .{failure.failure_message}),
.failure => |failure| printErrorExit("Error: {s}\n", .{failure.failure_message}),
}
}
pub fn printErrorExit(comptime format: []const u8, args: anytype) noreturn {
const stderr = std.io.getStdErr().outStream();
const stderr = std.io.getStdErr().writer();
stderr.print("err: " ++ format ++ "\n", args) catch std.os.exit(1);
std.os.exit(1);
}