nixpkgs 25.11 -> 26.05

This commit is contained in:
2026-05-30 20:36:35 +02:00
parent b0707744e2
commit e1aecedf30
4 changed files with 43 additions and 27 deletions

View File

@@ -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(.{
.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(.{
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 = 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

12
flake.lock generated
View File

@@ -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": {

View File

@@ -1,6 +1,10 @@
{
description = "zremap nix flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
};
outputs =
{
self,

View File

@@ -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.?);