diff --git a/.gitignore b/.gitignore index 3d3af6b..d49dc6f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -zig-cache/ +.zig-cache/ zig-out/ *~ diff --git a/build.zig b/build.zig index b8f3ddb..07733f8 100644 --- a/build.zig +++ b/build.zig @@ -3,6 +3,6 @@ const std = @import("std"); pub fn build(b: *std.Build) void { _ = b.addModule("zigx", .{ - .root_source_file = .{ .path = "x.zig" }, + .root_source_file = b.path("x.zig"), }); } diff --git a/c/build.zig b/c/build.zig index 0d6abd6..905aa5c 100644 --- a/c/build.zig +++ b/c/build.zig @@ -1,21 +1,21 @@ const std = @import("std"); -pub fn build(b: *std.build.Builder) void { +pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const x_mod = b.createModule(.{ - .source_file = .{ .path = b.pathJoin(&.{ b.build_root.path.?, "../x.zig" }) }, + .root_source_file = b.path("../x.zig" ), }); const x11_lib = b.addStaticLibrary(.{ .name = "x11", - .root_source_file = .{ .path = "x11.zig" }, + .root_source_file = b.path("x11.zig"), .target = target, .optimize = optimize, }); - x11_lib.addIncludePath(.{ .path = b.pathJoin(&.{ b.build_root.path.?, "include" }) }); - x11_lib.addModule("x", x_mod); + x11_lib.addIncludePath(b.path("include")); + x11_lib.root_module.addImport("x", x_mod); // I *think* we'll want to link libc here because it's probably guaranteed that // the application will be linking libc and not linking libc means we could have // discrepancies, for example, zig's start code that initializes the environment @@ -26,11 +26,13 @@ pub fn build(b: *std.build.Builder) void { { const exe = b.addExecutable(.{ .name = "hellox11", - .root_source_file = .{ .path = "example/hellox11.c" }, .target = target, .optimize = optimize, }); - exe.addIncludePath(.{ .path = b.pathJoin(&.{ b.build_root.path.?, "include" })}); + exe.addCSourceFiles(.{ + .files = &.{ "example/hellox11.c" }, + }); + exe.addIncludePath(b.path("include")); exe.linkLibC(); exe.linkLibrary(x11_lib); b.installArtifact(exe); diff --git a/c/x11.zig b/c/x11.zig index fda759a..d2daee2 100644 --- a/c/x11.zig +++ b/c/x11.zig @@ -6,7 +6,7 @@ const c = @cImport({ const x = @import("x"); const c_allocator = std.heap.c_allocator; -fn sendAll(sock: std.os.socket_t, data: []const u8) !void { +fn sendAll(sock: std.posix.socket_t, data: []const u8) !void { var total_sent: usize = 0; while (true) { const sent = try x.writeSock(sock, data[total_sent..], 0); @@ -15,8 +15,8 @@ fn sendAll(sock: std.os.socket_t, data: []const u8) !void { if (total_sent == data.len) return; } } -pub const SocketReader = std.io.Reader(std.os.socket_t, std.os.RecvFromError, readSocket); -fn readSocket(sock: std.os.socket_t, buffer: []u8) !usize { +pub const SocketReader = std.io.Reader(std.posix.socket_t, std.posix.RecvFromError, readSocket); +fn readSocket(sock: std.posix.socket_t, buffer: []u8) !usize { return x.readSock(sock, buffer, 0); } @@ -168,7 +168,7 @@ fn openDisplay(display_spec_opt: ?[*:0]const u8) error{Reported, OutOfMemory}!*c fn connectSetupAuth( display_num: ?u32, - sock: std.os.socket_t, + sock: std.posix.socket_t, auth_filename: []const u8, ) error{Reported,OutOfMemory}!?x.ConnectSetup.Header { const auth_mapped = x.MappedFile.init(auth_filename, .{}) catch |err| @@ -244,7 +244,7 @@ fn connectSetupAuth( export fn XCloseDisplay(display_opt: ?*c.Display) c_int { const display = display_opt orelse return 0; - const display_full = @fieldParentPtr(Display, "public", display); + const display_full: *Display = @fieldParentPtr("public", display); { var it = display_full.gc_list.first; @@ -274,7 +274,7 @@ export fn XCreateSimpleWindow( _ = border; _ = background; - const display_full = @fieldParentPtr(Display, "public", display); + const display_full: *Display = @fieldParentPtr("public", display); const new_window = display_full.resource_id_base + display_full.next_resource_id_offset; display_full.next_resource_id_offset += 1; @@ -339,7 +339,7 @@ export fn XCreateGC( value_mask: c_ulong, values: ?[*]c.XGCValues, ) c.GC { - const display_full = @fieldParentPtr(Display, "public", display); + const display_full: *Display = @fieldParentPtr("public", display); const gc_id = display_full.resource_id_base + display_full.next_resource_id_offset; display_full.next_resource_id_offset += 1; @@ -366,7 +366,7 @@ export fn XCreateGC( } export fn XMapRaised(display: *c.Display, window: c.Window) c_int { - const display_full = @fieldParentPtr(Display, "public", display); + const display_full: *Display = @fieldParentPtr("public", display); std.log.info("TODO: send ConfigureWindow stack-mode=Above", .{}); var msg: [x.map_window.len]u8 = undefined; @@ -382,11 +382,12 @@ fn handleReadError(err: anytype) noreturn { switch (err) { error.ConnectionResetByPeer, error.EndOfStream, + error.ConnectionTimedOut, => { //@panic("TODO: report x connection closed and/or reset"); // This seems to be similar to what libx11 does? std.io.getStdErr().writer().print("X connection broken\n", .{}) catch @panic("X connection broken"); - std.os.exit(1); + std.process.exit(1); }, error.MessageTooBig => { @panic("TODO: how to handle MessageTooBig?"); @@ -403,7 +404,7 @@ fn handleReadError(err: anytype) noreturn { } export fn XNextEvent(display: *c.Display, event: *c.XEvent) c_int { - const display_full = @fieldParentPtr(Display, "public", display); + const display_full: *Display = @fieldParentPtr("public", display); //var header_buf: [32]u8 align(4) = undefined; const len = x.readOneMsg(SocketReader{ .context = display.fd }, display_full.read_buf) catch |err| handleReadError(err); @@ -438,7 +439,7 @@ export fn XNextEvent(display: *c.Display, event: *c.XEvent) c_int { // ChangeWindowAttributes(window=w#0A000001, event-mask=KeyPress|ButtonPress|Exposure) export fn XSelectInput(display: *c.Display, window: c.Window, event_mask: c_ulong) c_int { - const display_full = @fieldParentPtr(Display, "public", display); + const display_full: *Display = @fieldParentPtr("public", display); var msg_buf: [x.change_window_attributes.max_len]u8 = undefined; const len = x.change_window_attributes.serialize(&msg_buf, window, .{