Scroll with the mouse wheel in the game's menus and along the D-pad strips

The wheel did nothing outside the map. Now each notch is one step of the stick a gamepad player would move: in a menu
with the game's focus box (the inventory, shops, Options, the save list) the focus moves up or down, and while a D-pad
strip (weapons, shields, bows, materials) is held open the choice moves left or right. The strip has no focus box
while it is held, so it is found by its open screen, ShortCut_00, as the map is. The wheel now also counts while the
cursor is released over the window, where the menus have the pointer. Input scripts take WHEEL lines and a recording
writes them, and a script's one-shot MOUSE or WHEEL line goes in at the first poll at or after its tick instead of
being lost when a poll skips that tick.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
itaskaev2andClaude Opus 5.5 committed 2026-11-11 00:23:48 +01:00
1 parent 7a37fc3c34
commit a10c546a06
7 files changed
+127 -37

No files matched your search

+5 -2
View File
@@ -174,7 +174,8 @@ The horizontal quick lists (D-pad up/left/right: materials, shields and weapons)
with at least 32 ms of neutral between them. At sensitivity 1, 32 horizontal counts request a step; a large flick
cannot queue continued scrolling after the mouse stops. Vertical movement is ignored in these lists. Switching or
releasing a selector resets its cursor/step state without sending the last movement to the camera. Selector input is
not consumed by the direct camera or Ultrahand hooks.
not consumed by the direct camera or Ultrahand hooks. The scroll wheel steps these lists too: each notch is one step,
away from you to the left, towards you to the right.
To detach a fused part from what Ultrahand holds, shake the mouse left and right, or press G (`bind_SHAKE`). A press
swings the right stick left and right for 0.8 s, holding the key keeps it swinging. With `mouse_mode = direct` a shake
of the mouse while Ultrahand holds an object swings the right stick with it: once the swings (10 degrees of camera turn
@@ -199,7 +200,7 @@ The stick direction bits (`StickLLeft` to `StickRDown`) are derived from the sti
## Mouse in the game's menus
On game 1.4.3, while one of the game's menus has its focus box (the frame the d-pad moves: the title, the save list, the inventory and its System tab, Options, shops, dialogue choices), the cursor is released from the mouse camera and shown in the middle of the window. A focus gap of up to 300 ms (a tab switch, a popup opening: the game drops the focus box for a frame or two) keeps the pointer where it is instead of capturing and centring it again. The item under the pointer takes the focus as if the d-pad had moved there, with the game's highlight, sound and description; a left click is A on it, a right click is B. The middle and side mouse buttons keep their bindings (bound to L and R they turn the tabs), and T presses Y (sort). The keys and the pad keep working, and the focus moves only when the pointer moves. This happens only while the keyboard and mouse are the device used last: after a gamepad button press or a stick pushed past half way the menus are as on the console, with no pointer, until the mouse moves or a key is pressed (`input_kbm_last` in `runtime/input.c`). The ability wheel, the d-pad strips, Autobuild and the Purah Pad's camera stay gameplay: the mouse keeps the camera there. The map has no focus box; it is found in `eui::ScreenMgr`'s list of open screens (every 100 ms: the Purah Pad's frame `AppMenuOverlay_00` with `AppMap_00` and the menu background `AppMenuBG_00`), and there the mouse moves the map's cursor as the left stick does, with the cursor still captured, and the scroll wheel zooms: each notch is a full-tilt push of the right stick (the map's zoom) for 100 ms with 50 ms of neutral after it, up (in) for a turn away from you; a fast scroll's notches wait their turn (at most four), a turn the other way drops them. The Scope opens the same map screen without the menu background and keeps the mouse camera. When the menu closes the cursor is captured again.
On game 1.4.3, while one of the game's menus has its focus box (the frame the d-pad moves: the title, the save list, the inventory and its System tab, Options, shops, dialogue choices), the cursor is released from the mouse camera and shown in the middle of the window. A focus gap of up to 300 ms (a tab switch, a popup opening: the game drops the focus box for a frame or two) keeps the pointer where it is instead of capturing and centring it again. The item under the pointer takes the focus as if the d-pad had moved there, with the game's highlight, sound and description; a left click is A on it, a right click is B. The middle and side mouse buttons keep their bindings (bound to L and R they turn the tabs), and T presses Y (sort). The scroll wheel moves the focus up and down, one step a notch (a full-tilt push of the left stick for 70 ms with 50 ms of neutral after it, up for a turn away from you), so a long list of items scrolls without moving the pointer; `menu_cursor = 0` turns this off with the pointer. The keys and the pad keep working, and the focus moves with the pointer only when the pointer moves. This happens only while the keyboard and mouse are the device used last: after a gamepad button press or a stick pushed past half way the menus are as on the console, with no pointer, until the mouse moves or a key is pressed (`input_kbm_last` in `runtime/input.c`). The ability wheel, the d-pad strips, Autobuild and the Purah Pad's camera stay gameplay: the mouse keeps the camera there. The map has no focus box; it is found in `eui::ScreenMgr`'s list of open screens (every 100 ms: the Purah Pad's frame `AppMenuOverlay_00` with `AppMap_00` and the menu background `AppMenuBG_00`), and there the mouse moves the map's cursor as the left stick does, with the cursor still captured, and the scroll wheel zooms: each notch is a full-tilt push of the right stick (the map's zoom) for 100 ms with 50 ms of neutral after it, up (in) for a turn away from you; a fast scroll's notches wait their turn (at most four), a turn the other way drops them. The Scope opens the same map screen without the menu background and keeps the mouse camera. When the menu closes the cursor is captured again.
`runtime/menu_cursor.c` reads eui's screens at each pad read and moves the focus with the writes `eui::BoxCursorMgr::moveBoxCursor` makes, so no game code is called. `menu_cursor = 0` (`TOTK_MENU_CURSOR=0`, live; the *Mouse in the game's menus* row of the Controls tab) turns it off; `TOTK_MENU_CURSOR_LOG=1` logs every screen it reads (by default the first six), with the layout size, the node count and the hit panes it uses.
@@ -220,6 +221,8 @@ Bridges that output a ViGEm DualShock 4 (ProCon2Windows, connectyourpro as teste
@<ms> <button> [hold_ms] # timed on the world clock
@<ms> LSTICK|RSTICK <x> <y> [hold_ms]
@<ms> MOUSE <dx> <dy>
<frame> WHEEL <notches> # scroll wheel notches, once; + away from the player
@<ms> WHEEL <notches>
```
`<frame>` counts 60 Hz ticks of game time since the first frame (presented frames at 60 fps), so the title menus get the presses at the same game time at any frame limit. `@<ms>` counts milliseconds of the world clock: game time stepped since the end of the first save load (the player leaves the title screen's origin), so a timed event lands at the same game time at any frame rate and load length. A later load, such as fast travel, still shifts what follows. In a script with timed lines the untimed ones stop when the world clock starts, as the load ends at another tick in each run. Each event logs once (`input: script frame N tick T: A`). `tools/input/load_save.txt` loads the first save from the title screen.
+83 -24
View File
@@ -57,7 +57,8 @@ static const SDL_GamepadButton pad_sdl[PAD_COUNT] = {
[PAD_LPADDLE2] = SDL_GAMEPAD_BUTTON_LEFT_PADDLE2, [PAD_RPADDLE2] = SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2,
};
// TOTK_INPUT_SCRIPT=<file>: lines "<frame> <button> [hold]" or "<frame> LSTICK|RSTICK <x> <y> [hold]", ORed into the real input.
// TOTK_INPUT_SCRIPT=<file>: lines "<frame> <button> [hold]", "<frame> LSTICK|RSTICK <x> <y> [hold]", "<frame> MOUSE
// <dx> <dy>" or "<frame> WHEEL <notches>" (+ away from the player), ORed into the real input.
// <frame> and its hold are 60 Hz ticks of game time since the first present (frame_step_ticks: presents at 60 fps), so
// the title menus get the presses at the same game time at any frame limit. A line "@<ms> ..." is timed instead: <ms>
// and its hold are milliseconds of the world clock (frame_step_world_us, game time since the loaded save's first
@@ -74,6 +75,7 @@ static ScriptEv *script_ev;
static int script_n, script_state; // 0 not loaded, 1 loaded
static int script_mixed; // the script has timed lines: its untimed ones end where the world clock starts
static int32_t script_mouse[2]; // one-shot raw counts, consumed by the camera hook; under lock
static int32_t script_wheel; // one-shot wheel notches, taken with the real ones (wheel_stick); under lock
static void script_load(void) {
script_state = 1;
@@ -96,7 +98,11 @@ static void script_load(void) {
ScriptEv e = {.at = (uint64_t)(at * unit + 0.5), .hold = timed ? 66667 : 4, .bit = -1, .timed = timed};
long a, b;
double c;
if (!strcmp(name, "MOUSE") || !strcmp(name, "LSTICK") || !strcmp(name, "RSTICK")) {
if (!strcmp(name, "WHEEL")) {
if (sscanf(line + off, "%ld", &a) != 1) { rt_log("input: script line %d: WHEEL needs notches", ln); continue; }
e.stick = 4, e.x = (int32_t)a, e.hold = 1; // one turn, never held
snprintf(e.text, sizeof e.text, "WHEEL %d", e.x);
} else if (!strcmp(name, "MOUSE") || !strcmp(name, "LSTICK") || !strcmp(name, "RSTICK")) {
int n = sscanf(line + off, "%ld %ld %lf", &a, &b, &c);
if (n < 2) { rt_log("input: script line %d: %s needs x y [hold]", ln, name); continue; }
e.stick = name[0] == 'M' ? 3 : name[0] == 'L' ? 1 : 2; e.x = (int32_t)a; e.y = (int32_t)b;
@@ -131,14 +137,17 @@ static void script_apply(uint64_t *b, int32_t sl[2], int32_t sr[2]) {
ScriptEv *e = &script_ev[i];
if (e->timed ? w < 0 : script_mixed && w >= 0) continue;
uint64_t now = e->timed ? (uint64_t)w : tick;
if (now < e->at || (now >= e->at + e->hold && (e->logged || !e->timed))) continue;
if (e->stick == 3 && e->logged) continue;
// A one-shot (MOUSE, WHEEL) goes in at the first poll at or after its time: a poll that skips a tick (the
// game below 60 fps) would otherwise lose it
if (e->stick >= 3 ? e->logged || now < e->at
: now < e->at || (now >= e->at + e->hold && (e->logged || !e->timed))) continue;
if (!e->logged) {
e->logged = 1;
if (e->timed) rt_log("input: script frame %llu at %.1f ms: %s", (unsigned long long)fr, w / 1000.0, e->text);
else rt_log("input: script frame %llu tick %llu: %s", (unsigned long long)fr, (unsigned long long)tick, e->text);
}
if (e->stick == 3) {
if (e->stick == 4) script_wheel += e->x;
else if (e->stick == 3) {
int64_t x = (int64_t)script_mouse[0] + e->x, y = (int64_t)script_mouse[1] + e->y;
script_mouse[0] = (int32_t)(x < INT32_MIN ? INT32_MIN : x > INT32_MAX ? INT32_MAX : x);
script_mouse[1] = (int32_t)(y < INT32_MIN ? INT32_MIN : y > INT32_MAX ? INT32_MAX : y);
@@ -261,6 +270,17 @@ void input_direct_mouse_sample(int enabled, int32_t *dx, int32_t *dy) {
plat_mutex_unlock(&lock);
}
// A turn of the real wheel as a WHEEL line of the recording (one-shot, as a MOUSE line). Under lock.
static void rec_wheel(int32_t notches) {
if (rec_state != 1) return;
char what[32];
snprintf(what, sizeof what, "WHEEL %d", notches);
int64_t w = frame_step_world_us();
uint64_t tick = frame_step_ticks();
rec_line(tick, w, tick + 1, w, what);
fflush(rec);
}
static float mouse_sens = -1; // TOTK_MOUSE_SENS, 0 = mouse camera off; live (cfg_version)
static unsigned mouse_sens_seen;
@@ -541,35 +561,76 @@ static int32_t shake_stick(int held) {
return (now - from) / SHAKE_SIDE_NS % 2 ? STICK_MAX : -STICK_MAX;
}
// The scroll wheel on the Purah Pad's map, which zooms with the right stick's y (up: in): each notch is a full-tilt
// pulse of MAP_ZOOM_PULSE_NS on that stick with MAP_ZOOM_GAP_NS of neutral after it, so a step of the zoom and a
// held zoom both see one notch as one push. A fast scroll's notches wait their turn (at most MAP_ZOOM_QUEUE), a turn the
// other way drops them. Returns the stick y for this poll, 0 between pulses and off the map. Under lock.
#define MAP_ZOOM_PULSE_NS 100000000ull
#define MAP_ZOOM_GAP_NS 50000000ull
#define MAP_ZOOM_QUEUE 4
static int32_t map_zoom_stick(int32_t notches, int on_map) {
// The scroll wheel (ikb_wheel_take, and an input script's WHEEL lines) as the stick a gamepad player would move:
// - on the Purah Pad's map it zooms: the right stick's y, away from the player zooming in;
// - while a D-pad strip (weapons, shields, bows, materials) is held open it steps the choice: the right stick's x, away
// from the player to the left, towards the player to the right;
// - in a menu with the game's focus box (the inventory, shops, Options, the save list; menu_cursor_menu) it steps the
// focus: the left stick's y, away from the player up.
// Each notch is a full-tilt pulse with neutral after it (wheel_timing), so the game sees one notch as one step, and a
// fast scroll's notches wait their turn (at most WHEEL_QUEUE); a turn the other way drops them. A strip's pulse is the
// mouse's (input_direct_mouse_row: 32 ms each way); a menu takes the stick on its own update, a frame of the game's
// 30 Hz or less, so its pulse covers two. Elsewhere, and while the settings menu is open, the notches are dropped.
enum { WHEEL_NONE, WHEEL_MAP, WHEEL_STRIP, WHEEL_MENU };
static const struct { uint64_t pulse_ns, gap_ns; } wheel_timing[] = {
[WHEEL_MAP] = {100000000ull, 50000000ull}, [WHEEL_STRIP] = {32000000ull, 32000000ull},
[WHEEL_MENU] = {70000000ull, 50000000ull}};
#define WHEEL_QUEUE 4
#define WHEEL_GAP_NS 300000000ull // a menu's focus gap (a tab switch): queued notches wait this long for its next screen
// The stick value for this poll at the place `where` (WHEEL_*): -STICK_MAX, 0 or STICK_MAX. Under lock.
static int32_t wheel_stick(int32_t notches, int where) {
static int32_t queued, dir;
static uint64_t until; // the end of the pulse (dir != 0) or of the neutral after it
static int place;
static uint64_t until, none_since; // until: the end of the pulse (dir != 0) or of the neutral after it
uint64_t now = plat_now_ns();
if (!on_map) { queued = dir = 0, until = 0; return 0; }
if (where == WHEEL_NONE) {
if (!none_since) none_since = now;
if (now - none_since > WHEEL_GAP_NS) queued = 0, place = WHEEL_NONE;
dir = 0;
return 0;
}
none_since = 0;
if (where != place) queued = dir = 0, until = 0, place = where;
if (notches) {
if (queued && (notches > 0) != (queued > 0)) queued = 0;
queued += notches;
queued = queued > MAP_ZOOM_QUEUE ? MAP_ZOOM_QUEUE : queued < -MAP_ZOOM_QUEUE ? -MAP_ZOOM_QUEUE : queued;
queued = queued > WHEEL_QUEUE ? WHEEL_QUEUE : queued < -WHEEL_QUEUE ? -WHEEL_QUEUE : queued;
}
if (dir) {
if (now < until) return dir * STICK_MAX;
dir = 0, until = now + MAP_ZOOM_GAP_NS;
dir = 0, until = now + wheel_timing[where].gap_ns;
return 0;
}
if (now < until || !queued) return 0;
dir = queued > 0 ? 1 : -1;
queued -= dir;
until = now + MAP_ZOOM_PULSE_NS;
until = now + wheel_timing[where].pulse_ns;
return dir * STICK_MAX;
}
// After the keys, the gamepad and the script: where the wheel goes this poll (b holds the script's D-pad too, so a
// scripted strip takes scripted notches). Under lock.
static void wheel_route(uint64_t b, int32_t sl[2], int32_t sr[2]) {
int32_t real = state > 0 ? ikb_wheel_take() : 0, notches = real + script_wheel; // the script's under TOTK_INPUT=none too
script_wheel = 0;
if (menu_is_open()) notches = 0;
if (real && notches) {
__atomic_store_n(&g_kbm_last, 1, __ATOMIC_RELAXED); // the pointer comes to a menu the wheel turns in
rec_wheel(real);
}
// A strip is its D-pad direction held with its screen open; with the menu cursor off (the screens not read,
// menu_cursor_shortcut -1) the buttons alone decide, as for the mouse's selectors
int sc = b & (1ull << B_UP | 1ull << B_LEFT | 1ull << B_RIGHT) && !(b & 1ull << B_L) ? menu_cursor_shortcut() : 0;
int strip = sc == -1 || sc == 1 || (sc == 0 && menu_cursor_strip());
int where = menu_cursor_map() ? WHEEL_MAP : strip ? WHEEL_STRIP : menu_cursor_menu() ? WHEEL_MENU : WHEEL_NONE;
int32_t v = wheel_stick(notches, where);
if (!v) return;
if (where == WHEEL_MAP) pick(&sr[0], &sr[1], 0, v);
else if (where == WHEEL_STRIP) pick(&sr[0], &sr[1], -v, 0);
else pick(&sl[0], &sl[1], 0, v);
}
// Under lock, state 1: the open gamepad's inputs by position (pd[PAD_*] != 0 held); 0 without a connected gamepad.
static int pad_physical(uint8_t pd[PAD_COUNT]) {
if ((!pad || !SDL_GamepadConnected(pad)) && plat_now_ns() / 1000000u >= next_scan) { next_scan = plat_now_ns() / 1000000u + RESCAN_MS; scan_pads(); }
@@ -658,13 +719,10 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx
// Before the screens were read (the menu cursor off) the buttons alone decide, as before.
if (selector && menu_cursor_shortcut() == 0) selector = 0;
mouse_camera(k, selector);
// On the map the left stick moves the cursor and the right one zooms: the mouse moves the cursor there,
// the scroll wheel zooms (map_zoom_stick). Elsewhere the wheel is unbound; its notches are dropped.
int map = menu_cursor_map();
if (map) pick(&sl[0], &sl[1], k[0], k[1]);
// On the map the left stick moves the cursor and the right one zooms: the mouse moves the cursor there
// (the scroll wheel zooms, wheel_route)
if (menu_cursor_map()) pick(&sl[0], &sl[1], k[0], k[1]);
else pick(&sr[0], &sr[1], k[0], k[1]);
int32_t zoom = map_zoom_stick(ikb_wheel_take(), map);
if (zoom) pick(&sr[0], &sr[1], 0, zoom);
int32_t shake = shake_stick(input_map_held(down, B_SHAKE));
if (shake) sr[0] = shake, sr[1] = 0;
// A mouse shake (mouse_direct.c) moves the stick with the mouse, side by side, and lets go when it rests
@@ -679,6 +737,7 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx
else if (kbm_used) __atomic_store_n(&g_kbm_last, 1, __ATOMIC_RELAXED);
}
script_apply(&b, sl, sr);
wheel_route(b, sl, sr);
rec_apply(b, sl, sr);
// Minus and Plus held together (gamepad or keys) open or close the menu and never reach the game
static int combo_held;
+5
View File
@@ -35,6 +35,11 @@ int menu_cursor_shortcut(void);
void menu_cursor_poll(uint64_t *buttons);
int menu_cursor_pointer(void);
int menu_cursor_map(void); // the Purah Pad's map is open: the mouse's stick is the left one (its cursor)
// A menu screen (not the ability wheel, a D-pad strip or the map) has the game's focus box, whichever device was used
// last: input.c turns the scroll wheel into steps of its focus. 0 with the menu cursor off.
int menu_cursor_menu(void);
// A D-pad strip's screen (ShortCut_00) is open; it has no focus box while held. 0 with the menu cursor off.
int menu_cursor_strip(void);
// The same for host UI (the text entry): never blocked. input_block(1) while a text entry is open: input_poll then
// reports nothing; input_block(0) when it closes: nothing until all buttons and stick directions are released.
void input_poll_ui(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx, int32_t *ry);
+4 -2
View File
@@ -23,7 +23,8 @@ static SDL_Window *win;
static volatile uint8_t key_held[KEY_COUNT];
static volatile int32_t esc_held, f8_held, focused;
static volatile int32_t mouse_dx, mouse_dy; // relative motion since the last ikb_mouse_take, whole counts
static volatile int32_t mouse_wheel; // wheel turned while captured, in 1/120 notches (ikb_wheel_take)
static volatile int32_t mouse_wheel; // wheel turned while captured or over the window, in 1/120 notches
// (ikb_wheel_take)
static float rem_x, rem_y; // window thread: the fractions SDL reported beyond them
static volatile int32_t mouse_travel; // raw counts moved in total, captured or not (ikb_mouse_travel)
static float travel_rem; // window thread: the fraction of a count beyond mouse_travel
@@ -266,7 +267,8 @@ void input_sdl_event(const SDL_Event *e) {
__atomic_store_n(&ptr_have, 0, __ATOMIC_RELEASE);
break;
case SDL_EVENT_MOUSE_WHEEL: // notches, + away from the player (a flipped wheel reports the other sign)
if (captured) {
// Captured, or released over the focused window: a game menu with the pointer takes it (input.c)
if (captured || (focused && __atomic_load_n(&ptr_have, __ATOMIC_ACQUIRE))) {
float y = e->wheel.direction == SDL_MOUSEWHEEL_FLIPPED ? -e->wheel.y : e->wheel.y;
plat_add32(&mouse_wheel, (int32_t)(y * 120));
}
+8 -3
View File
@@ -84,7 +84,8 @@ uint32_t input_key_char(int key) {
// ---- mouse camera: raw motion accumulated by the window thread, one stick sample per presented frame
static volatile LONG mouse_dx, mouse_dy; // raw counts since the last frame sample
static volatile LONG mouse_travel; // raw counts moved in total, captured or not (ikb_mouse_travel)
static volatile LONG mouse_wheel; // wheel turned while captured, in WHEEL_DELTA units (ikb_wheel_take)
static volatile LONG mouse_wheel; // wheel turned while captured or over the window, in WHEEL_DELTA units
// (ikb_wheel_take)
static volatile LONG cur_captured; // cursor hidden and confined to the client area
static volatile LONG cur_active; // WM_ACTIVATEAPP: the window's application is active
// Bits: CUR_REL, Esc or activation by a click on the title bar or border: until a client click; CUR_ESC, set with CUR_REL
@@ -148,8 +149,12 @@ int input_window_msg(HWND h, UINT m, WPARAM w, LPARAM l, LRESULT *res) {
InterlockedAdd(&mouse_dy, y);
}
}
// The wheel comes in the same message (usButtonData, signed, + away from the player)
if (cur_captured && ri.header.dwType == RIM_TYPEMOUSE && (ri.data.mouse.usButtonFlags & RI_MOUSE_WHEEL))
// The wheel comes in the same message (usButtonData, signed, + away from the player). It counts while the
// cursor is captured, or released over the client area: a game menu with the pointer (menu_cursor.c) takes it
// as steps of its focus. input.c drops the notches where nothing takes them.
float px, py;
if (ri.header.dwType == RIM_TYPEMOUSE && (ri.data.mouse.usButtonFlags & RI_MOUSE_WHEEL) &&
(cur_captured || ikb_pointer(&px, &py)))
InterlockedAdd(&mouse_wheel, (SHORT)ri.data.mouse.usButtonData);
break; // DefWindowProc must see WM_INPUT for cleanup
}
+3 -2
View File
@@ -13,8 +13,9 @@ void ikb_pointer_set(float nx, float ny); // moves the pointer there (the wind
int ikb_captured(void); // the cursor is captured for the mouse camera
void ikb_mouse_take(int32_t *dx, int32_t *dy); // raw mouse motion since the last call, in counts
uint32_t ikb_mouse_travel(void); // raw counts the mouse moved in total (|dx| + |dy|), captured or not
int32_t ikb_wheel_take(void); // whole wheel notches turned while captured since the last call (+ away
// from the player); a high-resolution wheel's part of a notch is kept
int32_t ikb_wheel_take(void); // whole wheel notches turned since the last call while the cursor was
// captured or over the focused window (+ away from the player); a
// high-resolution wheel's part of a notch is kept
void ikb_cursor_update(void); // what input_cursor_allowed says may have changed
void ikb_menu_closed(void); // the menu closed: a capture that Esc gave up comes back
+19 -4
View File
@@ -166,13 +166,15 @@ static void layout_name(uint64_t scr, char *out, size_t n) {
// 1.4.3 constructor keeps). The map has no focus box, so it is found here: the Purah Pad's frame (AppMenuOverlay_00)
// with AppMap_00 and the menu's background AppMenuBG_00 open. The Scope opens the frame over AppMap_00 without that
// background (Weeping of the Empire's engine/runtime/totk_menu_cursor.cpp census tells them apart the same way).
// A D-pad strip has no focus box either while it is held open: *strip is ShortCut_00 being open.
// TOTK_MENU_CURSOR_LOG=1 logs the open screens whenever the set changes.
enum { SM_COUNT = 0x8, SM_SCREENS = 0x10 };
static int map_open(void) {
static int map_open(int *strip) {
uint64_t sm = screen_mgr();
if (!sm) return 0;
int32_t n = (int32_t)rd32(sm + SM_COUNT);
uint64_t arr = rd64(sm + SM_SCREENS);
*strip = 0;
if (n <= 0 || n > 1024 || !ok_at(arr, 8ull * (uint64_t)n)) return 0;
const char *e = cfg_get("TOTK_MENU_CURSOR_LOG");
int verbose = e && !strcmp(e, "1"), pad = 0, map = 0, bg = 0;
@@ -187,6 +189,7 @@ static int map_open(void) {
pad |= !strcmp(nm, "AppMenuOverlay_00");
map |= !strcmp(nm, "AppMap_00");
bg |= !strcmp(nm, "AppMenuBG_00");
*strip |= !strcmp(nm, "ShortCut_00");
if (!verbose) continue;
for (const char *c = nm; *c; c++) h = (h ^ (uint8_t)*c) * 1099511628211ull;
if (len < sizeof list - 64) len += (size_t)snprintf(list + len, sizeof list - len, "%s%s", len ? " " : "", nm);
@@ -280,9 +283,13 @@ static int gameplay_screen(const char *nm) {
static volatile int32_t g_pointer; // a menu has the pointer: input_cursor_allowed releases the capture
static volatile int32_t g_map; // the Purah Pad's map is open (not the Scope): the mouse moves its cursor
static volatile int32_t g_menu; // a menu screen has the focus box, from either device (the scroll wheel's steps)
static volatile int32_t g_strip; // a D-pad strip's screen is open (the scroll wheel's steps along it)
int menu_cursor_pointer(void) { return __atomic_load_n(&g_pointer, __ATOMIC_RELAXED); }
int menu_cursor_map(void) { return __atomic_load_n(&g_map, __ATOMIC_RELAXED); }
int menu_cursor_menu(void) { return __atomic_load_n(&g_menu, __ATOMIC_RELAXED); }
int menu_cursor_strip(void) { return __atomic_load_n(&g_strip, __ATOMIC_RELAXED); }
static int enabled(void) {
if (!RT_V143) return 0;
@@ -325,19 +332,27 @@ void menu_cursor_poll(uint64_t *buttons) {
main_lo = MOD_MAIN_BASE, main_hi = MOD_MAIN_BASE + MAIN_SIZE;
if (RT_V143) rt_log("menu_cursor: on for 1.4.3 (TOTK_MENU_CURSOR=0 turns it off)");
}
if (!enabled()) { set_pointer(0); __atomic_store_n(&g_map, 0, __ATOMIC_RELAXED); return; }
if (!enabled()) {
set_pointer(0);
__atomic_store_n(&g_map, 0, __ATOMIC_RELAXED);
__atomic_store_n(&g_menu, 0, __ATOMIC_RELAXED);
__atomic_store_n(&g_strip, 0, __ATOMIC_RELAXED);
return;
}
Focus f = focus_now();
char nm[48] = "";
if (f.screen) layout_name(f.screen, nm, sizeof nm);
// The open screens are scanned every 100 ms, not at every pad read: each screen costs memory queries
uint64_t now = plat_now_ms();
static uint64_t map_at;
static int map, map_logged;
if (!map_at || now - map_at >= 100) map_at = now, map = map_open();
static int map, map_logged, strip;
if (!map_at || now - map_at >= 100) map_at = now, map = map_open(&strip);
__atomic_store_n(&g_strip, strip, __ATOMIC_RELAXED);
if (map && !map_logged) map_logged = 1, rt_log("menu_cursor: the map is open: the mouse moves its cursor");
__atomic_store_n(&g_map, map, __ATOMIC_RELAXED);
// With the gamepad as the last device the menus stay as they are on the console: no pointer, the capture kept.
// Moving the mouse (or a key) makes keyboard and mouse the last device and the pointer comes.
__atomic_store_n(&g_menu, f.screen && !gameplay_screen(nm) && !map, __ATOMIC_RELAXED);
int menu = f.screen && !gameplay_screen(nm) && ikb_foreground() && input_kbm_last();
if (menu) menu_seen = now;
// A menu's focus gap (a tab switch, a popup opening: no focus box for a frame or two) keeps the pointer where it