diff --git a/client/SDL/SDL3/sdl_context.cpp b/client/SDL/SDL3/sdl_context.cpp index 573c37567..f8041cfe2 100644 --- a/client/SDL/SDL3/sdl_context.cpp +++ b/client/SDL/SDL3/sdl_context.cpp @@ -763,7 +763,7 @@ int SdlContext::error_info_to_error(DWORD* pcode, char** msg, size_t* len) const return exit_code; } -void SdlContext::applyMonitorOffset(SDL_WindowID window, float& x, float& y) +void SdlContext::applyMonitorOffset(SDL_WindowID window, float& x, float& y) const { if (!freerdp_settings_get_bool(context()->settings, FreeRDP_UseMultimon)) return; @@ -850,6 +850,14 @@ bool SdlContext::removeDisplay(SDL_DisplayID id) return true; } +const SdlWindow* SdlContext::getWindowForId(SDL_WindowID id) const +{ + auto it = _windows.find(id); + if (it == _windows.end()) + return nullptr; + return &it->second; +} + SdlWindow* SdlContext::getWindowForId(SDL_WindowID id) { auto it = _windows.find(id); @@ -1048,9 +1056,11 @@ bool SdlContext::eventToPixelCoordinates(SDL_WindowID id, SDL_Event& ev) auto w = getWindowForId(id); if (!w) return false; + + /* Ignore errors here, sometimes SDL has no renderer */ auto renderer = SDL_GetRenderer(w->window()); if (!renderer) - return false; + return true; return SDL_ConvertEventToRenderCoordinates(renderer, &ev); } @@ -1078,9 +1088,11 @@ SDL_FPoint SdlContext::screenToPixel(SDL_WindowID id, const SDL_FPoint& pos) auto w = getWindowForId(id); if (!w) return {}; + + /* Ignore errors here, sometimes SDL has no renderer */ auto renderer = SDL_GetRenderer(w->window()); if (!renderer) - return {}; + return pos; SDL_FPoint rpos{}; if (!SDL_RenderCoordinatesFromWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y)) @@ -1094,9 +1106,11 @@ SDL_FPoint SdlContext::pixelToScreen(SDL_WindowID id, const SDL_FPoint& pos) auto w = getWindowForId(id); if (!w) return {}; + + /* Ignore errors here, sometimes SDL has no renderer */ auto renderer = SDL_GetRenderer(w->window()); if (!renderer) - return {}; + return pos; SDL_FPoint rpos{}; if (!SDL_RenderCoordinatesToWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y)) diff --git a/client/SDL/SDL3/sdl_context.hpp b/client/SDL/SDL3/sdl_context.hpp index fab4373f8..5cc17f814 100644 --- a/client/SDL/SDL3/sdl_context.hpp +++ b/client/SDL/SDL3/sdl_context.hpp @@ -106,6 +106,7 @@ class SdlContext [[nodiscard]] int exitCode() const; [[nodiscard]] SDL_PixelFormat pixelFormat() const; + [[nodiscard]] const SdlWindow* getWindowForId(SDL_WindowID id) const; [[nodiscard]] SdlWindow* getWindowForId(SDL_WindowID id); [[nodiscard]] SdlWindow* getFirstWindow(); @@ -162,7 +163,7 @@ class SdlContext [[nodiscard]] int error_info_to_error(DWORD* pcode, char** msg, size_t* len) const; - void applyMonitorOffset(SDL_WindowID window, float& x, float& y); + void applyMonitorOffset(SDL_WindowID window, float& x, float& y) const; rdpContext* _context = nullptr; wLog* _log = nullptr;