code: update to zig master in prep for 0.7.0

This commit makes the minimal necessary changes to get things working,
there are further changes which can be made to take advantage of new
features.
This commit is contained in:
Isaac Freund 2020-08-31 15:23:01 +02:00
parent 0bd8274bd4
commit 27b666dbba
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
14 changed files with 35 additions and 35 deletions

View file

@ -139,7 +139,7 @@ const ScanProtocolsStep = struct {
fn init(builder: *std.build.Builder) ScanProtocolsStep { fn init(builder: *std.build.Builder) ScanProtocolsStep {
return ScanProtocolsStep{ return ScanProtocolsStep{
.builder = builder, .builder = builder,
.step = std.build.Step.init("Scan Protocols", builder.allocator, make), .step = std.build.Step.init(.Custom, "Scan Protocols", builder.allocator, make),
}; };
} }
@ -234,7 +234,7 @@ const ScdocStep = struct {
fn init(builder: *std.build.Builder) ScdocStep { fn init(builder: *std.build.Builder) ScdocStep {
return ScdocStep{ return ScdocStep{
.builder = builder, .builder = builder,
.step = std.build.Step.init("Generate man pages", builder.allocator, make), .step = std.build.Step.init(.Custom, "Generate man pages", builder.allocator, make),
}; };
} }

View file

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

View file

@ -104,7 +104,7 @@ fn addArgument(wl_client: ?*c.wl_client, wl_resource: ?*c.wl_resource, arg: ?[*:
return; return;
}; };
self.args_map.get(id).?.value.append(owned_slice) catch { self.args_map.getEntry(id).?.value.append(owned_slice) catch {
c.wl_client_post_no_memory(wl_client); c.wl_client_post_no_memory(wl_client);
util.gpa.free(owned_slice); util.gpa.free(owned_slice);
return; return;
@ -133,7 +133,7 @@ fn runCommand(
}; };
c.wl_resource_set_implementation(callback_resource, null, null, null); c.wl_resource_set_implementation(callback_resource, null, null, null);
const args = self.args_map.get(c.wl_resource_get_id(wl_resource)).?.value.items; const args = self.args_map.get(c.wl_resource_get_id(wl_resource)).?.items;
var out: ?[]const u8 = null; var out: ?[]const u8 = null;
defer if (out) |s| util.gpa.free(s); defer if (out) |s| util.gpa.free(s);

View file

@ -35,7 +35,7 @@ server: *Server,
wlr_idle: *c.wlr_idle, wlr_idle: *c.wlr_idle,
wlr_input_inhibit_manager: *c.wlr_input_inhibit_manager, wlr_input_inhibit_manager: *c.wlr_input_inhibit_manager,
seats: std.TailQueue(Seat) = std.TailQueue(Seat).init(), seats: std.TailQueue(Seat) = .{},
exclusive_client: ?*c.wl_client = null, exclusive_client: ?*c.wl_client = null,

View file

@ -42,7 +42,7 @@ root: *Root,
wlr_output: *c.wlr_output, wlr_output: *c.wlr_output,
/// All layer surfaces on the output, indexed by the layer enum. /// All layer surfaces on the output, indexed by the layer enum.
layers: [4]std.TailQueue(LayerSurface) = [1]std.TailQueue(LayerSurface){std.TailQueue(LayerSurface).init()} ** 4, layers: [4]std.TailQueue(LayerSurface) = [1]std.TailQueue(LayerSurface){.{}} ** 4,
/// The area left for views and other layer surfaces after applying the /// The area left for views and other layer surfaces after applying the
/// exclusive zones of exclusive layer surfaces. /// exclusive zones of exclusive layer surfaces.
@ -50,7 +50,7 @@ layers: [4]std.TailQueue(LayerSurface) = [1]std.TailQueue(LayerSurface){std.Tail
usable_box: Box, usable_box: Box,
/// The top of the stack is the "most important" view. /// The top of the stack is the "most important" view.
views: ViewStack(View) = ViewStack(View){}, views: ViewStack(View) = .{},
/// The double-buffered state of the output. /// The double-buffered state of the output.
current: State = State{ .tags = 1 << 0 }, current: State = State{ .tags = 1 << 0 },
@ -71,7 +71,7 @@ layout: []const u8,
attach_mode: AttachMode = .top, attach_mode: AttachMode = .top,
/// List of status tracking objects relaying changes to this output to clients. /// List of status tracking objects relaying changes to this output to clients.
status_trackers: std.SinglyLinkedList(OutputStatus) = std.SinglyLinkedList(OutputStatus).init(), status_trackers: std.SinglyLinkedList(OutputStatus) = .{},
// All listeners for this output, in alphabetical order // All listeners for this output, in alphabetical order
listen_destroy: c.wl_listener = undefined, listen_destroy: c.wl_listener = undefined,
@ -240,7 +240,7 @@ fn layoutExternal(self: *Self, visible_count: u32) !void {
std.os.execveZ("/bin/sh", &cmd, std.c.environ) catch c._exit(1); std.os.execveZ("/bin/sh", &cmd, std.c.environ) catch c._exit(1);
} }
std.os.close(stdout_pipe[1]); std.os.close(stdout_pipe[1]);
const stdout = std.fs.File{ .handle = stdout_pipe[0], .io_mode = std.io.mode }; const stdout = std.fs.File{ .handle = stdout_pipe[0] };
defer stdout.close(); defer stdout.close();
// TODO abort after a timeout // TODO abort after a timeout

View file

@ -35,20 +35,20 @@ const DragIcon = @import("DragIcon.zig");
server: *Server, server: *Server,
wlr_output_layout: *c.wlr_output_layout, wlr_output_layout: *c.wlr_output_layout,
outputs: std.TailQueue(Output) = std.TailQueue(Output).init(), outputs: std.TailQueue(Output) = .{},
/// This output is used internally when no real outputs are available. /// This output is used internally when no real outputs are available.
/// It is not advertised to clients. /// It is not advertised to clients.
noop_output: Output = undefined, noop_output: Output = undefined,
drag_icons: std.SinglyLinkedList(DragIcon) = std.SinglyLinkedList(DragIcon).init(), drag_icons: std.SinglyLinkedList(DragIcon) = .{},
/// This list stores all unmanaged Xwayland windows. This needs to be in root /// This list stores all unmanaged Xwayland windows. This needs to be in root
/// since X is like the wild west and who knows where these things will go. /// since X is like the wild west and who knows where these things will go.
xwayland_unmanaged_views: if (build_options.xwayland) xwayland_unmanaged_views: if (build_options.xwayland)
std.TailQueue(XwaylandUnmanaged) std.TailQueue(XwaylandUnmanaged)
else else
void = if (build_options.xwayland) std.TailQueue(XwaylandUnmanaged).init(), void = if (build_options.xwayland) .{},
/// Number of pending configures sent in the current transaction. /// Number of pending configures sent in the current transaction.
/// A value of 0 means there is no current transaction. /// A value of 0 means there is no current transaction.
@ -92,7 +92,7 @@ pub fn deinit(self: *Self) void {
} }
pub fn addOutput(self: *Self, wlr_output: *c.wlr_output) void { pub fn addOutput(self: *Self, wlr_output: *c.wlr_output) void {
const node = self.outputs.allocateNode(util.gpa) catch { const node = util.gpa.create(std.TailQueue(Output).Node) catch {
c.wlr_output_destroy(wlr_output); c.wlr_output_destroy(wlr_output);
return; return;
}; };

View file

@ -48,7 +48,7 @@ wlr_seat: *c.wlr_seat,
cursor: Cursor = undefined, cursor: Cursor = undefined,
/// Mulitple keyboards are handled separately /// Mulitple keyboards are handled separately
keyboards: std.TailQueue(Keyboard) = std.TailQueue(Keyboard).init(), keyboards: std.TailQueue(Keyboard) = .{},
/// ID of the current keymap mode /// ID of the current keymap mode
mode_id: usize = 0, mode_id: usize = 0,
@ -61,10 +61,10 @@ focused: FocusTarget = .none,
/// Stack of views in most recently focused order /// Stack of views in most recently focused order
/// If there is a currently focused view, it is on top. /// If there is a currently focused view, it is on top.
focus_stack: ViewStack(*View) = ViewStack(*View){}, focus_stack: ViewStack(*View) = .{},
/// List of status tracking objects relaying changes to this seat to clients. /// List of status tracking objects relaying changes to this seat to clients.
status_trackers: std.SinglyLinkedList(SeatStatus) = std.SinglyLinkedList(SeatStatus).init(), status_trackers: std.SinglyLinkedList(SeatStatus) = .{},
listen_request_set_selection: c.wl_listener = undefined, listen_request_set_selection: c.wl_listener = undefined,
listen_request_start_drag: c.wl_listener = undefined, listen_request_start_drag: c.wl_listener = undefined,
@ -307,7 +307,7 @@ pub fn addDevice(self: *Self, device: *c.wlr_input_device) void {
} }
fn addKeyboard(self: *Self, device: *c.wlr_input_device) !void { fn addKeyboard(self: *Self, device: *c.wlr_input_device) !void {
const node = try self.keyboards.allocateNode(util.gpa); const node = try util.gpa.create(std.TailQueue(Keyboard).Node);
node.data.init(self, device) catch |err| { node.data.init(self, device) catch |err| {
switch (err) { switch (err) {
error.XkbContextFailed => log.err(.keyboard, "Failed to create XKB context", .{}), error.XkbContextFailed => log.err(.keyboard, "Failed to create XKB context", .{}),

View file

@ -111,7 +111,7 @@ float_box: Box = undefined,
draw_borders: bool = true, draw_borders: bool = true,
pub fn init(self: *Self, output: *Output, tags: u32, surface: var) void { pub fn init(self: *Self, output: *Output, tags: u32, surface: anytype) void {
self.* = .{ self.* = .{
.output = output, .output = output,
.current = .{ .tags = tags }, .current = .{ .tags = tags },

View file

@ -32,7 +32,7 @@ pub fn enterMode(
const config = seat.input_manager.server.config; const config = seat.input_manager.server.config;
const target_mode = args[1]; const target_mode = args[1];
seat.mode_id = config.mode_to_id.getValue(target_mode) orelse { seat.mode_id = config.mode_to_id.get(target_mode) orelse {
out.* = try std.fmt.allocPrint( out.* = try std.fmt.allocPrint(
allocator, allocator,
"cannot enter non-existant mode '{}'", "cannot enter non-existant mode '{}'",

View file

@ -149,7 +149,7 @@ pub fn mapPointer(
fn modeNameToId(allocator: *std.mem.Allocator, seat: *Seat, mode_name: []const u8, out: *?[]const u8) !usize { fn modeNameToId(allocator: *std.mem.Allocator, seat: *Seat, mode_name: []const u8, out: *?[]const u8) !usize {
const config = seat.input_manager.server.config; const config = seat.input_manager.server.config;
return config.mode_to_id.getValue(mode_name) orelse { return config.mode_to_id.get(mode_name) orelse {
out.* = try std.fmt.allocPrint( out.* = try std.fmt.allocPrint(
allocator, allocator,
"cannot add mapping to non-existant mode '{}p'", "cannot add mapping to non-existant mode '{}p'",

View file

@ -55,12 +55,12 @@ fn log(
comptime message_level: Level, comptime message_level: Level,
comptime scope: @TypeOf(.foobar), comptime scope: @TypeOf(.foobar),
comptime format: []const u8, comptime format: []const u8,
args: var, args: anytype,
) void { ) void {
if (@enumToInt(message_level) <= @enumToInt(level)) { if (@enumToInt(message_level) <= @enumToInt(level)) {
// Don't store/log messages in release small mode to save space // Don't store/log messages in release small mode to save space
if (std.builtin.mode != .ReleaseSmall) { if (std.builtin.mode != .ReleaseSmall) {
const stderr = std.debug.getStderrStream(); const stderr = std.io.getStdErr().writer();
stderr.print(@tagName(message_level) ++ ": (" ++ @tagName(scope) ++ ") " ++ stderr.print(@tagName(message_level) ++ ": (" ++ @tagName(scope) ++ ") " ++
format ++ "\n", args) catch return; format ++ "\n", args) catch return;
} }
@ -72,7 +72,7 @@ fn log(
pub fn emerg( pub fn emerg(
comptime scope: @TypeOf(.foobar), comptime scope: @TypeOf(.foobar),
comptime format: []const u8, comptime format: []const u8,
args: var, args: anytype,
) void { ) void {
@setCold(true); @setCold(true);
log(.emerg, scope, format, args); log(.emerg, scope, format, args);
@ -83,7 +83,7 @@ pub fn emerg(
pub fn alert( pub fn alert(
comptime scope: @TypeOf(.foobar), comptime scope: @TypeOf(.foobar),
comptime format: []const u8, comptime format: []const u8,
args: var, args: anytype,
) void { ) void {
@setCold(true); @setCold(true);
log(.alert, scope, format, args); log(.alert, scope, format, args);
@ -95,7 +95,7 @@ pub fn alert(
pub fn crit( pub fn crit(
comptime scope: @TypeOf(.foobar), comptime scope: @TypeOf(.foobar),
comptime format: []const u8, comptime format: []const u8,
args: var, args: anytype,
) void { ) void {
@setCold(true); @setCold(true);
log(.crit, scope, format, args); log(.crit, scope, format, args);
@ -106,7 +106,7 @@ pub fn crit(
pub fn err( pub fn err(
comptime scope: @TypeOf(.foobar), comptime scope: @TypeOf(.foobar),
comptime format: []const u8, comptime format: []const u8,
args: var, args: anytype,
) void { ) void {
@setCold(true); @setCold(true);
log(.err, scope, format, args); log(.err, scope, format, args);
@ -118,7 +118,7 @@ pub fn err(
pub fn warn( pub fn warn(
comptime scope: @TypeOf(.foobar), comptime scope: @TypeOf(.foobar),
comptime format: []const u8, comptime format: []const u8,
args: var, args: anytype,
) void { ) void {
log(.warn, scope, format, args); log(.warn, scope, format, args);
} }
@ -128,7 +128,7 @@ pub fn warn(
pub fn notice( pub fn notice(
comptime scope: @TypeOf(.foobar), comptime scope: @TypeOf(.foobar),
comptime format: []const u8, comptime format: []const u8,
args: var, args: anytype,
) void { ) void {
log(.notice, scope, format, args); log(.notice, scope, format, args);
} }
@ -138,7 +138,7 @@ pub fn notice(
pub fn info( pub fn info(
comptime scope: @TypeOf(.foobar), comptime scope: @TypeOf(.foobar),
comptime format: []const u8, comptime format: []const u8,
args: var, args: anytype,
) void { ) void {
log(.info, scope, format, args); log(.info, scope, format, args);
} }
@ -148,7 +148,7 @@ pub fn info(
pub fn debug( pub fn debug(
comptime scope: @TypeOf(.foobar), comptime scope: @TypeOf(.foobar),
comptime format: []const u8, comptime format: []const u8,
args: var, args: anytype,
) void { ) void {
log(.debug, scope, format, args); log(.debug, scope, format, args);
} }

View file

@ -94,7 +94,7 @@ pub fn main() anyerror!void {
log.info(.server, "shutting down", .{}); log.info(.server, "shutting down", .{});
} }
fn printErrorExit(comptime format: []const u8, args: var) noreturn { fn printErrorExit(comptime format: []const u8, args: anytype) noreturn {
const stderr = std.io.getStdErr().outStream(); const stderr = std.io.getStdErr().outStream();
stderr.print(format ++ "\n", args) catch std.os.exit(1); stderr.print(format ++ "\n", args) catch std.os.exit(1);
std.os.exit(1); std.os.exit(1);

View file

@ -23,7 +23,7 @@ pub const gpa = std.heap.c_allocator;
/// Take a pointer to c_void and cast it to a pointer to T. This function /// Take a pointer to c_void and cast it to a pointer to T. This function
/// exists to avoid having the verbosity of the required alignment casts all /// exists to avoid having the verbosity of the required alignment casts all
/// over the code. /// over the code.
pub fn voidCast(comptime T: type, ptr: var) *T { pub fn voidCast(comptime T: type, ptr: anytype) *T {
// See https://github.com/ziglang/zig/issues/5618 // See https://github.com/ziglang/zig/issues/5618
if (@TypeOf(ptr) != *c_void) if (@TypeOf(ptr) != *c_void)
@compileError("voidCast takes *c_void but " ++ @typeName(@TypeOf(ptr)) ++ " was provided"); @compileError("voidCast takes *c_void but " ++ @typeName(@TypeOf(ptr)) ++ " was provided");

View file

@ -140,7 +140,7 @@ pub fn ViewStack(comptime T: type) type {
pub fn iter( pub fn iter(
start: ?*Node, start: ?*Node,
dir: Direction, dir: Direction,
context: var, context: anytype,
filter: fn (*View, @TypeOf(context)) bool, filter: fn (*View, @TypeOf(context)) bool,
) Iter(@TypeOf(context)) { ) Iter(@TypeOf(context)) {
return .{ .it = start, .dir = dir, .context = context, .filter = filter }; return .{ .it = start, .dir = dir, .context = context, .filter = filter };