From fc8dcf1761da00c6359209703a9ea379ef7c5b8b Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Sun, 15 May 2022 22:42:43 +0800 Subject: [PATCH] import evdev bindings from previous experiments --- evdev/libevdev.ha | 29 +++++++++++++++++++++++++++++ evdev/types.ha | 12 ++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 evdev/libevdev.ha create mode 100644 evdev/types.ha diff --git a/evdev/libevdev.ha b/evdev/libevdev.ha new file mode 100644 index 0000000..3365b41 --- /dev/null +++ b/evdev/libevdev.ha @@ -0,0 +1,29 @@ +use io; +use rt; +use strings; + +export fn new_from_fd(fd: io::file) (rt::errno | libevdev) = { + let handle = null: libevdev; + const r = c_libevdev_new_from_fd(fd, &handle); + if (r < 0) { + return (-r): rt::errno; + }; + return handle; +}; + +export fn get_name(dev: libevdev) const str = { + return strings::fromc(c_libevdev_get_name(dev)); +}; + +export fn next_event(dev: libevdev, flags: uint) (rt::errno | input_event) = { + let ev = input_event { ... }; + const r = c_libevdev_next_event(dev, flags, &ev); + if (r < 0) { + return (-r): rt::errno; + }; + return ev; +}; + +@symbol("libevdev_new_from_fd") fn c_libevdev_new_from_fd(fd: int, dev: *libevdev) int; +@symbol("libevdev_get_name") fn c_libevdev_get_name(dev: libevdev) *const char; +@symbol("libevdev_next_event") fn c_libevdev_next_event(dev: libevdev, flags: uint, ev: *input_event) int; diff --git a/evdev/types.ha b/evdev/types.ha new file mode 100644 index 0000000..37c28e8 --- /dev/null +++ b/evdev/types.ha @@ -0,0 +1,12 @@ +use rt; + +export type libevdev = *void; + +export type input_event = struct { + time: rt::timeval, + _type: u16, + code: u16, + value: i32, +}; + +export def READ_FLAG_NORMAL: uint = 2; -- 2.45.2