upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/shims/gameinput.cpp
diff options
context:
space:
mode:
authorDadaCap <167002618+DadaCap@users.noreply.github.com>2026-11-28 09:06:15 +0100
committerGitHub <noreply@github.com>2026-11-28 09:06:15 +0100
commit766963e34a94e3904528d65aa65befe3aaae3b40 (patch)
tree3ff6d3006001a8fe4eba6e3e2213d1318b8115f5 /runtime/shims/gameinput.cpp
parent4295601b81148e909d0c6432b20326f198cff493 (diff)
parent28829e0aabeac81362d51fcbb51a72ea83bd4590 (diff)
Merge pull request #2487 from Tyrannys/rt-gameinput-clip-drag
gameinput: let go of the cursor clip while the window is dragged (RT-GAMEINPUT-CLIP-DRAG)
Diffstat (limited to 'runtime/shims/gameinput.cpp')
-rw-r--r--runtime/shims/gameinput.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp
index ecb8755fb..ef3f3b69a 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).
1787bool g_clipped = false; 1789bool g_clipped = false;
1788uint64_t g_clip_at = 0; 1790uint64_t g_clip_at = 0;
1791rt::gameinput::detail::CursorClipGate g_clip_gate;
1789 1792
1790void clip_cursor(bool want) { 1793void 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};