Files
mandy/runtime/test/gameinput_clip_test.cpp
Tyrannys 28829e0aab 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>
2026-11-27 12:13:35 -06:00

64 lines
3.4 KiB
C++

// CursorClipGate (shims/gameinput_clip.h): when the keyboard pad clips the cursor to the game window's client area.
// The clip must stay for clicks in the client area, and must let go while the window is dragged or sized, or a press
// on its title bar or border is held. No window, no SDL.
#include "gameinput_clip.h"
#include <cstdio>
namespace {
bool check(bool condition, const char* description) {
if (!condition) std::fprintf(stderr, "FAIL: %s\n", description);
return condition;
}
}
int main() {
using rt::gameinput::detail::CursorClipGate;
bool ok = true;
constexpr bool want = true, modal = true, down = true, client = true;
{
CursorClipGate g;
ok &= check(g.update(want, !modal, !down, client), "focused, no button: clip");
ok &= check(!g.update(!want, !modal, !down, client), "not wanted: no clip");
ok &= check(!g.update(!want, !modal, down, client), "not wanted, button held: no clip");
}
{
// A click in the client area keeps the clip for as long as it is held, so it cannot land on another window.
CursorClipGate g;
ok &= check(g.update(want, !modal, !down, client), "before a client click: clip");
ok &= check(g.update(want, !modal, down, client), "client press: clip");
ok &= check(g.update(want, !modal, down, !client), "client press dragged to the edge: still clipped");
ok &= check(g.update(want, !modal, !down, client), "after release: clip");
}
{
// The user's report: grabbing the title bar of the focused window. The press starts outside the client
// area, then Windows enters the move loop; the clip is let go for both and comes back after the release.
CursorClipGate g;
ok &= check(g.update(want, !modal, !down, !client), "cursor over the title bar, no button: clip");
ok &= check(!g.update(want, !modal, down, !client), "title-bar press: no clip");
ok &= check(!g.update(want, modal, down, !client), "move loop: no clip");
ok &= check(!g.update(want, modal, down, client), "move loop over the client area: still no clip");
ok &= check(!g.update(want, !modal, down, client), "move loop over, press still held: no clip");
ok &= check(g.update(want, !modal, !down, client), "released: clip again");
}
{
// A click on the title bar of the unfocused window: the button is already down when the clip is wanted.
CursorClipGate g;
ok &= check(!g.update(!want, !modal, down, !client), "unfocused press: no clip");
ok &= check(!g.update(want, !modal, down, !client), "focus gained by a title-bar press: no clip");
ok &= check(!g.update(want, !modal, down, client), "that press dragged over the client area: no clip");
ok &= check(g.update(want, !modal, !down, client), "released: clip");
// The same with focus gained by a client-area press: clipped at once.
ok &= check(!g.update(!want, !modal, down, client), "unfocused client press: no clip");
ok &= check(g.update(want, !modal, down, client), "focus gained by a client press: clip");
}
{
// A modal loop alone (keyboard move or size from the system menu, a menu): no clip, whatever the buttons.
CursorClipGate g;
ok &= check(!g.update(want, modal, !down, client), "keyboard move/size or menu loop: no clip");
ok &= check(g.update(want, !modal, !down, client), "loop over: clip");
}
return ok ? 0 : 1;
}