Skip to content

Commit

Permalink
code: update to zig 0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ifreund committed Jun 5, 2021
1 parent ca4abd2 commit c0a2286
Showing 22 changed files with 90 additions and 90 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
zig-cache
zig-cache/
zig-out/
doc/*.[1-9]
10 changes: 4 additions & 6 deletions build.zig
Original file line number Diff line number Diff line change
@@ -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 changes: 1 addition & 1 deletion deps/zig-wayland
2 changes: 1 addition & 1 deletion deps/zig-xkbcommon
4 changes: 2 additions & 2 deletions river/Config.zig
Original file line number Diff line number Diff line change
@@ -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();
19 changes: 9 additions & 10 deletions river/Control.zig
Original file line number Diff line number Diff line change
@@ -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);
}
10 changes: 5 additions & 5 deletions river/Cursor.zig
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 3 additions & 3 deletions river/LayerSurface.zig
Original file line number Diff line number Diff line change
@@ -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();
16 changes: 8 additions & 8 deletions river/Layout.zig
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions river/LayoutDemand.zig
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion river/LayoutManager.zig
Original file line number Diff line number Diff line change
@@ -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(),
8 changes: 4 additions & 4 deletions river/Output.zig
Original file line number Diff line number Diff line change
@@ -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()) {
20 changes: 11 additions & 9 deletions river/Root.zig
Original file line number Diff line number Diff line change
@@ -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;
@@ -75,7 +76,7 @@ xwayland_unmanaged_views: if (build_options.xwayland)
std.TailQueue(XwaylandUnmanaged)
else
void = if (build_options.xwayland)
.{},
.{},

/// Number of layout demands pending before the transaction may be started.
pending_layout_demands: u32 = 0,
@@ -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)});
};
}
9 changes: 5 additions & 4 deletions river/Seat.zig
Original file line number Diff line number Diff line change
@@ -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;
}
Loading

0 comments on commit c0a2286

Please sign in to comment.