[Bf-blender-cvs] [727cc426bc7] master: Fix drag & drop in Wayland with some applications

Campbell Barton noreply at git.blender.org
Thu Aug 4 14:34:20 CEST 2022


Commit: 727cc426bc723c8757941ce9bf23745ee5f6ab9d
Author: Campbell Barton
Date:   Thu Aug 4 22:33:22 2022 +1000
Branches: master
https://developer.blender.org/rB727cc426bc723c8757941ce9bf23745ee5f6ab9d

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).

===================================================================

M	intern/ghost/intern/GHOST_SystemWayland.cpp

===================================================================

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<std::string> 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());
       }



More information about the Bf-blender-cvs mailing list