diff options
-rw-r--r-- | src/main.zig | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/main.zig b/src/main.zig index 9969741..718c6ed 100644 --- a/src/main.zig +++ b/src/main.zig @@ -11,18 +11,18 @@ pub fn main() !void { var args = std.process.args(); defer args.deinit(); - if(!args.skip()) + if (!args.skip()) usage(); var input_filepath: []const u8 = ""; - if(args.next()) |arg| { + if (args.next()) |arg| { input_filepath = arg[0..arg.len]; } else { std.debug.print("error: missing required argument input_device\n", .{}); usage(); } - while(args.next()) |arg| { + while (args.next()) |arg| { const keybind = Keybind.parse_string(arg) catch { std.debug.print("error: invalid keybind: {s}\n", .{arg}); usage(); @@ -38,22 +38,22 @@ pub fn main() !void { defer std.os.close(event_fd); var event: c.js_event = undefined; - while(true) { + while (true) { const read_size = try std.os.read(event_fd, std.mem.asBytes(&event)); - if(read_size != @sizeOf(@TypeOf(event))) + if (read_size != @sizeOf(@TypeOf(event))) continue; - if(event.type & c.JS_EVENT_BUTTON == 0) + if (event.type & c.JS_EVENT_BUTTON == 0) continue; - if(event.value != 1) + if (event.value != 1) continue; - for(keybinds.items) |*keybind| { - if(event.number != keybind.key) + for (keybinds.items) |*keybind| { + if (event.number != keybind.key) continue; - std.debug.print("key pressed: {d}, running command: {s}\n", .{keybind.key, keybind.command}); + std.debug.print("key pressed: {d}, running command: {s}\n", .{ keybind.key, keybind.command }); keybind.execute_command(allocator); } } @@ -68,8 +68,8 @@ fn usage() void { \\ binds There may be multiple keybindings in the format key,command \\ \\EXAMPLES: - \\ zbind /dev/input/by-id/usb-Joystick "0,echo 'hello world' > log.log" "4,script.sh" - , .{}); + \\ zbind /dev/input/js0 "0,echo 'hello world' > log.log" "4,script.sh" + , .{}); std.os.exit(1); } @@ -94,4 +94,4 @@ const Keybind = struct { child.spawn() catch return; _ = child.wait() catch return; } -};
\ No newline at end of file +}; |