diff options
| author | Tyrannys <80750971+Tyrannys@users.noreply.github.com> | 2026-11-27 12:13:35 -0600 |
|---|---|---|
| committer | Tyrannys <80750971+Tyrannys@users.noreply.github.com> | 2026-11-27 12:13:35 -0600 |
| commit | 28829e0aabeac81362d51fcbb51a72ea83bd4590 (patch) | |
| tree | 32b5e004f2becef00bca3e9f195e757245b2820c /runtime/shims/gameinput.cpp | |
| parent | 43a9d562d355e7c5c428e486071b456353de8b05 (diff) | |
gameinput: let go of the cursor clip while the window is dragged
The keyboard pad clips the cursor to the foreground window's client
area and re-applies the clip every 100 ms. A press on the title bar was
pulled into the client area, and during the modal move loop each re-clip
pulled the cursor, and the window with it, down the screen instead of
letting it be dragged.
The clip is now released while the window's thread is in a move/size or
menu loop (GetGUIThreadInfo: GUI_INMOVESIZE, GUI_INMENUMODE,
GUI_SYSTEMMENUMODE), and while a mouse press that began outside the
client area is held, including one that activated the window. A press
in the client area keeps the clip, so a click still cannot land on
another window. The decision is CursorClipGate (shims/gameinput_clip.h),
covered by the new gameinput_clip test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/gameinput.cpp')
| -rw-r--r-- | runtime/shims/gameinput.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp index c989daff4..0c59cccdf 100644 --- a/runtime/shims/gameinput.cpp +++ b/runtime/shims/gameinput.cpp | |||
| @@ -52,6 +52,7 @@ | |||
| 52 | #include <vector> | 52 | #include <vector> |
| 53 | 53 | ||
| 54 | #include "gameinput.h" | 54 | #include "gameinput.h" |
| 55 | #include "gameinput_clip.h" | ||
| 55 | #include "gameinput_abi.h" | 56 | #include "gameinput_abi.h" |
| 56 | #include "gameinput_script.h" | 57 | #include "gameinput_script.h" |
| 57 | #include "keyboard_pad_connection.h" | 58 | #include "keyboard_pad_connection.h" |
| @@ -1783,11 +1784,29 @@ bool is_keyboard_pad(SDL_JoystickID jid) { return jid != 0 && jid == g_keyboard. | |||
| 1783 | // Keeps the cursor inside the game window while it has focus, so a click cannot land on another window, and releases | 1784 | // Keeps the cursor inside the game window while it has focus, so a click cannot land on another window, and releases |
| 1784 | // it on focus loss. Only with raw input (a clipped plain cursor would stop the stick at the window edge) and only for | 1785 | // it on focus loss. Only with raw input (a clipped plain cursor would stop the stick at the window edge) and only for |
| 1785 | // a real foreground window of this process: not KeyboardPadMode::Always over a terminal, nor a test's fake focus. | 1786 | // a real foreground window of this process: not KeyboardPadMode::Always over a terminal, nor a test's fake focus. |
| 1786 | // Re-applied every 100 ms, because Windows drops the clip on some focus and resize changes. | 1787 | // Re-applied every 100 ms, because Windows drops the clip on some focus and resize changes. Never while the window is |
| 1788 | // dragged or sized, or a press that began on its title bar or border is held (gameinput_clip.h has why). | ||
| 1787 | bool g_clipped = false; | 1789 | bool g_clipped = false; |
| 1788 | uint64_t g_clip_at = 0; | 1790 | uint64_t g_clip_at = 0; |
| 1791 | rt::gameinput::detail::CursorClipGate g_clip_gate; | ||
| 1789 | 1792 | ||
| 1790 | void clip_cursor(bool want) { | 1793 | void clip_cursor(bool want) { |
| 1794 | const HWND w = want ? GetForegroundWindow() : nullptr; | ||
| 1795 | if (w) { | ||
| 1796 | GUITHREADINFO gui{}; | ||
| 1797 | gui.cbSize = sizeof(gui); | ||
| 1798 | const bool modal_loop = GetGUIThreadInfo(GetWindowThreadProcessId(w, nullptr), &gui) && | ||
| 1799 | (gui.flags & (GUI_INMOVESIZE | GUI_INMENUMODE | GUI_SYSTEMMENUMODE)); | ||
| 1800 | const bool button_down = ((GetAsyncKeyState(VK_LBUTTON) | GetAsyncKeyState(VK_RBUTTON) | | ||
| 1801 | GetAsyncKeyState(VK_MBUTTON)) & 0x8000) != 0; | ||
| 1802 | POINT cursor; | ||
| 1803 | RECT client; | ||
| 1804 | const bool in_client = GetCursorPos(&cursor) && ScreenToClient(w, &cursor) && GetClientRect(w, &client) && | ||
| 1805 | PtInRect(&client, cursor); | ||
| 1806 | want = g_clip_gate.update(true, modal_loop, button_down, in_client); | ||
| 1807 | } else { | ||
| 1808 | want = g_clip_gate.update(false, false, false, false); | ||
| 1809 | } | ||
| 1791 | if (!want) { | 1810 | if (!want) { |
| 1792 | if (g_clipped) ClipCursor(nullptr); | 1811 | if (g_clipped) ClipCursor(nullptr); |
| 1793 | g_clipped = false; | 1812 | g_clipped = false; |
| @@ -1795,9 +1814,8 @@ void clip_cursor(bool want) { | |||
| 1795 | } | 1814 | } |
| 1796 | const uint64_t now = now_us(); | 1815 | const uint64_t now = now_us(); |
| 1797 | if (g_clipped && now - g_clip_at < 100'000) return; | 1816 | if (g_clipped && now - g_clip_at < 100'000) return; |
| 1798 | const HWND w = GetForegroundWindow(); | ||
| 1799 | RECT r; | 1817 | RECT r; |
| 1800 | if (!w || !GetClientRect(w, &r)) return; | 1818 | if (!GetClientRect(w, &r)) return; |
| 1801 | POINT top_left{r.left, r.top}, bottom_right{r.right, r.bottom}; | 1819 | POINT top_left{r.left, r.top}, bottom_right{r.right, r.bottom}; |
| 1802 | if (!ClientToScreen(w, &top_left) || !ClientToScreen(w, &bottom_right)) return; | 1820 | if (!ClientToScreen(w, &top_left) || !ClientToScreen(w, &bottom_right)) return; |
| 1803 | const RECT screen{top_left.x, top_left.y, bottom_right.x, bottom_right.y}; | 1821 | const RECT screen{top_left.x, top_left.y, bottom_right.x, bottom_right.y}; |