From 29710fb2ececee980e3923ed8f5f002ce219aa94 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Fri, 26 May 2023 17:06:33 +0100 Subject: [PATCH] vr_session: Support for trackpad scrolling --- src/main.cpp | 2 ++ src/vr_session.cpp | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 14ce7c1..32a5209 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -89,6 +89,7 @@ const struct option *gamescope_options = (struct option[]){ { "vr-overlay-physical-width", required_argument, nullptr, 0 }, { "vr-overlay-physical-curvature", required_argument, nullptr, 0 }, { "vr-overlay-physical-pre-curve-pitch", required_argument, nullptr, 0 }, + { "vr-scroll-speed", required_argument, nullptr, 0 }, #endif // wlserver options @@ -195,6 +196,7 @@ const char usage[] = " --vr-overlay-physical-width Sets the physical width of our VR overlay in metres\n" " --vr-overlay-physical-curvature Sets the curvature of our VR overlay\n" " --vr-overlay-physical-pre-curve-pitch Sets the pre-curve pitch of our VR overlay\n" + " --vr-scrolls-speed Mouse scrolling speed of trackpad scroll in VR. Default: 8.0\n" "\n" #endif "Debug options:\n" diff --git a/src/vr_session.cpp b/src/vr_session.cpp index 2da4026..ac9ee20 100644 --- a/src/vr_session.cpp +++ b/src/vr_session.cpp @@ -31,6 +31,8 @@ struct OpenVRSession float flPhysicalWidth = 2.0f; float flPhysicalCurvature = 0.0f; float flPhysicalPreCurvePitch = 0.0f; + float flScrollSpeed = 8.0f; + float flScrollAccum[2] = { 0.0f, 0.0f }; vr::VROverlayHandle_t hOverlay = vr::k_ulOverlayHandleInvalid; vr::VROverlayHandle_t hOverlayThumbnail = vr::k_ulOverlayHandleInvalid; struct wlserver_input_method *pIME = nullptr; @@ -91,6 +93,8 @@ bool vr_init(int argc, char **argv) GetVR().flPhysicalCurvature = atof( optarg ); } else if (strcmp(opt_name, "vr-overlay-physical-pre-curve-pitch") == 0) { GetVR().flPhysicalPreCurvePitch = atof( optarg ); + } else if (strcmp(opt_name, "vr-scroll-speed") == 0) { + GetVR().flScrollSpeed = atof( optarg ); } break; case '?': @@ -144,6 +148,7 @@ bool vrsession_init() vr::VROverlay()->SetOverlayFlag( GetVR().hOverlay, vr::VROverlayFlags_EnableControlBarKeyboard, GetVR().bEnableControlBarKeyboard ); vr::VROverlay()->SetOverlayFlag( GetVR().hOverlay, vr::VROverlayFlags_EnableControlBarClose, GetVR().bEnableControlBarClose ); vr::VROverlay()->SetOverlayFlag( GetVR().hOverlay, vr::VROverlayFlags_WantsModalBehavior, GetVR().bModal ); + vr::VROverlay()->SetOverlayFlag( GetVR().hOverlay, vr::VROverlayFlags_SendVRSmoothScrollEvents, true ); vrsession_update_touch_mode(); vr::VROverlay()->SetOverlayWidthInMeters( GetVR().hOverlay, GetVR().flPhysicalWidth ); @@ -315,6 +320,22 @@ static void vrsession_input_thread() break; } + case vr::VREvent_ScrollSmooth: + { + wlserver_lock(); + + GetVR().flScrollAccum[0] += -vrEvent.data.scroll.xdelta * GetVR().flScrollSpeed; + GetVR().flScrollAccum[1] += -vrEvent.data.scroll.ydelta * GetVR().flScrollSpeed; + + float dx, dy; + GetVR().flScrollAccum[0] = modf( GetVR().flScrollAccum[0], &dx ); + GetVR().flScrollAccum[1] = modf( GetVR().flScrollAccum[1], &dy ); + + wlserver_mousewheel( dx, dy, timestamp ); + wlserver_unlock(); + break; + } + case vr::VREvent_ButtonPress: { vr::EVRButtonId button = (vr::EVRButtonId)vrEvent.data.controller.button;