diff --git a/build.zig b/build.zig index 12a6aef..94fa98c 100644 --- a/build.zig +++ b/build.zig @@ -1,6 +1,6 @@ const std = @import("std"); -const Scanner = @import("deps/zig-wayland/build.zig").Scanner; +const Scanner = @import("zig-wayland").Scanner; pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); @@ -9,27 +9,6 @@ pub fn build(b: *std.Build) void { const scanner = Scanner.create(b, .{}); scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml"); - 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 ziglua = b.dependency("ziglua", .{ - .target = target, - .optimize = optimize, - }); - // These must be manually kept in sync with the versions wlroots supports // until wlroots gives the option to request a specific version. scanner.generate("wl_compositor", 4); @@ -40,6 +19,23 @@ pub fn build(b: *std.Build) void { scanner.generate("wl_data_device_manager", 3); scanner.generate("xdg_wm_base", 2); + const wayland = b.createModule(.{ .root_source_file = scanner.result }); + const xkbcommon = b.dependency("zig-xkbcommon", .{}).module("xkbcommon"); + const pixman = b.dependency("zig-pixman", .{}).module("pixman"); + const wlroots = b.dependency("zig-wlroots", .{}).module("wlroots"); + + wlroots.addImport("wayland", wayland); + wlroots.addImport("xkbcommon", xkbcommon); + wlroots.addImport("pixman", pixman); + + wlroots.resolved_target = target; + wlroots.linkSystemLibrary("wlroots", .{}); + + const ziglua = b.dependency("ziglua", .{ + .target = target, + .optimize = optimize, + }); + const gaze = b.addExecutable(.{ .name = "gaze", .root_source_file = .{ .path = "src/main.zig" }, @@ -49,21 +45,17 @@ pub fn build(b: *std.Build) void { gaze.linkLibC(); - gaze.addModule("wayland", wayland); + gaze.root_module.addImport("wayland", wayland); + gaze.root_module.addImport("xkbcommon", xkbcommon); + gaze.root_module.addImport("wlroots", wlroots); + gaze.root_module.addImport("ziglua", ziglua.module("ziglua")); + gaze.linkSystemLibrary("wayland-server"); + gaze.linkSystemLibrary("xkbcommon"); + gaze.linkSystemLibrary("pixman-1"); // TODO: remove when https://github.com/ziglang/zig/issues/131 is implemented scanner.addCSource(gaze); - gaze.addModule("xkbcommon", xkbcommon); - gaze.linkSystemLibrary("xkbcommon"); - - gaze.addModule("wlroots", wlroots); - gaze.linkSystemLibrary("wlroots"); - gaze.linkSystemLibrary("pixman-1"); - - gaze.addModule("ziglua", ziglua.module("ziglua")); - gaze.linkLibrary(ziglua.artifact("lua")); - b.installArtifact(gaze); } diff --git a/build.zig.zon b/build.zig.zon index 87243d4..d4a76e1 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -4,8 +4,24 @@ .paths = .{""}, .dependencies = .{ .ziglua = .{ - .url = "https://github.com/natecraddock/ziglua/archive/8cd91ec9de5c206ae4e37034127d8972758dc55c.tar.gz", - .hash = "12205d977da825e681a09048180700bb4cc00bbeb417e8ff5c5fe59cb76189ffa592", + .url = "https://github.com/natecraddock/ziglua/archive/486f51d3acc61d805783f5f07aee34c75ab59a25.tar.gz", + .hash = "12208603e0f51fa6ce7201d8e851c5979b6b78887434623ac87a0f2a5a3dd3e75130", + }, + .@"zig-pixman" = .{ + .url = "https://codeberg.org/ifreund/zig-pixman/archive/v0.1.0.tar.gz", + .hash = "122014eeb4600a059bdcfe1c864862f17e6d5e4237e3bb7d6818f2a5583f6f4eb843", + }, + .@"zig-wayland" = .{ + .url = "https://codeberg.org/ifreund/zig-wayland/archive/v0.1.0.tar.gz", + .hash = "1220b0f8f822c1625af7aae4cb3ab2c4ec1a4c0e99ef32867b2a8d88bb070b3e7f6d", + }, + .@"zig-wlroots" = .{ + .url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.17.0.tar.gz", + .hash = "1220714d1cc39c3abb1d9c22a0b838d847ead099cb7d9931821490483f30c022e827", + }, + .@"zig-xkbcommon" = .{ + .url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.1.0.tar.gz", + .hash = "1220840390382c88caf9b0887f6cebbba3a7d05960b8b2ee6d80567b2950b71e5017", }, }, } diff --git a/flake.lock b/flake.lock index d99e03e..8af82e3 100644 --- a/flake.lock +++ b/flake.lock @@ -1,125 +1,12 @@ { "nodes": { - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1673956053, - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-compat_2": { - "flake": false, - "locked": { - "lastModified": 1673956053, - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-utils": { - "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_2": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1705309234, - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_3": { - "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "gitignore": { - "inputs": { - "nixpkgs": [ - "zls-overlay", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1703887061, - "narHash": "sha256-gGPa9qWNc6eCXT/+Z5/zMkyYOuRZqeFZBDbopNZQkuY=", - "owner": "hercules-ci", - "repo": "gitignore.nix", - "rev": "43e1aa1308018f37118e34d3a9cb4f5e75dc11d5", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "gitignore.nix", - "type": "github" - } - }, - "langref": { - "flake": false, - "locked": { - "narHash": "sha256-94broSBethRhPJr0G9no4TPyB8ee6BQ/hHK1QnLPln0=", - "type": "file", - "url": "https://raw.githubusercontent.com/ziglang/zig/54bbc73f8502fe073d385361ddb34a43d12eec39/doc/langref.html.in" - }, - "original": { - "type": "file", - "url": "https://raw.githubusercontent.com/ziglang/zig/54bbc73f8502fe073d385361ddb34a43d12eec39/doc/langref.html.in" - } - }, "nixpkgs": { "locked": { - "lastModified": 1709150264, - "narHash": "sha256-HofykKuisObPUfj0E9CJVfaMhawXkYx3G8UIFR/XQ38=", + "lastModified": 1716509168, + "narHash": "sha256-4zSIhSRRIoEBwjbPm3YiGtbd8HDWzFxJjw5DYSDy1n8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9099616b93301d5cf84274b184a3a5ec69e94e08", + "rev": "bfb7a882678e518398ce9a31a881538679f6f092", "type": "github" }, "original": { @@ -130,93 +17,7 @@ }, "root": { "inputs": { - "nixpkgs": "nixpkgs", - "zig-overlay": "zig-overlay", - "zls-overlay": "zls-overlay" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "zig-overlay": { - "inputs": { - "flake-compat": "flake-compat", - "flake-utils": "flake-utils", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1709208548, - "narHash": "sha256-cHzhHGJ2mT11mta+JOVNURSG5MdNJrBsDowVIj5nl2Q=", - "owner": "mitchellh", - "repo": "zig-overlay", - "rev": "bfa983b61aa539e64703404f434f77b10d41c37e", - "type": "github" - }, - "original": { - "owner": "mitchellh", - "repo": "zig-overlay", - "type": "github" - } - }, - "zig-overlay_2": { - "inputs": { - "flake-compat": "flake-compat_2", - "flake-utils": "flake-utils_3", - "nixpkgs": [ - "zls-overlay", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1709035693, - "narHash": "sha256-ac5fR8n4RPjP5GHhFMdtUhdL6e/eFCxIOO+7UoP1B/g=", - "owner": "mitchellh", - "repo": "zig-overlay", - "rev": "e1c418c2315adaeca6f27fd8919141eb7992866d", - "type": "github" - }, - "original": { - "owner": "mitchellh", - "repo": "zig-overlay", - "type": "github" - } - }, - "zls-overlay": { - "inputs": { - "flake-utils": "flake-utils_2", - "gitignore": "gitignore", - "langref": "langref", - "nixpkgs": [ - "nixpkgs" - ], - "zig-overlay": "zig-overlay_2" - }, - "locked": { - "lastModified": 1709179266, - "narHash": "sha256-BdofpXMQlk82nzHC7+rK7pOEIO5lSCco7IV2Hyb2OIE=", - "owner": "zigtools", - "repo": "zls", - "rev": "7d6a9e22a27b9f432d85a48db2e0180d15a87fa2", - "type": "github" - }, - "original": { - "owner": "zigtools", - "repo": "zls", - "type": "github" + "nixpkgs": "nixpkgs" } } }, diff --git a/flake.nix b/flake.nix index 8c86644..9460900 100644 --- a/flake.nix +++ b/flake.nix @@ -3,18 +3,18 @@ inputs = { nixpkgs.url = "nixpkgs/nixos-unstable"; - zig-overlay.url = "github:mitchellh/zig-overlay"; - zig-overlay.inputs.nixpkgs.follows = "nixpkgs"; + # zig-overlay.url = "github:mitchellh/zig-overlay"; + # zig-overlay.inputs.nixpkgs.follows = "nixpkgs"; - zls-overlay.url = "github:zigtools/zls"; - zls-overlay.inputs.nixpkgs.follows = "nixpkgs"; + # zls-overlay.url = "github:zigtools/zls"; + # zls-overlay.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, nixpkgs, - zig-overlay, - zls-overlay, + # zig-overlay, + # zls-overlay, }: let version = self.shortRev or "dirty"; supportedSystems = ["x86_64-linux"]; @@ -44,7 +44,8 @@ buildInputs = [ - zig-overlay.packages.${system}.master-2024-01-02 + # zig-overlay.packages.${system}.master-2024-02-29 + zig_0_12 wlroots_0_17 libGL libevdev @@ -58,7 +59,8 @@ ++ ( if inShell then [ - zls-overlay.packages.${system}.default + # zls-overlay.packages.${system}.default + zls valgrind gdb ] diff --git a/src/commands.zig b/src/commands.zig index 3bc78be..0b623cc 100644 --- a/src/commands.zig +++ b/src/commands.zig @@ -29,8 +29,7 @@ pub fn focus(server: *Server, client: *Client) !void { const wlr_keyboard = server.seat.getKeyboard() orelse return; server.seat.keyboardNotifyEnter( client.xdg_surface.surface, - &wlr_keyboard.keycodes, - wlr_keyboard.num_keycodes, + wlr_keyboard.keycodes[0..wlr_keyboard.num_keycodes], &wlr_keyboard.modifiers, ); } diff --git a/src/event.zig b/src/event.zig index afee4a5..dc3768d 100644 --- a/src/event.zig +++ b/src/event.zig @@ -10,8 +10,9 @@ fn Event(comptime name: []const u8, comptime T: type) type { listener: ?*const fn (server: *serv.Server, data: *T) void = null, fn call(listener: *wl.Listener(*T), data: *T) void { - const self = @fieldParentPtr(Event(name, T), "wl_listener", listener); - const server = @fieldParentPtr(Events, name, self).server; + const self: *Event(name, T) = @fieldParentPtr("wl_listener", listener); + const events: *Events = @fieldParentPtr(name, self); + const server = events.server; std.log.debug("calling event {s}", .{name}); if (self.listener) |l| { l(server, data); diff --git a/src/server/client.zig b/src/server/client.zig index f0312f9..b4896a5 100644 --- a/src/server/client.zig +++ b/src/server/client.zig @@ -45,19 +45,19 @@ pub const Client = struct { } fn onMap(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Client, "map_l", listener); + const self: *Client = @fieldParentPtr("map_l", listener); self.server.clients.prepend(self); // TODO: remove this and add this in a lua file Api.focus(self.server, self) catch {}; } fn onUnmap(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Client, "unmap_l", listener); + const self: *Client = @fieldParentPtr("unmap_l", listener); self.link.remove(); } fn onDestroy(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Client, "destroy_l", listener); + const self: *Client = @fieldParentPtr("destroy_l", listener); self.destroy(); } }; diff --git a/src/server/cursor.zig b/src/server/cursor.zig index 2f5a155..8034812 100644 --- a/src/server/cursor.zig +++ b/src/server/cursor.zig @@ -75,7 +75,7 @@ pub const Cursor = struct { listener: *wl.Listener(*wlr.Pointer.event.Motion), event: *wlr.Pointer.event.Motion, ) void { - const self = @fieldParentPtr(Cursor, "motion", listener); + const self: *Cursor = @fieldParentPtr("motion", listener); self.cursor.move(event.device, event.delta_x, event.delta_y); self.handleMotion(event.time_msec); } @@ -84,7 +84,7 @@ pub const Cursor = struct { listener: *wl.Listener(*wlr.Pointer.event.MotionAbsolute), event: *wlr.Pointer.event.MotionAbsolute, ) void { - const self = @fieldParentPtr(Cursor, "motion_absolute", listener); + const self: *Cursor = @fieldParentPtr("motion_absolute", listener); self.cursor.warpAbsolute(event.device, event.x, event.y); self.handleMotion(event.time_msec); } @@ -93,7 +93,7 @@ pub const Cursor = struct { listener: *wl.Listener(*wlr.Pointer.event.Button), event: *wlr.Pointer.event.Button, ) void { - const self = @fieldParentPtr(Cursor, "button", listener); + const self: *Cursor = @fieldParentPtr("button", listener); _ = self.server.seat.pointerNotifyButton(event.time_msec, event.button, event.state); } @@ -101,7 +101,7 @@ pub const Cursor = struct { listener: *wl.Listener(*wlr.Pointer.event.Axis), event: *wlr.Pointer.event.Axis, ) void { - const self = @fieldParentPtr(Cursor, "axis", listener); + const self: *Cursor = @fieldParentPtr("axis", listener); self.server.seat.pointerNotifyAxis( event.time_msec, event.orientation, @@ -112,7 +112,7 @@ pub const Cursor = struct { } fn onFrame(listener: *wl.Listener(*wlr.Cursor), _: *wlr.Cursor) void { - const self = @fieldParentPtr(Cursor, "frame", listener); + const self: *Cursor = @fieldParentPtr("frame", listener); self.server.seat.pointerNotifyFrame(); } @@ -120,7 +120,7 @@ pub const Cursor = struct { listener: *wl.Listener(*wlr.Seat.event.RequestSetCursor), event: *wlr.Seat.event.RequestSetCursor, ) void { - const self = @fieldParentPtr(Cursor, "request_set_cursor_l", listener); + const self: *Cursor = @fieldParentPtr("request_set_cursor_l", listener); if (event.seat_client == self.server.seat.pointer_state.focused_client) self.cursor.setSurface(event.surface, event.hotspot_x, event.hotspot_y); } @@ -129,7 +129,7 @@ pub const Cursor = struct { listener: *wl.Listener(*wlr.Seat.event.RequestSetSelection), event: *wlr.Seat.event.RequestSetSelection, ) void { - const self = @fieldParentPtr(Cursor, "request_set_selection_l", listener); + const self: *Cursor = @fieldParentPtr("request_set_selection_l", listener); self.server.seat.setSelection(event.source, event.serial); } }; diff --git a/src/server/keyboard.zig b/src/server/keyboard.zig index d75c016..744ad21 100644 --- a/src/server/keyboard.zig +++ b/src/server/keyboard.zig @@ -49,13 +49,13 @@ pub const Keyboard = struct { } fn modifiers(listener: *wl.Listener(*wlr.Keyboard), wlr_keyboard: *wlr.Keyboard) void { - const keyboard = @fieldParentPtr(Keyboard, "modifiers", listener); + const keyboard: *Keyboard = @fieldParentPtr("modifiers", listener); keyboard.server.seat.setKeyboard(wlr_keyboard); keyboard.server.seat.keyboardNotifyModifiers(&wlr_keyboard.modifiers); } fn key(listener: *wl.Listener(*wlr.Keyboard.event.Key), event: *wlr.Keyboard.event.Key) void { - const keyboard = @fieldParentPtr(Keyboard, "key", listener); + const keyboard: *Keyboard = @fieldParentPtr("key", listener); // TODO: Actually handle keybinds in gaze. Bellow is what was used in tinywl. // // Translate libinput keycode -> xkbcommon diff --git a/src/server/monitor.zig b/src/server/monitor.zig index 8def160..0973cd1 100644 --- a/src/server/monitor.zig +++ b/src/server/monitor.zig @@ -69,18 +69,18 @@ pub const Monitor = struct { } fn onDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void { - const self = @fieldParentPtr(Monitor, "destroy_l", listener); + const self: *Monitor = @fieldParentPtr("destroy_l", listener); self.destroy(); } fn onFrame(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void { - const output = @fieldParentPtr(Monitor, "frame_l", listener); + const output: *Monitor = @fieldParentPtr("frame_l", listener); const scene_output = output.server.scene.getSceneOutput(output.wlr_output).?; _ = scene_output.commit(null); - var now: std.os.timespec = undefined; - std.os.clock_gettime(std.os.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported"); + var now: std.posix.timespec = undefined; + std.posix.clock_gettime(std.posix.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported"); scene_output.sendFrameDone(&now); } @@ -88,7 +88,7 @@ pub const Monitor = struct { listener: *wl.Listener(*wlr.Output.event.RequestState), event: *wlr.Output.event.RequestState, ) void { - const output = @fieldParentPtr(Monitor, "request_state_l", listener); + const output: *Monitor = @fieldParentPtr("request_state_l", listener); _ = output.wlr_output.commitState(event.state); }