From 85523de2316b0d0882c5e4648ad807eb72753051 Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Mon, 16 May 2022 01:16:24 +0800 Subject: [PATCH] add evdev::uinput --- evdev/uinput/types.ha | 5 +++++ evdev/uinput/uinput.ha | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 evdev/uinput/types.ha create mode 100644 evdev/uinput/uinput.ha diff --git a/evdev/uinput/types.ha b/evdev/uinput/types.ha new file mode 100644 index 0000000..7a62b7f --- /dev/null +++ b/evdev/uinput/types.ha @@ -0,0 +1,5 @@ +use io; + +export type uinput = *void; + +export def OPEN_MANAGED: io::file = -2; diff --git a/evdev/uinput/uinput.ha b/evdev/uinput/uinput.ha new file mode 100644 index 0000000..e8bc1a5 --- /dev/null +++ b/evdev/uinput/uinput.ha @@ -0,0 +1,27 @@ +use evdev; +use io; +use rt; + +export fn create_from_device(dev: evdev::libevdev, fd: io::file) + (uinput | rt::errno) = { + let handle = null: uinput; + const r = c_libevdev_uinput_create_from_device(dev, fd: int, &handle); + if (r < 0) { + return (-r): rt::errno; + }; + return handle; +}; + +export fn write_event(uinput_dev: uinput, event_type: uint, code: uint, value: int) + (void | rt::errno) = { + const r = c_libevdev_uinput_write_event(uinput_dev, event_type, code, value); + if (r < 0) { + return (-r): rt::errno; + }; +}; + +@symbol("libevdev_uinput_create_from_device") fn c_libevdev_uinput_create_from_device( + dev: evdev::libevdev, uinput_fd: int, uinput_dev: *uinput) int; +export @symbol("libevdev_uinput_destroy") fn destroy(dev: uinput) void; +@symbol("libevdev_uinput_write_event") fn c_libevdev_uinput_write_event( + uinput_dev: uinput, etype: uint, code: uint, value: int) int; -- 2.45.2