feat(input): #89 cursor capture — Input.cursor_mode (hide/lock/confine)
All checks were successful
bootstrap / cfree-fixpoint (push) Successful in 22s
ci / build-and-test (push) Successful in 2m24s
commit-lint / conventional-commits (push) Successful in 5s
docs / build-and-deploy (push) Successful in 29s

A windowed action game can hide the OS cursor and lock/confine the mouse to the
window. Input.cursor_mode(mode): 0 normal, 1 hidden (draw your own reticle),
2 locked (hidden + dissociated — the mouse feeds relative motion via
Input.mouse_dx/dy and Input.mouse_x/y is a clamped virtual cursor, FPS/twin-stick
aim), 3 confined (dissociated but visible; the mouse can't leave the window).
The platform auto-releases (shows + reconnects) while the window is not key
(Cmd-Tab) and on close, so the cursor is never left captured. Headless it is a
no-op (DCE'd).

Native macOS impl in cocoa.ll: [NSCursor hide]/[unhide] (ref-counted, toggled
only on change so the count stays balanced across focus changes),
CGAssociateMouseAndMouseCursorPosition, and CGGetLastMouseDelta for the relative
virtual cursor, behind a new win_cursor_mode intrinsic. Windowed-only behaviour
(not in the headless golden suite); example compiles headless and links
windowed. Full suite 115/0, fixpoint holds.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-02 08:06:34 +03:00
parent f3f1336882
commit 3eb5447f74
11 changed files with 26543 additions and 26240 deletions

View file

@ -402,6 +402,20 @@ function input_strength(name: pointer) -> fixed {
return fixed(0)
}
# ---- cursor capture (#89) --------------------------------------------------
# Set the OS cursor mode for a windowed game:
# 0 normal — cursor visible and free (default).
# 1 hidden — cursor hidden while the window is focused (draw your own reticle).
# 2 locked — hidden + dissociated; the mouse feeds relative motion through
# Input.mouse_dx/dy and Input.mouse_x/y is a clamped virtual cursor
# (the FPS / twin-stick capture mode).
# 3 confined — dissociated but visible; the mouse cannot leave the window.
# The platform auto-releases (shows + reconnects) while the window is not key
# (Cmd-Tab) and on close. Headless / non-windowed: a no-op.
function input_cursor_mode(mode: int) -> void {
if is_windowed() { win_cursor_mode(mode) }
}
# ---- mouse -----------------------------------------------------------------
function input_mouse_x() -> int { in_init(); return in_mx }
function input_mouse_y() -> int { in_init(); return in_my }