From a1994fca99cfaf8da51a11951dd4f20ffbd3692c Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Sun, 3 Jul 2022 22:00:42 +0800 Subject: [PATCH] evdev::next_event: return status --- evdev/libevdev.ha | 7 +++---- evdev/types.ha | 12 +++++++++++- tools/evdev-dump-events/main.ha | 12 +++++++++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/evdev/libevdev.ha b/evdev/libevdev.ha index 7aa89d5..fd331c8 100644 --- a/evdev/libevdev.ha +++ b/evdev/libevdev.ha @@ -22,13 +22,12 @@ export fn set_name(dev: libevdev, name: str) void = { c_libevdev_set_name(dev, cstr); }; -export fn next_event(dev: libevdev, flags: uint) (errors::error | input_event) = { - let ev = input_event { ... }; - const r = c_libevdev_next_event(dev, flags, &ev); +export fn next_event(dev: libevdev, flags: uint, ev: *input_event) (errors::error | read_status) = { + const r = c_libevdev_next_event(dev, flags, ev); if (r < 0) { return errors::errno(-r); }; - return ev; + return r: read_status; }; export fn enable_event_type(dev: libevdev, event_type: uint) (void | unknown_error) = { diff --git a/evdev/types.ha b/evdev/types.ha index e6a6cf1..8db9b60 100644 --- a/evdev/types.ha +++ b/evdev/types.ha @@ -11,4 +11,14 @@ export type input_event = struct { export type unknown_error = !void; -export def READ_FLAG_NORMAL: uint = 2; +export type read_status = enum int { + SUCCESS = 0, + SYNC = 1, +}; + +export type read_flag = enum uint { + SYNC = 1, + NORMAL = 2, + FORCE_SYNC = 4, + BLOCKING = 8, +}; diff --git a/tools/evdev-dump-events/main.ha b/tools/evdev-dump-events/main.ha index 21d9e0f..6db9d00 100644 --- a/tools/evdev-dump-events/main.ha +++ b/tools/evdev-dump-events/main.ha @@ -27,9 +27,15 @@ export fn main() void = { fmt::printfln("Input device name: {}", evdev::get_name(evdev))!; for (true) { - let ev = match (evdev::next_event(evdev, evdev::READ_FLAG_NORMAL)) { - case let ev: evdev::input_event => - yield ev; + let ev = evdev::input_event {...}; + match (evdev::next_event(evdev, evdev::read_flag::NORMAL, &ev)) { + case let r: evdev::read_status => + switch (r) { + case evdev::read_status::SUCCESS => + yield; + case evdev::read_status::SYNC => + continue; + }; case let err: errors::error => match (err) { case errors::again => -- 2.45.2