Fix: Make the Go web console wheel scroll correctly

The Go web server's mouse handler read deltaY as an int, so json.Unmarshal
rejected the entire mouse message whenever the browser reported a
fractional delta (Chrome's smooth scrolling splits one 100px notch into
33.33 + 33.33 + 33.34), and the wheel was dead while clicks and moves
kept working. Treating every event as one notch was wrong the other way:
it scrolled three to four times too far, and sub-pixel deltas from a
touchpad truncated to zero.

The server now accumulates the delta in notch units per client and
injects WM_MOUSEWHEEL only once a whole notch is reached. The remainder
is rounded, not truncated, so a float sum of 99.99px still lands on
exactly one notch and the first notch fires halfway through a physical
one, like native scrolling. The page forwards e.deltaMode so line and
page based deltas convert correctly, and touchpad flings are capped at
20 notches per event.

Verified against a live Go server with a connected client: 100px sends
one packet, three 33.33px events send one, 53.33px sends one, sub-pixel
events accumulate to none, and the wParam is -120 down / +120 up with
SendToScreen returning no error. The MFC web console is untouched.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-10-26 17:10:09 +01:00
1 parent c271911fcb
commit 6236ed1eb4
4 files changed
+156 -17

No files matched your search

+4 -2
View File
@@ -5854,13 +5854,15 @@
};
}
function sendMouse(type, x, y, button, delta) {
function sendMouse(type, x, y, button, delta, deltaMode) {
if (!controlEnabled) return; // Control mode required
// Update cursor overlay position
updateCursorOverlay(x, y);
if (ws && ws.readyState === WebSocket.OPEN && token) {
const msg = { cmd: 'mouse', token, id: currentDeviceId(), type, x, y, button: button || 0 };
if (delta !== undefined) msg.delta = delta;
// deltaMode: 0=像素 1=行 2=页。服务端按它把 delta 换算成滚轮刻度。
if (deltaMode !== undefined) msg.deltaMode = deltaMode;
ws.send(JSON.stringify(msg));
}
}
@@ -6495,7 +6497,7 @@
canvas.addEventListener('wheel', function(e) {
e.preventDefault();
const pos = getMousePos(e);
sendMouse('wheel', pos.x, pos.y, 0, e.deltaY);
sendMouse('wheel', pos.x, pos.y, 0, e.deltaY, e.deltaMode);
}, { passive: false });
canvas.addEventListener('contextmenu', e => e.preventDefault());