From 35df9e95add081d5ff06caab990b603034c90806 Mon Sep 17 00:00:00 2001 From: David Fort Date: Mon, 30 Sep 2024 08:16:18 +0200 Subject: [PATCH 1/2] sdl3: fix build with last SDL_ttf --- client/SDL/SDL3/dialogs/sdl_widget.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/SDL/SDL3/dialogs/sdl_widget.cpp b/client/SDL/SDL3/dialogs/sdl_widget.cpp index fadf7ff0f..4781bb9fc 100644 --- a/client/SDL/SDL3/dialogs/sdl_widget.cpp +++ b/client/SDL/SDL3/dialogs/sdl_widget.cpp @@ -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"); From d05c781cd994077112cf635fd13b1d961b57b959 Mon Sep 17 00:00:00 2001 From: David Fort Date: Mon, 7 Oct 2024 10:02:26 +0200 Subject: [PATCH 2/2] sdl3 client: take in account last SDL changes This patch uses the last changes in the SDL3 clipboard to have that clean separation between mime type announcement and retrieving the corresponding clipboard data. With these changes we don't have anymore that spurious notifications where we loose the clipboard ownership, and also we don't trigger data retrieval by calling functions like SDL_ClipboardHasText(). --- client/SDL/SDL3/sdl_clip.cpp | 72 ++++++++++++++++++++------------- client/SDL/SDL3/sdl_clip.hpp | 2 +- client/SDL/SDL3/sdl_freerdp.cpp | 2 +- 3 files changed, 46 insertions(+), 30 deletions(-) diff --git a/client/SDL/SDL3/sdl_clip.cpp b/client/SDL/SDL3/sdl_clip.cpp index 1cd77cf7e..f10b9107b 100644 --- a/client/SDL/SDL3/sdl_clip.cpp +++ b/client/SDL/SDL3/sdl_clip.cpp @@ -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 clientFormatNames; std::vector 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; diff --git a/client/SDL/SDL3/sdl_clip.hpp b/client/SDL/SDL3/sdl_clip.hpp index 9b30b3a1c..cc59f2dee 100644 --- a/client/SDL/SDL3/sdl_clip.hpp +++ b/client/SDL/SDL3/sdl_clip.hpp @@ -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(); diff --git a/client/SDL/SDL3/sdl_freerdp.cpp b/client/SDL/SDL3/sdl_freerdp.cpp index 7de876cd2..368096c55 100644 --- a/client/SDL/SDL3/sdl_freerdp.cpp +++ b/client/SDL/SDL3/sdl_freerdp.cpp @@ -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: