From 7439e35258fd47d079bebcdb09454e3b667c2a7b Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Sat, 11 May 2024 07:25:35 +0100 Subject: [PATCH] InputEmulation: Implement scroll_discrete support Fixes scrolling in Steam Input --- src/InputEmulation.cpp | 19 ++++++++++++++++++- src/InputEmulation.h | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/InputEmulation.cpp b/src/InputEmulation.cpp index a6daae8309..58d0cee07d 100644 --- a/src/InputEmulation.cpp +++ b/src/InputEmulation.cpp @@ -167,6 +167,13 @@ namespace gamescope } break; + case EIS_EVENT_SCROLL_DISCRETE: + { + m_flScrollAccum[0] += eis_event_scroll_get_discrete_dx( pEisEvent ) / 120.0; + m_flScrollAccum[1] += eis_event_scroll_get_discrete_dy( pEisEvent ) / 120.0; + } + break; + case EIS_EVENT_KEYBOARD_KEY: { wlserver_lock(); @@ -186,7 +193,17 @@ namespace gamescope case EIS_EVENT_FRAME: { - // Not used currently, maybe we want to accum scroll? + double flScrollX = m_flScrollAccum[0]; + double flScrollY = m_flScrollAccum[1]; + m_flScrollAccum[0] = 0.0; + m_flScrollAccum[1] = 0.0; + + if ( flScrollX == 0.0 && flScrollY == 0.0 ) + return; + + wlserver_lock(); + wlserver_mousewheel( flScrollX, flScrollY, ++s_uSequence ); + wlserver_unlock(); } break; diff --git a/src/InputEmulation.h b/src/InputEmulation.h index 9dde5d6f5d..1084f9ddf3 100644 --- a/src/InputEmulation.h +++ b/src/InputEmulation.h @@ -19,5 +19,7 @@ namespace gamescope private: eis *m_pEis = nullptr; int m_nFd = -1; + + double m_flScrollAccum[2]{}; }; }