From 56cfac068f9576789f2c48f2edc93e25878efcb4 Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Wed, 8 Jun 2022 22:16:27 +0800 Subject: [PATCH] pointerd: support button events --- cmd/pointerd/main.ha | 19 +++++++++++++++++++ proto/control/types.ha | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/cmd/pointerd/main.ha b/cmd/pointerd/main.ha index 378d6f4..b896517 100644 --- a/cmd/pointerd/main.ha +++ b/cmd/pointerd/main.ha @@ -17,6 +17,17 @@ fn sigint(sig: int, info: *signal::siginfo, ucontext: *void) void = { exit = true; }; +fn protocol_key_to_event_code(key: u8) u16 = { + switch (key) { + case control::key::BTN_LEFT => + return evdev::BTN_LEFT; + case control::key::BTN_RIGHT => + return evdev::BTN_RIGHT; + case => + fmt::fatalf("Invalid key code {}", key); + }; +}; + export fn main() void = { const evdev = evdev::new(); defer evdev::destroy(evdev); @@ -67,6 +78,14 @@ export fn main() void = { uinput::write_event(uinput, evdev::EV_REL, evdev::REL_X, buf.x)!; uinput::write_event(uinput, evdev::EV_REL, evdev::REL_Y, buf.y)!; uinput::write_event(uinput, evdev::EV_SYN, evdev::SYN_REPORT, 0)!; + case control::code::KEY_PRESSED => + const code = protocol_key_to_event_code(buf.key); + uinput::write_event(uinput, evdev::EV_KEY, code, 1)!; + uinput::write_event(uinput, evdev::EV_SYN, evdev::SYN_REPORT, 0)!; + case control::code::KEY_RELEASED => + const code = protocol_key_to_event_code(buf.key); + uinput::write_event(uinput, evdev::EV_KEY, code, 0)!; + uinput::write_event(uinput, evdev::EV_SYN, evdev::SYN_REPORT, 0)!; case => fmt::errorfln("Unrecognized control code: {}", buf.code)!; }; diff --git a/proto/control/types.ha b/proto/control/types.ha index f5b0354..e58f5ff 100644 --- a/proto/control/types.ha +++ b/proto/control/types.ha @@ -2,6 +2,13 @@ export def DEFAULT_PORT: u16 = 0x519; export type code = enum u8 { RELATIVE_MOVEMENT = 0, + KEY_PRESSED = 1, + KEY_RELEASED = 2, +}; + +export type key = enum u8 { + BTN_LEFT = 0, + BTN_RIGHT = 1, }; export type request = union { @@ -12,6 +19,7 @@ export type request = union { x: i8, y: i8, }, + key: u8, }, }, bytes: [3]u8, -- 2.45.2