[client,sdl] wrap mouse cursor move in SdlContext

This commit is contained in:
akallabeth
2026-01-25 12:16:16 +01:00
parent 2e7639d903
commit c6b104cce0
3 changed files with 17 additions and 12 deletions

View File

@@ -840,6 +840,18 @@ wLog* SdlContext::getWLog()
return _log;
}
bool SdlContext::moveMouseTo(const SDL_FPoint& pos)
{
auto window = SDL_GetMouseFocus();
if (!window)
return true;
const auto id = SDL_GetWindowID(window);
const auto spos = pixelToScreen(id, pos);
SDL_WarpMouseInWindow(window, spos.x, spos.y);
return true;
}
bool SdlContext::handleEvent(const SDL_WindowEvent* ev)
{

View File

@@ -120,6 +120,8 @@ class SdlContext
[[nodiscard]] wLog* getWLog();
[[nodiscard]] bool moveMouseTo(const SDL_FPoint& pos);
[[nodiscard]] SDL_FPoint screenToPixel(SDL_WindowID id, const SDL_FPoint& pos);
[[nodiscard]] SDL_FPoint pixelToScreen(SDL_WindowID id, const SDL_FPoint& pos);

View File

@@ -288,18 +288,9 @@ static int sdl_run(SdlContext* sdl)
static_cast<INT32>(reinterpret_cast<uintptr_t>(windowEvent.user.data1));
const auto y =
static_cast<INT32>(reinterpret_cast<uintptr_t>(windowEvent.user.data2));
SDL_Window* window = SDL_GetMouseFocus();
if (window)
{
const Uint32 id = SDL_GetWindowID(window);
INT32 sx = x;
INT32 sy = y;
if (sdl_scale_coordinates(sdl, id, &sx, &sy, FALSE, FALSE))
SDL_WarpMouseInWindow(window, static_cast<float>(sx),
static_cast<float>(sy));
}
if (!sdl->moveMouseTo(
{ static_cast<float>(x) * 1.0f, static_cast<float>(y) * 1.0f }))
return -1;
}
break;
case SDL_EVENT_USER_POINTER_SET: