Merge pull request #12303 from akallabeth/sdl-pointer-fix

[client,sdl] improve cursor updates, fix surface sizes
This commit is contained in:
akallabeth
2026-02-14 12:18:35 +01:00
committed by GitHub
3 changed files with 33 additions and 11 deletions

View File

@@ -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<int>(pos.w), static_cast<int>(pos.h), sdl->pixelFormat());
SDL_CreateSurface(static_cast<int>(orig.w), static_cast<int>(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<float>(ptr->image->w),
static_cast<float>(ptr->image->h) });
auto normal = SDL_CreateSurface(static_cast<int>(hidpi_scale.x),
static_cast<int>(hidpi_scale.y), ptr->image->format);
std::unique_ptr<SDL_Surface, void (*)(SDL_Surface*)> normal{
SDL_CreateSurface(static_cast<int>(hidpi_scale.x), static_cast<int>(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<int>(pos.x), static_cast<int>(pos.y));
ptr->cursor =
SDL_CreateColorCursor(normal.get(), static_cast<int>(pos.x), static_cast<int>(pos.y));
if (!ptr->cursor)
{
WLog_Print(sdl->getWLog(), WLOG_ERROR, "SDL_CreateColorCursor(%fx%f) failed",
static_cast<double>(pos.x), static_cast<double>(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");

View File

@@ -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

View File

@@ -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);