mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-22 21:15:57 +00:00
Release the mouse cursor with Esc, recapture on a client click and skip capture when a title bar click activates the window
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eb12f260ad
commit
cb9ea1ae05
4 files changed
+38
-3
No files matched your search
@@ -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