Skip to content

bugfix(input): Fix touchpad upward scrolling in UI list boxes#2586

Open
afc-afc0 wants to merge 3 commits intoTheSuperHackers:mainfrom
afc-afc0:bugfix/touchpad-scroll-up
Open

bugfix(input): Fix touchpad upward scrolling in UI list boxes#2586
afc-afc0 wants to merge 3 commits intoTheSuperHackers:mainfrom
afc-afc0:bugfix/touchpad-scroll-up

Conversation

@afc-afc0
Copy link
Copy Markdown

Summary

  • Fixes touchpad upward scrolling in UI list boxes (GadgetListBox) where the list momentarily scrolls up then jumps back down - Preserves wheel delta sign when normalizing, so touchpad's small continuous deltas are no longer truncated to 0 and misidentified as downward scroll
  • Mouse wheel behavior is completely unchanged

Root Cause

In Mouse::createStreamMessages(), the wheel delta was divided by MOUSE_WHEEL_DELTA (120) before being sent as a message argument.
Touchpad devices send small deltas (e.g. +30) that truncate to 0 on integer division. In WindowXlat.cpp, the direction check if (argument > 0) maps 0 to GWM_WHEEL_DOWN, causing upward touchpad scroll to be treated as downward.

Fix

Clamp the normalized wheel delta to at least 1 or -1 based on the original sign of wheelPos, ensuring the scroll direction is
always preserved. Only Mouse.cpp is changed — no consumers need modification.

Test plan

  • Verified mouse wheel scrolls up and down correctly in UI list boxes
  • Verified mouse wheel zoom in/out works correctly on the map
  • Verified no regression in combo box scrolling
  • Verified touchpad upward scrolling no longer jumps back down

Preserve wheel delta sign when normalizing for touchpad scroll direction
detection. Touchpad devices send small continuous deltas that were
truncated to 0 by integer division with MOUSE_WHEEL_DELTA, causing
upward scroll to be misidentified as downward scroll. Clamp the
normalized value to at least 1 or -1 based on the original sign.
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 12, 2026

Greptile Summary

This PR fixes a bug where touchpad upward scrolling in UI list boxes would appear to momentarily scroll up and immediately snap back down. The root cause was integer division truncating small touchpad deltas (e.g., +30 / 120 = 0), which caused the direction check argument > 0 to misclassify upward touchpad scrolls as downward. The fix changes appendIntegerArgument to appendRealArgument with float division in Mouse.cpp, preserving fractional values so the sign is never lost. All consumers in both Generals/ and GeneralsMD/ are consistently updated to read .real instead of .integer.

Confidence Score: 5/5

Safe to merge — minimal, targeted fix with no regressions for standard mouse wheel behavior.

The change is mechanically correct: float division preserves sign for small touchpad deltas, all consumers are consistently updated to read .real, and the winProcessMouseEvent signature already accepted void* so no ABI impact. Standard mouse wheel behavior (delta=120 → 1.0f) is numerically identical to the old integer result. No P0/P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
Core/GameEngine/Source/GameClient/Input/Mouse.cpp Core fix: changes appendIntegerArgument(wheelPos / MOUSE_WHEEL_DELTA) to appendRealArgument(wheelPos / (Real)MOUSE_WHEEL_DELTA), preserving sign for small touchpad deltas that integer-divide to 0.
Generals/Code/GameEngine/Include/Common/MessageStream.h Comment on MSG_RAW_MOUSE_WHEEL updated from integer to Real spin to match the new argument type — documentation-only change.
GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h Same documentation-only comment update as the Generals variant — MSG_RAW_MOUSE_WHEEL now correctly documents Real spin argument.
Generals/Code/GameEngine/Source/GameClient/MessageStream/WindowXlat.cpp Updated two read sites from .integer to .real for MSG_RAW_MOUSE_WHEEL argument 1: direction check in rawMouseToWindowMessage and the wheelPos variable in the main handler — both correctly aligned with the new Real storage type.
GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/WindowXlat.cpp Identical consumer update to the Generals variant — .integer to .real for MSG_RAW_MOUSE_WHEEL argument 1 in both read sites.
Generals/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp Updated MSG_RAW_MOUSE_WHEEL handler to read spin as .real instead of .integer; zoom calculation -spin * ZoomHeightPerSecond is unchanged and now benefits from proportional touchpad zoom values.
GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp Identical update to Generals variant — spin now read as .real, enabling proportional touchpad zoom via the same -spin * ZoomHeightPerSecond expression.

Sequence Diagram

sequenceDiagram
    participant TP as Touchpad (Δ=+30)
    participant MC as Mouse::createStreamMessages()
    participant MS as MessageStream
    participant WX as WindowXlat / LookAtXlat
    participant WM as WindowManager / TacticalView

    Note over MC: OLD (integer division)
    TP->>MC: wheelPos = +30
    MC->>MS: appendIntegerArgument(30/120 = 0)
    MS->>WX: MSG_RAW_MOUSE_WHEEL arg[1].integer = 0
    WX->>WM: 0 > 0 is false → GWM_WHEEL_DOWN ❌

    Note over MC: NEW (float division)
    TP->>MC: wheelPos = +30
    MC->>MS: appendRealArgument(30.0f/120.0f = 0.25f)
    MS->>WX: MSG_RAW_MOUSE_WHEEL arg[1].real = 0.25f
    WX->>WM: 0.25f > 0 is true → GWM_WHEEL_UP ✅
Loading

Reviews (3): Last reviewed commit: "Apply float based fix" | Re-trigger Greptile

@DevGeniusCode
Copy link
Copy Markdown

Good catch, closes #2584
I checked mine and it did solve the issue
Need to replicate to vanilla generals

@DevGeniusCode DevGeniusCode added GUI For graphical user interface Minor Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour labels Apr 12, 2026
@xezon xezon added Bug Something is not working right, typically is user facing Gen Relates to Generals labels Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something is not working right, typically is user facing Gen Relates to Generals GUI For graphical user interface Minor Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Choppy/unsmooth scrolling UP using laptop touchpad (GadgetListBox)

3 participants