From e1aecedf30f3b3cedd89d84364bd7e548a011bcd Mon Sep 17 00:00:00 2001 From: Asmir A Date: Sat, 30 May 2026 20:36:35 +0200 Subject: [PATCH] nixpkgs 25.11 -> 26.05 --- build.zig | 18 ++++++++++-------- flake.lock | 12 +++++++----- flake.nix | 4 ++++ src/main.zig | 36 ++++++++++++++++++++++-------------- 4 files changed, 43 insertions(+), 27 deletions(-) diff --git a/build.zig b/build.zig index 410e517..7902ed4 100644 --- a/build.zig +++ b/build.zig @@ -15,18 +15,20 @@ pub fn build(b: *std.Build) void { // set a preferred release mode, allowing the user to decide how to optimize. const optimize = b.standardOptimizeOption(.{}); - var exe = b.addExecutable(.{ + const exe_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + .link_libc = true, + }); + exe_module.linkSystemLibrary("evdev", .{}); + + const exe = b.addExecutable(.{ .name = "zremap", // In this case the main source file is merely a path, however, in more), // complicated build scripts, this could be a generated file. - .root_module = b.createModule(.{ - .root_source_file = b.path("src/main.zig"), - .target = target, - .optimize = optimize, - }), + .root_module = exe_module, }); - exe.linkLibC(); - exe.linkSystemLibrary("evdev"); // This declares intent for the executable to be installed into the // standard location when the user invokes the "install" step (the default diff --git a/flake.lock b/flake.lock index 90937b2..b8670cc 100644 --- a/flake.lock +++ b/flake.lock @@ -2,16 +2,18 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1758446476, - "narHash": "sha256-5rdAi7CTvM/kSs6fHe1bREIva5W3TbImsto+dxG4mBo=", + "lastModified": 1779971959, + "narHash": "sha256-R5nauXyqyfRUFiZycFFZdkF7wl6eaUpPLst35+2nJQY=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "a1f79a1770d05af18111fbbe2a3ab2c42c0f6cd0", + "rev": "ec942ba042dad5ef097e2ef3a3effc034241f011", "type": "github" }, "original": { - "id": "nixpkgs", - "type": "indirect" + "owner": "NixOS", + "ref": "nixos-26.05", + "repo": "nixpkgs", + "type": "github" } }, "root": { diff --git a/flake.nix b/flake.nix index 0e3a103..9508587 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,10 @@ { description = "zremap nix flake"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05"; + }; + outputs = { self, diff --git a/src/main.zig b/src/main.zig index 6730ec8..c4c9ad0 100644 --- a/src/main.zig +++ b/src/main.zig @@ -17,10 +17,10 @@ fn event_equal(e1: *const c.input_event, e2: *const c.input_event) bool { return (e1.type == e2.type) and (e1.code == e2.code) and (e1.value == e2.value); } -fn inputDeviceOpenAndGrab(dev_name: []const u8) !?*c.libevdev { - const dev_fd = try std.fs.openFileAbsolute(dev_name, .{}); +fn inputDeviceOpenAndGrab(dev_name: [:0]const u8) !?*c.libevdev { + const dev_fd = try std.posix.openatZ(std.posix.AT.FDCWD, dev_name, .{}, 0); const dev = c.libevdev_new(); - if (c.libevdev_set_fd(dev, dev_fd.handle) < 0) { + if (c.libevdev_set_fd(dev, dev_fd) < 0) { return error.libevdevCreateFail; } if (c.libevdev_grab(dev, c.LIBEVDEV_GRAB) < 0) { @@ -43,29 +43,37 @@ fn uinputWrite(uinput_dev: *c.libevdev_uinput, event: *const c.input_event) !voi } } +fn sleepMs(ms: i64) void { + const ts = std.c.timespec{ + .sec = @divFloor(ms, std.time.ms_per_s), + .nsec = @rem(ms, std.time.ms_per_s) * std.time.ns_per_ms, + }; + _ = std.c.nanosleep(&ts, null); +} + fn uinputWriteKey(uinput_dev: *c.libevdev_uinput, key: u16) !void { const pressKey = c.input_event{ .type = c.EV_KEY, .code = key, .value = 1, .time = undefined }; const releaseKey = c.input_event{ .type = c.EV_KEY, .code = key, .value = 0, .time = undefined }; const sync = c.input_event{ .type = c.EV_SYN, .code = c.SYN_REPORT, .value = 0, .time = undefined }; - std.Thread.sleep(20 * std.time.ns_per_ms); + sleepMs(20); try uinputWrite(uinput_dev, &pressKey); try uinputWrite(uinput_dev, &sync); - std.Thread.sleep(20 * std.time.ns_per_ms); + sleepMs(20); try uinputWrite(uinput_dev, &releaseKey); } -pub fn main() !void { - var gpa = std.heap.GeneralPurposeAllocator(.{}){}; - const allocator = gpa.allocator(); - defer _ = gpa.deinit(); +pub fn main(init: std.process.Init.Minimal) !void { + var args = init.args.iterate(); + _ = args.skip(); // program name - const args = try std.process.argsAlloc(allocator); - - if (args.len != 2) { + const dev_name = args.next() orelse { std.debug.print("error: expected one argument", .{}); - std.posix.exit(1); + std.process.exit(1); + }; + if (args.next() != null) { + std.debug.print("error: expected one argument", .{}); + std.process.exit(1); } - const dev_name = args[1]; const dev = try inputDeviceOpenAndGrab(dev_name); const uinput_dev = try uinputCreate(dev.?);