diff --git a/client/SDL/SDL3/sdl_pointer.cpp b/client/SDL/SDL3/sdl_pointer.cpp index 322269190..ebc5ac39e 100644 --- a/client/SDL/SDL3/sdl_pointer.cpp +++ b/client/SDL/SDL3/sdl_pointer.cpp @@ -127,12 +127,15 @@ bool sdl_Pointer_Set_Process(SdlContext* sdl) const Uint32 id = SDL_GetWindowID(window); - auto pos = sdl->pixelToScreen(id, SDL_FRect{ ix, iy, isw, ish }); + const SDL_FRect orig{ ix, iy, isw, ish }; + auto pos = sdl->pixelToScreen(id, orig); + WLog_Print(sdl->getWLog(), WLOG_DEBUG, "cursor scale: pixel:%s, display:%s", + sdl::utils::toString(orig).c_str(), sdl::utils::toString(pos).c_str()); sdl_Pointer_Clear(ptr); ptr->image = - SDL_CreateSurface(static_cast(pos.w), static_cast(pos.h), sdl->pixelFormat()); + SDL_CreateSurface(static_cast(orig.w), static_cast(orig.h), sdl->pixelFormat()); if (!ptr->image) { WLog_Print(sdl->getWLog(), WLOG_ERROR, "SDL_CreateSurface failed"); @@ -170,31 +173,33 @@ bool sdl_Pointer_Set_Process(SdlContext* sdl) const auto hidpi_scale = sdl->pixelToScreen(fw->id(), SDL_FPoint{ static_cast(ptr->image->w), static_cast(ptr->image->h) }); - auto normal = SDL_CreateSurface(static_cast(hidpi_scale.x), - static_cast(hidpi_scale.y), ptr->image->format); + std::unique_ptr normal{ + SDL_CreateSurface(static_cast(hidpi_scale.x), static_cast(hidpi_scale.y), + ptr->image->format), + SDL_DestroySurface + }; assert(normal); - if (!SDL_BlitSurfaceScaled(ptr->image, nullptr, normal, nullptr, + if (!SDL_BlitSurfaceScaled(ptr->image, nullptr, normal.get(), nullptr, SDL_ScaleMode::SDL_SCALEMODE_LINEAR)) { WLog_Print(sdl->getWLog(), WLOG_ERROR, "SDL_BlitSurfaceScaled failed"); return false; } - if (!SDL_AddSurfaceAlternateImage(normal, ptr->image)) + if (!SDL_AddSurfaceAlternateImage(normal.get(), ptr->image)) { WLog_Print(sdl->getWLog(), WLOG_ERROR, "SDL_AddSurfaceAlternateImage failed"); return false; } - ptr->cursor = SDL_CreateColorCursor(normal, static_cast(pos.x), static_cast(pos.y)); + ptr->cursor = + SDL_CreateColorCursor(normal.get(), static_cast(pos.x), static_cast(pos.y)); if (!ptr->cursor) { - WLog_Print(sdl->getWLog(), WLOG_ERROR, "SDL_CreateColorCursor(%fx%f) failed", - static_cast(pos.x), static_cast(pos.y)); + WLog_Print(sdl->getWLog(), WLOG_ERROR, "SDL_CreateColorCursor(display:%s, pixel:%s} failed", + sdl::utils::toString(pos).c_str(), sdl::utils::toString(orig).c_str()); return false; } - SDL_DestroySurface(normal); - if (!SDL_SetCursor(ptr->cursor)) { WLog_Print(sdl->getWLog(), WLOG_ERROR, "SDL_SetCursor failed"); diff --git a/client/SDL/SDL3/sdl_utils.cpp b/client/SDL/SDL3/sdl_utils.cpp index 436033106..49401d970 100644 --- a/client/SDL/SDL3/sdl_utils.cpp +++ b/client/SDL/SDL3/sdl_utils.cpp @@ -474,6 +474,21 @@ namespace sdl::utils return ss.str(); } + + std::string toString(SDL_Rect rect) + { + std::stringstream ss; + ss << "SDL_Rect{" << rect.x << "x" << rect.y << "-" << rect.w << "x" << rect.h << "}"; + return ss.str(); + } + + std::string toString(SDL_FRect rect) + { + std::stringstream ss; + ss << "SDL_Rect{" << rect.x << "x" << rect.y << "-" << rect.w << "x" << rect.h << "}"; + return ss.str(); + } + } // namespace sdl::utils namespace sdl::error diff --git a/client/SDL/SDL3/sdl_utils.hpp b/client/SDL/SDL3/sdl_utils.hpp index b4b449406..92ad4ec4d 100644 --- a/client/SDL/SDL3/sdl_utils.hpp +++ b/client/SDL/SDL3/sdl_utils.hpp @@ -86,6 +86,8 @@ namespace sdl::utils [[nodiscard]] std::string toString(SDL_DisplayOrientation orientation); [[nodiscard]] std::string toString(const SDL_DisplayMode* mode); [[nodiscard]] std::string toString(Uint32 type); + [[nodiscard]] std::string toString(SDL_Rect rect); + [[nodiscard]] std::string toString(SDL_FRect rect); [[nodiscard]] UINT32 orientaion_to_rdp(SDL_DisplayOrientation orientation);