From 727cc426bc723c8757941ce9bf23745ee5f6ab9d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 4 Aug 2022 22:33:22 +1000 Subject: Fix drag & drop in Wayland with some applications Drag & drop worked with GTK3 apps but not QT5 (pcmanfm-qt for eg) as files are separated by '\n' instead of '\r\n'. Resolve by supporting both (follow up to T99737). --- intern/ghost/intern/GHOST_SystemWayland.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'intern/ghost') diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp index 5eea90015b1..7da8d56ed0d 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cpp +++ b/intern/ghost/intern/GHOST_SystemWayland.cpp @@ -1227,7 +1227,9 @@ static void data_device_handle_drop(void *data, struct wl_data_device * /*wl_dat if (mime_receive == mime_text_uri) { static constexpr const char *file_proto = "file://"; - static constexpr const char *crlf = "\r\n"; + /* NOTE: some applications CRLF (`\r\n`) GTK3 for e.g. & others don't `pcmanfm-qt`. + * So support both, once `\n` is found, strip the preceding `\r` if found. */ + static constexpr const char *lf = "\n"; GHOST_WindowWayland *win = ghost_wl_surface_user_data(surface); std::vector uris; @@ -1236,12 +1238,16 @@ static void data_device_handle_drop(void *data, struct wl_data_device * /*wl_dat while (true) { pos = data.find(file_proto, pos); const size_t start = pos + sizeof(file_proto) - 1; - pos = data.find(crlf, pos); - const size_t end = pos; + pos = data.find(lf, pos); if (pos == std::string::npos) { break; } + /* Account for 'CRLF' case. */ + size_t end = pos; + if (data[end - 1] == '\r') { + end -= 1; + } uris.push_back(data.substr(start, end - start)); CLOG_INFO(LOG, 2, "drop_read_uris pos=%zu, text_uri=\"%s\"", start, uris.back().c_str()); } -- cgit v1.2.3