refactor: finish first phase
This commit is contained in:
parent
9f78401625
commit
015eeab44a
18
src/main.zig
18
src/main.zig
@ -12,7 +12,6 @@ const LShiftDown = c.input_event{ .type = c.EV_KEY, .code = c.KEY_LEFTSHIFT, .va
|
||||
const LShiftUp = c.input_event{ .type = c.EV_KEY, .code = c.KEY_LEFTSHIFT, .value = 0, .time = undefined };
|
||||
const RShiftDown = c.input_event{ .type = c.EV_KEY, .code = c.KEY_RIGHTSHIFT, .value = 1, .time = undefined };
|
||||
const RShiftUp = c.input_event{ .type = c.EV_KEY, .code = c.KEY_RIGHTSHIFT, .value = 0, .time = undefined };
|
||||
var uinput: *align(8) c.libevdev_uinput = undefined;
|
||||
|
||||
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);
|
||||
@ -27,14 +26,12 @@ fn inputDeviceOpenAndGrab(dev_name: []const u8) !?*c.libevdev {
|
||||
if (c.libevdev_grab(dev, c.LIBEVDEV_GRAB) < 0) {
|
||||
return error.libevdevGrabFail;
|
||||
}
|
||||
if (c.libevdev_uinput_create_from_device(@ptrCast(dev), c.LIBEVDEV_UINPUT_OPEN_MANAGED, @ptrCast(uinput)) < 0) {
|
||||
return error.libevdevUinputCreateFail;
|
||||
}
|
||||
return dev;
|
||||
}
|
||||
|
||||
fn uinputCreate(dev: *c.libevdev) !?*c.libevdev_uinput {
|
||||
if (c.libevdev_uinput_create_from_device(@ptrCast(dev), c.LIBEVDEV_UINPUT_OPEN_MANAGED, @ptrCast(uinput)) < 0) {
|
||||
var uinput: *align(8) c.libevdev_uinput = undefined;
|
||||
if (c.libevdev_uinput_create_from_device(@ptrCast(dev), c.LIBEVDEV_UINPUT_OPEN_MANAGED, @ptrCast(&uinput)) < 0) {
|
||||
return error.libevdevUinputCreateFail;
|
||||
}
|
||||
return uinput;
|
||||
@ -70,8 +67,7 @@ pub fn main() !void {
|
||||
}
|
||||
const dev_name = args[1];
|
||||
const dev = try inputDeviceOpenAndGrab(dev_name);
|
||||
//const uinput_dev = try uinputCreate(dev.?);
|
||||
const uinput_dev = uinput;
|
||||
const uinput_dev = try uinputCreate(dev.?);
|
||||
|
||||
var write_esc_lshift: bool = undefined;
|
||||
var write_esc_rshift: bool = undefined;
|
||||
@ -99,7 +95,7 @@ pub fn main() !void {
|
||||
}
|
||||
|
||||
if (event.type != c.EV_KEY) {
|
||||
try uinputWrite(uinput_dev, &event);
|
||||
try uinputWrite(uinput_dev.?, &event);
|
||||
continue :outer;
|
||||
}
|
||||
|
||||
@ -112,16 +108,16 @@ pub fn main() !void {
|
||||
event.code = c.KEY_LEFTMETA;
|
||||
}
|
||||
|
||||
try uinputWrite(uinput_dev, &event);
|
||||
try uinputWrite(uinput_dev.?, &event);
|
||||
|
||||
if (write_esc_lshift) {
|
||||
write_esc_lshift = false;
|
||||
try uinputWriteKey(uinput_dev, c.KEY_ESC);
|
||||
try uinputWriteKey(uinput_dev.?, c.KEY_ESC);
|
||||
}
|
||||
|
||||
if (write_esc_rshift) {
|
||||
write_esc_rshift = false;
|
||||
try uinputWriteKey(uinput_dev, c.KEY_ESC);
|
||||
try uinputWriteKey(uinput_dev.?, c.KEY_ESC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user