plat/plock.rs#
Source: lib/plat/plock.rs
plock -- (G7a) the pointer lock of a window and the raw relative motion while it holds it,
the part every platform shares
win_pointer_lock(w, on) -> PointerLock lock the pointer to window w (on) or let it go;
the state right after the call
win_pointer_lock_state(w) -> PointerLock the state now
win_raw_motion_take(w) -> (dx, dy) the raw motion since the last call (0, 0 when none
or w does not hold the lock)
E_POINTER_LOCK the state changed (data 1: locked now, 0: not)
E_RAW_MOTION raw motion waits (one event until it is taken)
While a window holds the lock the pointer is hidden, stays where it is (or inside the window)
and its motion comes raw: without the system's acceleration where the platform has it, in the
device's counts. Per platform:
Windows Raw Input (WM_INPUT of usage page 1, usage 2), the cursor clipped to the middle of
the window (ClipCursor) and hidden; motion in mouse counts; absolute devices (a
remote desktop, a tablet, some virtual machines) as differences of their positions
in pixels (win_plock.rs)
Wayland zwp_pointer_constraints_v1.lock_pointer and zwp_relative_pointer_v1's
unaccelerated motion; Unsupported when the compositor lacks one of them
(linux_wl_lock.rs)
X11 XInput 2.1 raw motion (XI_RawMotion: the device's values before acceleration) and a
pointer grab confined to the window with an invisible cursor; Unsupported without
XInput 2, Refused when another client holds a grab (linux_x11_lock.rs)
macOS CGAssociateMouseAndMouseCursorPosition(false), the cursor hidden; motion from the
events' deltaX / deltaY (points, after the system's acceleration) (apple_mac.rs)
browser requestPointerLock on the canvas (unadjustedMovement where the browser has it:
raw; else the browser's accelerated CSS pixels); the browser grants it only from a
user's gesture: Pending until the next press in the page (web_windows.rs, loader.js)
Android, iOS Unsupported (touch controls are a later stage)
The lock always lets go: Esc (the key goes to the lock, not to the app; the browser owns Esc
itself), the window losing the keyboard focus, being minimized or closed, and
win_pointer_lock(w, false). It is never taken back by itself: after a release the app asks
again (a click "to play"). A request while the window has no focus waits (Pending) and takes
effect when it gets the focus. One window holds the lock at a time (there is one pointer):
asking for another lets the first go.
enum PointerLock(G7a) the state of a window's pointer lock (win_pointer_lock, ui.pointer_lock)Off-- not locked: never asked for, or let go (by the app, Esc, the focus going elsewhere, the window minimized or closed)Pending-- asked for, not granted yet: the window has no focus yet, the browser waits for the next press in the page, the Wayland compositor has not confirmed itLocked-- locked: the pointer is hidden and stays put, win_raw_motion_take has its motionUnsupported-- this platform or display cannot lock the pointer: Android, iOS; a Wayland compositor without zwp_pointer_constraints_v1 or zwp_relative_pointer_manager_v1, an X server without XInput 2.1Refused-- the system said no: the browser's pointerlockerror, another X11 client holds a grab, no such window
fn win_pointer_lock(w: i32, on: bool) -> PointerLock(G7a) lock the pointer to window w (on) or let it go (off) -> the state right after the call: Locked at once where the platform grants it, Pending while it waits (see PointerLock), Off after a release. E_POINTER_LOCK follows every change. The pointer is hidden while locked and its motion comes through win_raw_motion_take; Esc, the focus going elsewhere, minimizing and closing the window always let it go. A window that is not the one holding (or waiting for) the lock lets nothing go with offfn win_pointer_lock_state(w: i32) -> PointerLock(G7a) the state of window w's pointer lock (Off for a window that neither holds nor waits for it; Unsupported / Refused stay until the next request)fn win_raw_motion_take(w: i32) -> (f64, f64)(G7a) the raw relative motion of window w's pointer since the last call, while w holds the lock: (dx, dy), right and down positive, in the device's counts where the platform gives them (Windows' Raw Input, Wayland's unaccelerated motion, X11's raw values, the browser with unadjustedMovement), else in its accelerated pixels (macOS' deltas, the browser without it); (0, 0) when there is none. E_RAW_MOTION says that some waitsfn pointer_lock_test(w: i32, s: PointerLock)(test aid, plattest --test input) the shared state without a platform: window w's lock is in state s now, as a backend says it (E_POINTER_LOCK on a change)fn raw_motion_test(w: i32, dx: f64, dy: f64)(test aid) raw motion of window w as a backend reports itfn pointer_lock_key_test(vk: u32, down: bool) -> bool(test aid) a key as a backend asks the lock about it -> true: the key is the lock's (Esc)fn raw_mouse_decode(rec: &[u8]) -> Option<(u16, i32, i32)>(G7a) the motion of a Windows RAWINPUT record of a mouse (the bytes GetRawInputData fills: the 64-bit RAWINPUTHEADER, then RAWMOUSE) -> (usFlags, lLastX, lLastY); None for another device or a short record. MOUSE_MOVE_ABSOLUTE (usFlags bit 0) gives positions 0..65535 instead of motion (MOUSE_VIRTUAL_DESKTOP, bit 1: of the whole desktop)fn raw_abs_delta(prev: Option<[i32; 2]>, now: [i32; 2], span: [i32; 2]) -> (f64, f64)(G7a) the motion of an absolute pointer (a remote desktop, a tablet, a virtual machine) between two of its positions (0..65535 across the screen or the desktop ofspanpixels) -> pixels; the first position after a pause (prev None) moves nothingfn xi_raw_decode(ev: &[u8]) -> Option<(u16, u16, u32, f64, f64, u32)>(G7a) the raw motion of an XInput 2 raw event (XI_RawMotion, the whole GenericEvent as the server sends it) -> (deviceid, sourceid, time, raw value of valuator 0, of valuator 1, which of the two it carries: bit 0 / bit 1); None for a short or malformed event. The raw values (FP3232, before acceleration) follow the mask and the transformed valuesfn wl_fixed(v: i32) -> f64(G7a) Wayland's fixed-point value (24.8) as a number