Skip to content

GameInput shim: keyboard pad right stick reads raw mouse input, cursor kept in the window, LEONIDA_MOUSE_SENSITIVITY - #2162

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Cozmaaa:raw-mouse
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Cozmaaa:raw-mouse

Conversation

@Cozmaaa

@Cozmaaa Cozmaaa commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in #2078: #2078 (comment) (new item, no ID yet)

Follow-up to #875 (merged), the keyboard pad.

What and why

The keyboard pad's right stick followed GetCursorPos deltas, so it stopped turning once the cursor reached the edge of the screen, and Windows' pointer acceleration changed how far it moved. This PR makes three changes:

  • Raw mouse input. When the keyboard pad attaches, the shim starts one thread with a message-only window (HWND_MESSAGE, never shown) that registers for raw mouse input (RAWINPUTDEVICE 0x01/0x02, RIDEV_INPUTSINK).
    • Each relative WM_INPUT movement is added to a running total (atomics). The poll takes the difference of that total, so the existing decay, scaling and clamping are unchanged.
    • Absolute reports (remote desktop, some VMs, pen tablets) are ignored.
    • If creating the window or the registration fails, the shim logs it and falls back to GetCursorPos.
  • Cursor kept in the window. While raw input is on and a window of this process is in the foreground, the cursor is clipped to that window's client area (ClipCursor, re-applied every 100 ms because Windows drops the clip on alt-tab), so a click cannot land on another window.
    • It is released when focus moves away or the pad is turned off.
    • It is never applied with the fallback (it would stop the stick at the window edge) or with a test cursor source.
    • The cursor stays visible: hiding it has to happen on the thread that owns the game's window.
  • LEONIDA_MOUSE_SENSITIVITY (0.1..10, default 1) scales the axis units per count.

docs/gameinput.md covers these changes and adds the env var row and a VERIFY item. If the title registers raw mouse input itself, Windows keeps one target window per device type and process, so the title's registration would replace the shim's; a console title isn't expected to do that.

Tested

  • gameinput_test (CTest gameinput): 190/190 checks, 5 of them new: sensitivity 2 doubles and 0.5 halves the stick, out-of-range values clamp to 10 and 0.1, and unset it is 1 and leaves LEONIDA_DS_TRIGGER_GAIN alone. The existing mouse tests still pass through the fake cursor source.
  • By hand with gameinput_probe --seconds 20 (LEONIDA_KEYBOARD_PAD=always, LEONIDA_MOUSE_SENSITIVITY=2): the log shows raw mouse input on, and the right stick keeps moving while the mouse pushes past the screen edge. The probe's console window belongs to the terminal, so clipping isn't exercised there.
  • Full CTest run: 110/111. The one failure, d3d12_draw ("bundle blend pixel"), doesn't link gameinput.cpp and fails the same way without this change.
  • Windows 11, VS 2026 MSVC, Ninja, RelWithDebInfo, SDL3 3.4.20 through -DLEONIDA_SDL3_FETCH=ON, NVIDIA GeForce RTX 5070 Ti. No GPU work in this change.
  • No game data used.

AI-assisted.

…eeps the cursor in the window

GetCursorPos deltas stop at the screen edge and include pointer
acceleration. A message-only window on its own thread now registers for
raw mouse input (RIDEV_INPUTSINK) and sums the relative counts; the poll
takes the difference of that total. Absolute reports are ignored, and
GetCursorPos stays as the fallback if registration fails.

With raw input on and a window of this process in the foreground, the
cursor is clipped to that window's client area (re-applied every 100 ms),
and released on focus loss or when the pad is turned off.

LEONIDA_MOUSE_SENSITIVITY (0.1..10, default 1) scales the axis units per
count.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the raw-input lifecycle, focus gating, cursor clipping and sensitivity parsing. The fallback stays on GetCursorPos when raw registration is unavailable, the clip is limited to an owned foreground window, and focus loss releases it. The reported test and manual coverage match the change. I found no blocking issue; I did not run tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants