macos: Provide fallback pasteboard for gtype Dnd
authorArjan Molenaar <gaphor@gmail.com>
Wed, 11 Jan 2023 22:17:24 +0000 (23:17 +0100)
committerArjan Molenaar <gaphor@gmail.com>
Sun, 15 Jan 2023 09:03:47 +0000 (10:03 +0100)
The Drag data should pass through the macos pasteboard system.
We need to provide some pasteboard type. Let's make it a "URL",
which is a pretty generic type anyway.

gdk/macos/gdkmacospasteboard.c

index f74f9818cdcee0419973d77adf32462ae9ff7811..66b3c9f03b427c3aacf67dc6780c3269718ebc34 100644 (file)
@@ -372,7 +372,7 @@ _gdk_macos_pasteboard_register_drag_types (NSWindow *window)
   serializable = gdk_content_formats_union_serialize_mime_types (serializable);
   mime_types = gdk_content_formats_get_mime_types (serializable, &n_mime_types);
 
-  for (guint i = 0; mime_types[i]; i++)
+  for (gsize i = 0; i < n_mime_types; i++)
     {
       const char *mime_type = mime_types[i];
       NSPasteboardType type;
@@ -386,6 +386,25 @@ _gdk_macos_pasteboard_register_drag_types (NSWindow *window)
         }
     }
 
+  gdk_content_formats_unref (serializable);
+
+  /* Default to an url type (think gobject://internal)
+   * to support internal, GType-based DnD.
+   */
+  if (n_mime_types == 0)
+    {
+      GdkContentFormats *formats;
+      gsize n_gtypes;
+
+      formats = gdk_content_provider_ref_formats (self->_contentProvider);
+      gdk_content_formats_get_gtypes (formats, &n_gtypes);
+
+      if (n_gtypes)
+        [ret addObject:NSPasteboardTypeURL];
+
+      gdk_content_formats_unref (formats);
+    }
+
   return g_steal_pointer (&ret);
 }