Skip to content

Commit e95e30e

Browse files
authored
Re-add scroll blocking/throttling (#544)
1 parent eaa5849 commit e95e30e

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

ui/src/components/WebRTCVideo.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export default function WebRTCVideo() {
6767
const hdmiError = ["no_lock", "no_signal", "out_of_range"].includes(hdmiState);
6868
const isVideoLoading = !isPlaying;
6969

70+
const [blockWheelEvent, setBlockWheelEvent] = useState(false);
71+
7072
// Misc states and hooks
7173
const disableVideoFocusTrap = useUiStore(state => state.disableVideoFocusTrap);
7274
const [send] = useJsonRpc();
@@ -281,6 +283,11 @@ export default function WebRTCVideo() {
281283

282284
const mouseWheelHandler = useCallback(
283285
(e: WheelEvent) => {
286+
287+
if (settings.scrollThrottling && blockWheelEvent) {
288+
return;
289+
}
290+
284291
// Determine if the wheel event is an accel scroll value
285292
const isAccel = Math.abs(e.deltaY) >= 100;
286293

@@ -300,8 +307,14 @@ export default function WebRTCVideo() {
300307
const invertedScrollValue = -clampedScrollValue;
301308

302309
send("wheelReport", { wheelY: invertedScrollValue });
310+
311+
// Apply blocking delay based of throttling settings
312+
if (settings.scrollThrottling && !blockWheelEvent) {
313+
setBlockWheelEvent(true);
314+
setTimeout(() => setBlockWheelEvent(false), settings.scrollThrottling);
315+
}
303316
},
304-
[send],
317+
[send, blockWheelEvent, settings],
305318
);
306319

307320
const resetMousePosition = useCallback(() => {

ui/src/hooks/stores.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ interface SettingsState {
314314
keyboardLedSync: KeyboardLedSync;
315315
setKeyboardLedSync: (sync: KeyboardLedSync) => void;
316316

317+
scrollThrottling: number;
318+
setScrollThrottling: (value: number) => void;
319+
317320
showPressedKeys: boolean;
318321
setShowPressedKeys: (show: boolean) => void;
319322
}
@@ -354,6 +357,9 @@ export const useSettingsStore = create(
354357
keyboardLedSync: "auto",
355358
setKeyboardLedSync: sync => set({ keyboardLedSync: sync }),
356359

360+
scrollThrottling: 0,
361+
setScrollThrottling: value => set({ scrollThrottling: value }),
362+
357363
showPressedKeys: true,
358364
setShowPressedKeys: show => set({ showPressedKeys: show }),
359365
}),

ui/src/routes/devices.$id.settings.mouse.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useFeatureFlag } from "../hooks/useFeatureFlag";
1414
import { cx } from "../cva.config";
1515

1616
import { SettingsItem } from "./devices.$id.settings";
17+
import { SelectMenuBasic } from "@components/SelectMenuBasic";
1718

1819
export default function SettingsMouseRoute() {
1920
const hideCursor = useSettingsStore(state => state.isCursorHidden);
@@ -26,6 +27,19 @@ export default function SettingsMouseRoute() {
2627

2728
const [jiggler, setJiggler] = useState(false);
2829

30+
const scrollThrottling = useSettingsStore(state => state.scrollThrottling);
31+
const setScrollThrottling = useSettingsStore(
32+
state => state.setScrollThrottling,
33+
);
34+
35+
const scrollThrottlingOptions = [
36+
{ value: "0", label: "Off" },
37+
{ value: "10", label: "Low" },
38+
{ value: "25", label: "Medium" },
39+
{ value: "50", label: "High" },
40+
{ value: "100", label: "Very High" },
41+
];
42+
2943
const [send] = useJsonRpc();
3044

3145
useEffect(() => {
@@ -65,6 +79,21 @@ export default function SettingsMouseRoute() {
6579
/>
6680
</SettingsItem>
6781

82+
<SettingsItem
83+
title="Scroll Throttling"
84+
description="Reduce the frequency of scroll events"
85+
>
86+
<SelectMenuBasic
87+
size="SM"
88+
label=""
89+
className="max-w-[292px]"
90+
value={scrollThrottling}
91+
fullWidth
92+
onChange={e => setScrollThrottling(parseInt(e.target.value))}
93+
options={scrollThrottlingOptions}
94+
/>
95+
</SettingsItem>
96+
6897
<SettingsItem
6998
title="Jiggler"
7099
description="Simulate movement of a computer mouse. Prevents sleep mode, standby mode or the screensaver from activating"

0 commit comments

Comments
 (0)