uinput: implement uinput functionality
This commit is contained in:
		
							parent
							
								
									468c4bd474
								
							
						
					
					
						commit
						33db0ea301
					
				
							
								
								
									
										19
									
								
								src/main.zig
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								src/main.zig
									
									
									
									
									
								
							| @ -1,7 +1,8 @@ | ||||
| const std = @import("std"); | ||||
| const c = @cImport({ | ||||
|     @cInclude("linux/input.h"); | ||||
|     @cInclude("libevdev-1.0/libevdev/libevdev.h"); | ||||
|     @cInclude("libevdev/libevdev.h"); | ||||
|     @cInclude("libevdev/libevdev-uinput.h"); | ||||
|     @cInclude("errno.h"); | ||||
| }); | ||||
| 
 | ||||
| @ -14,17 +15,16 @@ const LShiftUp = c.input_event{ .type = c.EV_KEY, .code = c.KEY_LEFTSHIFT, .valu | ||||
| 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 }; | ||||
| const Syn = c.input_event{ .type = c.EV_SYN, .code = c.SYN_REPORT, .value = 0, .time = undefined }; | ||||
| var uidev: *align(8) void = 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); | ||||
| } | ||||
| 
 | ||||
| //fn event_read(event: *c.input_event) !void { | ||||
| //    event.* = try std.io.getStdIn().reader().readStruct(@TypeOf(event.*)); | ||||
| //} | ||||
| 
 | ||||
| fn event_write(event: *const c.input_event) !void { | ||||
|     try std.io.getStdOut().writer().writeStruct(event.*); | ||||
|     if (c.libevdev_uinput_write_event(@ptrCast(uidev), event.*.type, event.*.code, event.*.value) < 0) { | ||||
|         return error.writeFailed; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| fn write_esc() !void { | ||||
| @ -61,6 +61,11 @@ pub fn main() !void { | ||||
|         std.os.exit(1); | ||||
|     } | ||||
| 
 | ||||
|     if (c.libevdev_uinput_create_from_device(@ptrCast(dev), c.LIBEVDEV_UINPUT_OPEN_MANAGED, @ptrCast(&uidev)) < 0) { | ||||
|         std.debug.print("evdev: failed creating uinput device", .{}); | ||||
|         std.os.exit(1); | ||||
|     } | ||||
| 
 | ||||
|     var write_esc_lshift: bool = undefined; | ||||
|     var write_esc_rshift: bool = undefined; | ||||
|     var is_lshift_down: bool = false; | ||||
| @ -82,7 +87,7 @@ pub fn main() !void { | ||||
|             break :outer; | ||||
|         } | ||||
| 
 | ||||
|         if (event.type == c.EV_MSC and event.type == c.MSC_SCAN) { | ||||
|         if (event.type == c.EV_MSC and event.code == c.MSC_SCAN) { | ||||
|             continue :outer; | ||||
|         } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user