From 54e9be2b53e83cc161407ea5fab01e92ab3dd9cd Mon Sep 17 00:00:00 2001 From: rmschooley Date: Thu, 15 May 2025 03:31:14 -0500 Subject: [PATCH] Update WebRTCVideo.tsx Changed code to improve wheel mouse scrolling. This should allow better performance (including some amount of acceleration) under most browsers. --- ui/src/components/WebRTCVideo.tsx | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/ui/src/components/WebRTCVideo.tsx b/ui/src/components/WebRTCVideo.tsx index cea39da..3f6d913 100644 --- a/ui/src/components/WebRTCVideo.tsx +++ b/ui/src/components/WebRTCVideo.tsx @@ -259,25 +259,22 @@ export default function WebRTCVideo() { (e: WheelEvent) => { if (blockWheelEvent) return; - // Determine if the wheel event is from a trackpad or a mouse wheel - const isTrackpad = Math.abs(e.deltaY) < trackpadThreshold; + // Determine if the wheel event is an accelerable scroll value + const isAccel = Math.abs(e.deltaY) >= 100; - // Apply appropriate sensitivity based on input device - const scrollSensitivity = isTrackpad ? trackpadSensitivity : mouseSensitivity; + // Calculate the accelerable scroll value + const accelScrollValue = e.deltaY / 100; - // Calculate the scroll value - const scroll = e.deltaY * scrollSensitivity; + // Calculate the non-accelerable scroll value + const nonAccelScrollValue = e.deltaY > 0 ? 1: -1; - // Apply clamping - const clampedScroll = Math.max(clampMin, Math.min(clampMax, scroll)); + // Get actual scroll value + const scrollValue = isAccel ? accelScrollValue : nonAccelScrollValue; - // Round to the nearest integer - const roundedScroll = Math.round(clampedScroll); + // Apply clamping (i.e. min and max mouse wheel hardware value) + const clampedScrollValue = Math.max(-128, Math.min(127, scrollValue)); - // Invert the scroll value to match expected behavior - const invertedScroll = -roundedScroll; - - send("wheelReport", { wheelY: invertedScroll }); + send("wheelReport", { wheelY: clampedScrollValue }); // Apply blocking delay setBlockWheelEvent(true);