From 1de13cf4ddfb11e65b67b567872db253e6b1f54f Mon Sep 17 00:00:00 2001 From: okay Date: Mon, 25 Sep 2023 18:40:50 -0700 Subject: [PATCH] [input] add has_stylus property to Input class this allows harmony to query for stylus presence --- src/harmony/app/canvas.cpy | 13 ++++++------- src/rmkit/input/device_id.cpy | 13 +++++++++++++ src/rmkit/input/input.cpy | 10 ++++++++++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/harmony/app/canvas.cpy b/src/harmony/app/canvas.cpy index 4a921b0..d27aa27 100644 --- a/src/harmony/app/canvas.cpy +++ b/src/harmony/app/canvas.cpy @@ -160,14 +160,13 @@ namespace app_ui: eraser->set_framebuffer(self.layers[cur_layer].fb.get()) bool ignore_event(input::SynMotionEvent &ev): - #ifdef KOBO - ev.pressure = 0.5 - ev.tilt_x = 0.5 - ev.tilt_y = 0.5 - return false - #else + if not ui::MainLoop::in.has_stylus: + ev.pressure = 0.5 + ev.tilt_x = 0.5 + ev.tilt_y = 0.5 + return false + return input::is_touch_event(ev) != NULL - #endif void on_mouse_move(input::SynMotionEvent &ev): diff --git a/src/rmkit/input/device_id.cpy b/src/rmkit/input/device_id.cpy index e8b7be3..c0c3e0b 100644 --- a/src/rmkit/input/device_id.cpy +++ b/src/rmkit/input/device_id.cpy @@ -57,6 +57,19 @@ namespace input: return UNKNOWN + static bool supports_stylus(int fd): + if fd <= 0: + return false + + unsigned long bit[EV_MAX] + ioctl(fd, EVIOCGBIT(0, EV_MAX), bit) + if check_bit_set(fd, EV_KEY, BTN_TOOL_PEN): + return true + if check_bit_set(fd, EV_KEY, BTN_STYLUS) && test_bit(EV_ABS, bit): + return true + + return false + static EV_TYPE id_by_name(int fd): char name[256]; ioctl(fd, EVIOCGNAME(sizeof(name)), name); diff --git a/src/rmkit/input/input.cpy b/src/rmkit/input/input.cpy index af6ee57..a13c2bd 100644 --- a/src/rmkit/input/input.cpy +++ b/src/rmkit/input/input.cpy @@ -50,6 +50,11 @@ namespace input: fd = _fd T::set_fd(fd) + bool supports_stylus(): + return input::supports_stylus(fd) + + + void handle_event_fd(): int bytes = read(fd, ev_data, sizeof(input_event) * 64); if bytes < sizeof(input_event) || bytes == -1: @@ -89,6 +94,7 @@ namespace input: public: int max_fd fd_set rdfs + bool has_stylus InputClass wacom InputClass touch @@ -132,6 +138,7 @@ namespace input: self.monitor(input::ipc_fd[0]) self.set_scaling(framebuffer::fb_info::display_width, framebuffer::fb_info::display_height) + self.has_stylus = supports_stylus() return @@ -286,6 +293,8 @@ namespace input: #endif return + bool supports_stylus(): + return wacom.supports_stylus() || touch.supports_stylus() // TODO: should we just put this in the SynMotionEvent? static WacomEvent* is_wacom_event(SynMotionEvent &syn_ev): @@ -295,3 +304,4 @@ namespace input: if evt != nullptr && evt->is_touch(): return evt return nullptr +