Keep the wheel's focus until the pointer leaves a dead zone, and draw a pointer of our own

After the scroll wheel, the keys or the pad move the focus in a menu, the pointer takes it back only once it has
moved 6 layout units from where it was then (menu_cursor_poll), so a hand resting on the mouse no longer undoes a
scroll. While the cursor is not captured, the game window shows a gold arrowhead drawn at the window's DPI
(cursor_art.c) instead of the Windows arrow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
itaskaev2andClaude Opus 5.5 committed 2026-11-11 09:44:01 +01:00
1 parent a10c546a06
commit c0ca89fdda
5 files changed
+168 -4

No files matched your search

+37 -1
View File
@@ -122,6 +122,39 @@ static void cursor_update(HWND h) {
ReleaseSRWLockExclusive(&cur_lock);
}
// The pointer shown over the client area while the cursor is not captured (cursor_art.c), 32 pixels at 96 DPI and
// larger with the window's DPI; made again when the DPI changes. Window thread. NULL when Windows refuses it: the
// window class's arrow stays.
static HCURSOR art_cursor(HWND h) {
static HCURSOR cur;
static UINT made_dpi;
UINT dpi = GetDpiForWindow(h);
if (!dpi) dpi = USER_DEFAULT_SCREEN_DPI;
if (cur && dpi == made_dpi) return cur;
int size = MulDiv(32, (int)dpi, USER_DEFAULT_SCREEN_DPI), hot;
size = size < 32 ? 32 : size > 128 ? 128 : size;
BITMAPV5HEADER bh = {.bV5Size = sizeof bh, .bV5Width = size, .bV5Height = -size, .bV5Planes = 1, .bV5BitCount = 32,
.bV5Compression = BI_BITFIELDS, .bV5RedMask = 0xff0000, .bV5GreenMask = 0xff00,
.bV5BlueMask = 0xff, .bV5AlphaMask = 0xff000000u};
void *bits = NULL;
HDC dc = GetDC(NULL);
HBITMAP color = CreateDIBSection(dc, (BITMAPINFO *)&bh, DIB_RGB_COLORS, &bits, NULL, 0);
ReleaseDC(NULL, dc);
HBITMAP mask = CreateBitmap(size, size, 1, 1, NULL);
HCURSOR made = NULL;
if (color && mask && bits) {
cursor_art(bits, size, &hot);
ICONINFO ii = {.fIcon = FALSE, .xHotspot = (DWORD)hot, .yHotspot = (DWORD)hot, .hbmMask = mask,
.hbmColor = color};
made = (HCURSOR)CreateIconIndirect(&ii);
}
if (color) DeleteObject(color);
if (mask) DeleteObject(mask);
if (!made) return cur; // the old size, or NULL
cur = made, made_dpi = dpi; // the old one may still be on screen: kept (a DPI change is rare)
return cur;
}
int input_cursor_released(void) { return (cur_rel & CUR_REL) != 0; }
void input_cursor_suspend(int on) {
@@ -159,7 +192,10 @@ int input_window_msg(HWND h, UINT m, WPARAM w, LPARAM l, LRESULT *res) {
break; // DefWindowProc must see WM_INPUT for cleanup
}
case WM_SETCURSOR:
if (cur_captured && LOWORD(l) == HTCLIENT) { SetCursor(NULL); *res = TRUE; return 1; }
if (LOWORD(l) == HTCLIENT) {
HCURSOR c = cur_captured ? NULL : art_cursor(h);
if (cur_captured || c) { SetCursor(c); *res = TRUE; return 1; }
}
break;
case WM_SYSCOMMAND: // Alt pressed alone would enter the window menu loop, which stalls the game: Alt is a game key
if ((w & 0xFFF0) == SC_KEYMENU && l == 0) { *res = 0; return 1; }