mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
[client,sdl] wrap mouse cursor move in SdlContext
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user