mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-19 12:25:56 +00:00
Merge the Esc cursor release
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
d3589c904e
4 files changed
+38
-3
No files matched your search
+2
-2
@@ -20,13 +20,13 @@ Input comes from the first SDL3 gamepad, the keyboard and the mouse, merged into
|
||||
| Plus | Start | Tab | menu, inventory |
|
||||
| Minus | Back | M | map |
|
||||
|
||||
Esc is free. Z and X duplicate ZL and ZR so menu pages turn with two neighbouring keys; the menu tabs (L, R) are Q and R. The mouse wheel is unbound. The bindings are one table, `input_bindings` in `runtime/input_map.c` (platform-neutral key ids; `runtime/input_win.c` translates Win32 virtual keys), so a remapping page can edit it later.
|
||||
Esc is unbound in the game; it releases the mouse cursor (see Mouse camera). Z and X duplicate ZL and ZR so menu pages turn with two neighbouring keys; the menu tabs (L, R) are Q and R. The mouse wheel is unbound. The bindings are one table, `input_bindings` in `runtime/input_map.c` (platform-neutral key ids; `runtime/input_win.c` translates Win32 virtual keys), so a remapping page can edit it later.
|
||||
|
||||
## Mouse camera
|
||||
|
||||
Mouse motion (raw input) becomes right-stick deflection. Each presented frame takes the counts moved since the last frame, divides by the frame time and sets the deflection to `counts per second * TOTK_MOUSE_SENS / 3000` of full, held for that frame, so the turn rate does not depend on the frame rate. This is not mouselook: the game's stick curve and dead zone still apply, so very slow movements do nothing and a fast flick saturates. The mouse deflection competes with the gamepad and arrow keys by the larger-deflection rule.
|
||||
|
||||
`TOTK_MOUSE_SENS` (0 to 10, default 1; higher turns faster, 0 turns the mouse camera and the cursor capture off). While the window is the foreground window the cursor is hidden and confined to the client area. It is released on focus loss, minimise, while F11 changes the window, during a size or move loop and while a text entry is open. To resize or move the window by hand, alt-tab away first or use F11. `TOTK_INPUT=none` disables the capture too.
|
||||
`TOTK_MOUSE_SENS` (0 to 10, default 1; higher turns faster, 0 turns the mouse camera and the cursor capture off). While the window is the foreground window the cursor is hidden and confined to the client area. It is released on focus loss, minimise, while F11 changes the window, during a size or move loop and while a text entry is open. Esc releases it by hand: the cursor shows, the mouse camera and mouse buttons stop, and the window can be moved, minimised or closed. A mouse click inside the client area captures it again; that click does not reach the game. Activating the window by a click on its title bar or border does not capture, so it can be dragged or closed right away; Alt+Tab or a click in the client area captures as before. `TOTK_INPUT=none` disables the capture too.
|
||||
|
||||
The stick direction bits (`StickLLeft` to `StickRDown`) are derived from the sticks at 50% deflection. A gamepad plugged in later is picked up within one second; with none connected the log says `input: no gamepad`.
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include "gfx.h"
|
||||
#include "input.h"
|
||||
#include "vk.h"
|
||||
|
||||
#define SRC_W 640
|
||||
@@ -147,6 +148,26 @@ int probe_window(void) {
|
||||
}
|
||||
printf("probe-window: focus off/on pushed 2 messages (15)\n");
|
||||
|
||||
// Cursor release: Esc releases, a client click recaptures, a title bar activation releases. The probe window may not be
|
||||
// the foreground window, so this checks the release flag, not the clip state.
|
||||
HWND hw = gfx_window_handle();
|
||||
SendMessageW(hw, WM_KEYDOWN, VK_ESCAPE, 0);
|
||||
int esc = input_cursor_released();
|
||||
SendMessageW(hw, WM_LBUTTONDOWN, MK_LBUTTON, 0);
|
||||
int click = input_cursor_released();
|
||||
SendMessageW(hw, WM_MOUSEACTIVATE, (WPARAM)hw, MAKELPARAM(HTCLIENT, WM_LBUTTONDOWN));
|
||||
int client = input_cursor_released();
|
||||
SendMessageW(hw, WM_MOUSEACTIVATE, (WPARAM)hw, MAKELPARAM(HTCAPTION, WM_LBUTTONDOWN));
|
||||
int caption = input_cursor_released();
|
||||
SendMessageW(hw, WM_ACTIVATEAPP, FALSE, 0);
|
||||
SendMessageW(hw, WM_ACTIVATEAPP, TRUE, 0);
|
||||
int back = input_cursor_released();
|
||||
if (!esc || click || client || !caption || back) {
|
||||
printf("probe-window: released esc=%d click=%d client=%d caption=%d reactivated=%d\n", esc, click, client, caption, back);
|
||||
return fail("cursor release");
|
||||
}
|
||||
printf("probe-window: cursor released by Esc and title bar activation, recaptured by a click\n");
|
||||
|
||||
// Resize: the client area changes, the swapchain follows, presenting still reads back exact.
|
||||
gfx_window_resize(1280, 720);
|
||||
RECT rc;
|
||||
|
||||
@@ -19,6 +19,7 @@ void input_block(int on);
|
||||
// releases the cursor around an F11 window change, (0) captures it again once the client area has its new size.
|
||||
#ifdef _WIN32
|
||||
int input_window_msg(HWND h, UINT m, WPARAM w, LPARAM l, LRESULT *res);
|
||||
int input_cursor_released(void); // Esc or a non-client activation released the cursor (probe)
|
||||
#endif
|
||||
void input_cursor_suspend(int on);
|
||||
|
||||
|
||||
+14
-1
@@ -189,6 +189,7 @@ static int key_vk(int key) {
|
||||
static volatile LONG mouse_dx, mouse_dy; // raw counts since the last frame sample
|
||||
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
|
||||
static volatile LONG cur_released; // Esc, or activation by a click on the title bar or border: until a client click
|
||||
static volatile LONG cur_suspend; // F11 or a modal size or move loop under way
|
||||
static SRWLOCK cur_lock = SRWLOCK_INIT; // serialises cursor_update (window thread, input_block callers)
|
||||
static volatile LONG g_block; // text entry state, see input_block
|
||||
@@ -209,7 +210,7 @@ static float mouse_sens_get(void) {
|
||||
static void cursor_update(HWND h) {
|
||||
const char *in = cfg_get("TOTK_INPUT");
|
||||
AcquireSRWLockExclusive(&cur_lock);
|
||||
int want = h && cur_active && !cur_suspend && g_block != 1 && mouse_sens_get() > 0 && !(in && !strcmp(in, "none")) &&
|
||||
int want = h && cur_active && !cur_released && !cur_suspend && g_block != 1 && mouse_sens_get() > 0 && !(in && !strcmp(in, "none")) &&
|
||||
GetForegroundWindow() == h && !IsIconic(h);
|
||||
RECT r;
|
||||
POINT tl = {0, 0};
|
||||
@@ -225,6 +226,8 @@ static void cursor_update(HWND h) {
|
||||
ReleaseSRWLockExclusive(&cur_lock);
|
||||
}
|
||||
|
||||
int input_cursor_released(void) { return cur_released != 0; }
|
||||
|
||||
void input_cursor_suspend(int on) {
|
||||
InterlockedExchange(&cur_suspend, on != 0);
|
||||
cursor_update(gfx_window_handle());
|
||||
@@ -251,7 +254,17 @@ int input_window_msg(HWND h, UINT m, WPARAM w, LPARAM l, LRESULT *res) {
|
||||
case WM_SETCURSOR:
|
||||
if (cur_captured && LOWORD(l) == HTCLIENT) { SetCursor(NULL); *res = TRUE; return 1; }
|
||||
break;
|
||||
case WM_KEYDOWN: // Esc is unbound in the game layout, so it only releases the cursor
|
||||
if (w == VK_ESCAPE) { InterlockedExchange(&cur_released, 1); cursor_update(h); }
|
||||
break;
|
||||
case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: // client area only; poll_merged drops the click
|
||||
if (cur_released) { InterlockedExchange(&cur_released, 0); cursor_update(h); }
|
||||
break;
|
||||
case WM_MOUSEACTIVATE: // sent before WM_ACTIVATEAPP: a title bar or border click must not capture
|
||||
if (LOWORD(l) != HTCLIENT) InterlockedExchange(&cur_released, 1);
|
||||
break;
|
||||
case WM_ACTIVATEAPP:
|
||||
if (!w) InterlockedExchange(&cur_released, 0); // Alt+Tab back in captures again
|
||||
InterlockedExchange(&cur_active, w != 0);
|
||||
cursor_update(h);
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user