From 83376f702e65146868ae4e551e324cabd5155fb6 Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Mon, 16 May 2022 01:16:53 +0800 Subject: [PATCH] tools: add uinput-pointer --- .gitignore | 1 + Makefile | 4 ++-- tools/uinput-pointer/main.ha | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tools/uinput-pointer/main.ha diff --git a/.gitignore b/.gitignore index 7b7653c..9179b41 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /evdev-dump-events +/uinput-pointer diff --git a/Makefile b/Makefile index 016fa4c..bc461c2 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,3 @@ -evdev-dump-events: +evdev-dump-events uinput-pointer: hare build -levdev -o $@ tools/$@/ -.PHONY: evdev-dump-events +.PHONY: evdev-dump-events uinput-pointer diff --git a/tools/uinput-pointer/main.ha b/tools/uinput-pointer/main.ha new file mode 100644 index 0000000..9239266 --- /dev/null +++ b/tools/uinput-pointer/main.ha @@ -0,0 +1,32 @@ +use evdev; +use evdev::uinput; +use fmt; +use rt; +use time; + +export fn main() void = { + const evdev = evdev::new(); + defer evdev::destroy(evdev); + evdev::set_name(evdev, "uinput pointer"); + evdev::enable_event_type(evdev, evdev::EV_REL)!; + evdev::enable_event_code(evdev, evdev::EV_REL, evdev::REL_X, null)!; + evdev::enable_event_code(evdev, evdev::EV_REL, evdev::REL_Y, null)!; + evdev::enable_event_type(evdev, evdev::EV_KEY)!; + evdev::enable_event_code(evdev, evdev::EV_KEY, evdev::BTN_LEFT, null)!; + evdev::enable_event_code(evdev, evdev::EV_KEY, evdev::BTN_MIDDLE, null)!; + evdev::enable_event_code(evdev, evdev::EV_KEY, evdev::BTN_RIGHT, null)!; + + const uinput = match (evdev::uinput::create_from_device(evdev, evdev::uinput::OPEN_MANAGED)) { + case let uinput: evdev::uinput::uinput => + yield uinput; + case let err: rt::errno => + fmt::fatalf("Failed to create uinput dev: {}", rt::strerror(err)); + }; + defer evdev::uinput::destroy(uinput); + + for (let i = 0; i < 100; i += 1) { + evdev::uinput::write_event(uinput, evdev::EV_REL, evdev::REL_X, 1)!; + evdev::uinput::write_event(uinput, evdev::EV_SYN, evdev::SYN_REPORT, 0)!; + time::sleep(10 * time::MILLISECOND); + }; +}; -- 2.45.2