SDL3 clipboard: text/plain may contain escaped Unicode while text/plain;charset=utf-8 has proper UTF-8 on Wayland
Author: rat29aCreated Sep 28, 2026Updated Sep 28, 2026
Summary
When copying text with Czech diacritics (ěščřžýá, or any non-ASCII characters) on Wayland and pasting into an RDP session via sdl-freerdp3, the pasted text appears as literal Unicode escape sequences (\u011b\u0161\u010d\u0159\u017e) instead of the actual characters.
Root cause
Wayland clipboard managers (observed on KWin, likely also GNOME/gnome-shell) can expose different content under different MIME types for the same clipboard copy:
| MIME type | Content | Interpretation |
|--------------------------|--------------------------------|-------------------------|
| text/plain | \u011b\u0161\u010d\u0159\u017e | Literal escaped Unicode |
| text/plain;charset=utf-8 | ěščřžýá | Proper UTF-8 |
In sdl_clip.cpp, getCurrentTextMime() iterates through s_mime_text() and returns the first match: {"text/plain", "text/plain;charset=utf-8", …}. Since text/plain is first, the escaped data is used.
Additionally, even if text/plain;charset=utf-8 were preferred for reading, winpr's clipboard lacks a synthesizer to convert from that MIME's format ID to CF_UNICODETEXT — synthesizers exist only for "text/plain" (without charset).
Fix
Two changes in ReceiveFormatDataRequestHandle:
1. Prefer text/plain;charset=utf-8 as data source when available
2. Always store under the "text/plain" format ID so existing synthesizers work
diff
--- a/client/SDL/SDL3/sdl_clip.cpp
+++ b/client/SDL/SDL3/sdl_clip.cpp
@@ -677,10 +677,14 @@ std::shared_ptr<BYTE> sdlClip::ReceiveFormatDataRequestHandle(
case CF_TEXT:
case CF_OEMTEXT:
case CF_UNICODETEXT:
- mime = getCurrentTextMime();
+ // Prefer charset-qualified for correct UTF-8
+ if (SDL_HasClipboardData(mime_text_utf8))
+ mime = mime_text_utf8;
+ else
+ mime = getCurrentTextMime();
if (!mime)
return {};
- localFormatId = ClipboardGetFormatId(clipboard->_system, mime);
+ localFormatId = ClipboardGetFormatId(clipboard->_system, mime_text_plain);
break;
case CF_DIB:
Testing
1. Copy Czech text from a Wayland-native app (Firefox on Wayland)
2. Verify: wl-paste -t text/plain | xxd vs wl-paste -t text/plain\;charset=utf-8 | xxd
3. Connect via sdl-freerdp3 and paste into Notepad on Windows
4. Confirm diacritics display correctly
Environment
- FreeRDP 3.31.1 / 3.32.0
- Arch Linux, Wayland (KDE Plasma 6)
- sdl-freerdp3Source: FreeRDP/FreeRDP