[gtk/wip/chergert/gdk-macos-gdkdrag] wip more internal drag handling



commit f76ccf5a4058996ff87df8aaaea323152c5aede3
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jun 18 22:51:54 2021 -0700

    wip more internal drag handling

 gdk/macos/gdkmacospasteboard-private.h |  2 ++
 gdk/macos/gdkmacospasteboard.c         | 25 +++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
---
diff --git a/gdk/macos/gdkmacospasteboard-private.h b/gdk/macos/gdkmacospasteboard-private.h
index fdeb936535..166fa9b6a9 100644
--- a/gdk/macos/gdkmacospasteboard-private.h
+++ b/gdk/macos/gdkmacospasteboard-private.h
@@ -27,6 +27,8 @@
 
 G_BEGIN_DECLS
 
+#define GDK_MACOS_LOCAL_DND_MIME_TYPE "application/x-gtk-local-dnd"
+
 @interface GdkMacosPasteboardItemDataProvider : NSObject <NSPasteboardItemDataProvider>
 {
   GdkContentProvider *_contentProvider;
diff --git a/gdk/macos/gdkmacospasteboard.c b/gdk/macos/gdkmacospasteboard.c
index fcfc5b6b96..d30a2e90f5 100644
--- a/gdk/macos/gdkmacospasteboard.c
+++ b/gdk/macos/gdkmacospasteboard.c
@@ -33,6 +33,7 @@ enum {
   TYPE_COLOR,
   TYPE_TIFF,
   TYPE_PNG,
+  TYPE_INTERNAL,
   TYPE_LAST
 };
 
@@ -67,6 +68,8 @@ get_pasteboard_type (int type)
       pasteboard_types[TYPE_FILE_URL] = [[NSString alloc] initWithUTF8String:"public.file-url"];
 #endif
 
+      pasteboard_types[TYPE_INTERNAL] = [[NSString alloc] initWithUTF8String:"org.gtk.pasteboard.internal"];
+
       g_once_init_leave (&initialized, TRUE);
     }
 
@@ -90,6 +93,8 @@ _gdk_macos_pasteboard_from_ns_type (NSPasteboardType type)
     return g_intern_string ("image/tiff");
   else if ([type isEqualToString:PTYPE(PNG)])
     return g_intern_string ("image/png");
+  else if ([type isEqualToString:PTYPE(INTERNAL)])
+    return g_intern_string (GDK_MACOS_LOCAL_DND_MIME_TYPE);
 
   G_GNUC_END_IGNORE_DEPRECATIONS;
 
@@ -125,6 +130,10 @@ _gdk_macos_pasteboard_to_ns_type (const char       *mime_type,
     {
       return PTYPE(PNG);
     }
+  else if (g_strcmp0 (mime_type, GDK_MACOS_LOCAL_DND_MIME_TYPE) == 0)
+    {
+      return PTYPE(INTERNAL);
+    }
 
   return nil;
 }
@@ -283,6 +292,11 @@ _gdk_macos_pasteboard_read_async (GObject             *object,
       NSData *data = [pasteboard dataForType:PTYPE(PNG)];
       stream = create_stream_from_nsdata (data);
     }
+  else if (strcmp (mime_type, GDK_MACOS_LOCAL_DND_MIME_TYPE) == 0)
+    {
+      /* Should be internal copy */
+      g_warn_if_reached ();
+    }
 
   if (stream != NULL)
     {
@@ -332,6 +346,7 @@ _gdk_macos_pasteboard_register_drag_types (NSWindow *window)
                                                             PTYPE(COLOR),
                                                             PTYPE(TIFF),
                                                             PTYPE(PNG),
+                                                            PTYPE(INTERNAL),
                                                             nil]];
 }
 
@@ -386,6 +401,16 @@ _gdk_macos_pasteboard_register_drag_types (NSWindow *window)
         }
     }
 
+  if ([ret count] == 0)
+    {
+      NSPasteboardType type;
+      NSPasteboardType alternate = nil;
+
+      if ((type = _gdk_macos_pasteboard_to_ns_type (GDK_MACOS_LOCAL_DND_MIME_TYPE, &alternate)))
+        [ret addObject:type];
+    }
+
+
   return g_steal_pointer (&ret);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]