From ca127106ee9533f0a47dc1775b72da889f745cf6 Mon Sep 17 00:00:00 2001 From: Dragon-Baroque <74261498+Dragon-Baroque@users.noreply.github.com> Date: Tue, 6 Aug 2024 13:50:06 +0200 Subject: [PATCH] Add MIME targets to SDL_EVENT_DROP_TEXT in X11 src/video/x11/SDL_x11events.c Add Text targets "text/plain;charset=utf-8", "UTF8_STRING", "TEXT" to "text/plain". --- src/video/x11/SDL_x11events.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index b5b5d60f81..94ebf47ce8 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -126,9 +126,19 @@ static Atom X11_PickTarget(Display *disp, Atom list[], int list_count) int i; for (i = 0; i < list_count && request == None; i++) { name = X11_XGetAtomName(disp, list[i]); - if ((SDL_strcmp("text/uri-list", name) == 0) || (SDL_strcmp("text/plain", name) == 0)) { + /* Preferred MIME targets */ + if ((SDL_strcmp("text/uri-list", name) == 0) || + (SDL_strcmp("text/plain;charset=utf-8", name) == 0) || + (SDL_strcmp("UTF8_STRING", name) == 0)) { request = list[i]; } + /* Fallback MIME targets */ + if ((SDL_strcmp("text/plain", name) == 0) || + (SDL_strcmp("TEXT", name) == 0)) { + if (request == None) { + request = list[i]; + } + } X11_XFree(name); } return request; @@ -1759,7 +1769,10 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent) if (name) { char *token = SDL_strtok_r((char *)p.data, "\r\n", &saveptr); while (token) { - if (SDL_strcmp("text/plain", name) == 0) { + if ((SDL_strcmp("text/plain;charset=utf-8", name) == 0) || + (SDL_strcmp("UTF8_STRING", name) == 0) || + (SDL_strcmp("text/plain", name) == 0) || + (SDL_strcmp("TEXT", name) == 0)) { SDL_SendDropText(data->window, token); } else if (SDL_strcmp("text/uri-list", name) == 0) { if (SDL_URIToLocal(token, token) >= 0) {