From b01a83ff3949c9ae42d75a1ad5c80c4fb9a529f8 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 12 Jan 2024 23:40:24 -0600 Subject: [PATCH] Send pen input as pen events on Windows --- app/streaming/input/abstouch.cpp | 40 +++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/app/streaming/input/abstouch.cpp b/app/streaming/input/abstouch.cpp index 75e76d88..fff12af3 100644 --- a/app/streaming/input/abstouch.cpp +++ b/app/streaming/input/abstouch.cpp @@ -112,15 +112,39 @@ void SdlInputHandler::handleAbsoluteFingerEvent(SDL_TouchFingerEvent* event) pointerId = (uint32_t)event->fingerId; } - // Try to send it as a native touch event, otherwise fall back to our touch emulation - if (LiSendTouchEvent(eventType, pointerId, vidrelx / dst.w, vidrely / dst.h, event->pressure, - 0.0f, 0.0f, LI_ROT_UNKNOWN) == LI_ERR_UNSUPPORTED) { - emulateAbsoluteFingerEvent(event); + // Try to send it as a native pen/touch event, otherwise fall back to our touch emulation + if (LiGetHostFeatureFlags() & LI_FF_PEN_TOUCH_EVENTS) { + bool isPen = false; + + int numTouchDevices = SDL_GetNumTouchDevices(); + for (int i = 0; i < numTouchDevices; i++) { + if (event->touchId == SDL_GetTouchDevice(i)) { + const char* touchName = SDL_GetTouchName(i); + + // SDL will report "pen" as the name of pen input devices on Windows. + // https://github.com/libsdl-org/SDL/pull/5926 + isPen = touchName && SDL_strcmp(touchName, "pen") == 0; + break; + } + } + + if (isPen) { + LiSendPenEvent(eventType, LI_TOOL_TYPE_PEN, 0, vidrelx / dst.w, vidrely / dst.h, event->pressure, + 0.0f, 0.0f, LI_ROT_UNKNOWN, LI_TILT_UNKNOWN); + } + else { + LiSendTouchEvent(eventType, pointerId, vidrelx / dst.w, vidrely / dst.h, event->pressure, + 0.0f, 0.0f, LI_ROT_UNKNOWN); + } + + if (!m_DisabledTouchFeedback) { + // Disable touch feedback when passing touch natively + disableTouchFeedback(); + m_DisabledTouchFeedback = true; + } } - else if (!m_DisabledTouchFeedback) { - // Disable touch feedback when passing touch natively - disableTouchFeedback(); - m_DisabledTouchFeedback = true; + else { + emulateAbsoluteFingerEvent(event); } }