Merge pull request #10711 from hardening/sdl3_fix3

Fixes for the SDL3 client
This commit is contained in:
akallabeth
2024-10-07 12:11:32 +02:00
committed by GitHub
4 changed files with 50 additions and 34 deletions

View File

@@ -81,7 +81,7 @@ SdlWidget::SdlWidget(SdlWidget&& other) noexcept
SDL_Texture* SdlWidget::render_text(SDL_Renderer* renderer, const std::string& text,
SDL_Color fgcolor, SDL_FRect& src, SDL_FRect& dst)
{
auto surface = TTF_RenderUTF8_Blended(_font, text.c_str(), fgcolor);
auto surface = TTF_RenderText_Blended(_font, text.c_str(), 0, fgcolor);
if (!surface)
{
widget_log_error(-1, "TTF_RenderText_Blended");
@@ -98,7 +98,7 @@ SDL_Texture* SdlWidget::render_text(SDL_Renderer* renderer, const std::string& t
int w = 0;
int h = 0;
TTF_SizeUTF8(_font, text.c_str(), &w, &h);
TTF_GetTextSize(_font, text.c_str(), 0, &w, &h);
src.w = w;
src.h = h;
@@ -135,8 +135,8 @@ SDL_Texture* SdlWidget::render_text_wrapped(SDL_Renderer* renderer, const std::s
{
Sint32 w = 0;
Sint32 h = 0;
TTF_SizeUTF8(_font, " ", &w, &h);
auto surface = TTF_RenderUTF8_Blended_Wrapped(_font, text.c_str(), fgcolor, _text_width);
TTF_GetTextSize(_font, " ", 0, &w, &h);
auto surface = TTF_RenderText_Blended_Wrapped(_font, text.c_str(), 0, fgcolor, _text_width);
if (!surface)
{
widget_log_error(-1, "TTF_RenderText_Blended");

View File

@@ -129,9 +129,9 @@ BOOL sdlClip::uninit(CliprdrClientContext* clip)
return TRUE;
}
bool sdlClip::handle_update()
bool sdlClip::handle_update(const SDL_ClipboardEvent& ev)
{
if (!_ctx || !_sync)
if (!_ctx || !_sync || ev.owner)
return true;
clearServerFormats();
@@ -149,36 +149,51 @@ bool sdlClip::handle_update()
std::vector<std::string> clientFormatNames;
std::vector<CLIPRDR_FORMAT> clientFormats;
if (SDL_HasClipboardText())
{
clientFormats.push_back({ CF_TEXT, nullptr });
clientFormats.push_back({ CF_OEMTEXT, nullptr });
clientFormats.push_back({ CF_UNICODETEXT, nullptr });
}
if (SDL_HasClipboardData(mime_html.c_str()))
clientFormatNames.emplace_back(type_HtmlFormat);
for (auto& mime : mime_bitmap)
size_t nformats = ev.n_mime_types;
const char** clipboard_mime_formats = ev.mime_types;
WLog_Print(_log, WLOG_TRACE, "SDL has %d formats", nformats);
bool textPushed = false;
bool imgPushed = false;
for (size_t i = 0; i < nformats; i++)
{
if (SDL_HasClipboardData(mime.c_str()))
std::string local_mime = clipboard_mime_formats[i];
WLog_Print(_log, WLOG_TRACE, " - %s", local_mime.c_str());
if (std::find(mime_text.begin(), mime_text.end(), local_mime) != mime_text.end())
{
clientFormats.push_back({ CF_DIB, nullptr });
clientFormats.push_back({ CF_DIBV5, nullptr });
for (auto& bmp : mime_bitmap)
clientFormatNames.push_back(bmp);
for (auto& img : mime_images)
clientFormatNames.push_back(img);
break;
/* text formats */
if (!textPushed)
{
clientFormats.push_back({ CF_TEXT, nullptr });
clientFormats.push_back({ CF_OEMTEXT, nullptr });
clientFormats.push_back({ CF_UNICODETEXT, nullptr });
textPushed = true;
}
}
}
else if (local_mime == mime_html)
/* html */
clientFormatNames.emplace_back(type_HtmlFormat);
else if (std::find(mime_bitmap.begin(), mime_bitmap.end(), local_mime) != mime_bitmap.end())
{
/* image formats */
if (!imgPushed)
{
clientFormats.push_back({ CF_DIB, nullptr });
clientFormats.push_back({ CF_DIBV5, nullptr });
for (auto& img : mime_images)
{
if (SDL_HasClipboardData(img.c_str()))
clientFormatNames.push_back(img);
for (auto& bmp : mime_bitmap)
clientFormatNames.push_back(bmp);
for (auto& img : mime_images)
clientFormatNames.push_back(img);
imgPushed = true;
}
}
}
for (auto& name : clientFormatNames)
@@ -227,7 +242,8 @@ UINT sdlClip::MonitorReady(CliprdrClientContext* context, const CLIPRDR_MONITOR_
return ret;
clipboard->_sync = true;
if (!clipboard->handle_update())
SDL_ClipboardEvent ev = { SDL_EVENT_CLIPBOARD_UPDATE, 0, 0, false, NULL, 0 };
if (!clipboard->handle_update(ev))
return ERROR_INTERNAL_ERROR;
return CHANNEL_RC_OK;

View File

@@ -94,7 +94,7 @@ class sdlClip
BOOL init(CliprdrClientContext* clip);
BOOL uninit(CliprdrClientContext* clip);
bool handle_update();
bool handle_update(const SDL_ClipboardEvent& ev);
private:
UINT SendClientCapabilities();

View File

@@ -1015,7 +1015,7 @@ static int sdl_run(SdlContext* sdl)
sdl_Pointer_Set_Process(&windowEvent.user);
break;
case SDL_EVENT_CLIPBOARD_UPDATE:
sdl->clip.handle_update();
sdl->clip.handle_update(windowEvent.clipboard);
break;
case SDL_EVENT_USER_QUIT:
default: