unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: Alan Third <alan@idiocy.org>
Cc: 33035@debbugs.gnu.org, Lars Ingebrigtsen <larsi@gnus.org>,
	Philipp Stephani <p.stephani2@gmail.com>
Subject: bug#33035: 27.0.50; Deprecated macOS functions
Date: Sun, 10 Jan 2021 17:53:09 +0100	[thread overview]
Message-ID: <8CE304B6-BBB8-4B2D-A1E9-BAC6EDCE1706@acm.org> (raw)
In-Reply-To: <X/sp1ilhO/3nIiVj@breton.holly.idiocy.org>

[-- Attachment #1: Type: text/plain, Size: 198 bytes --]

10 jan. 2021 kl. 17.22 skrev Alan Third <alan@idiocy.org>:

> And after a quick look, I don't think macOS < 10.13 will work either.

So it seems! Updated patch below. (Still only tested on 10.14.)


[-- Attachment #2: 0001-Avoid-macOS-NSFilenamesPboardType-warning-bug-33035.patch --]
[-- Type: application/octet-stream, Size: 4540 bytes --]

From d87155035a81224af618625a8ae2fbcc58b0aa6c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Sun, 10 Jan 2021 17:05:18 +0100
Subject: [PATCH] Avoid macOS NSFilenamesPboardType warning (bug#33035)

* src/nsterm.h (NS_USE_NSPasteboardTypeFileURL): New #define.
* src/nsterm.m (ns_term_init):
([EmacsView performDragOperation:]):
* src/nsselect.m (ns_string_to_symbol):
(nxatoms_of_nsselect):
NSFilenamesPboardType was deprecated in macOS 10.14; use
NSPasteboardTypeFileURL instead when available.
---
 src/nsselect.m | 15 +++++++++++++--
 src/nsterm.h   |  9 +++++++++
 src/nsterm.m   | 21 ++++++++++++++++++---
 3 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/src/nsselect.m b/src/nsselect.m
index 27db9248e4..5ab3ef77fe 100644
--- a/src/nsselect.m
+++ b/src/nsselect.m
@@ -78,7 +78,13 @@ Updated by Christian Limpach (chris@nice.ch)
     return QSECONDARY;
   if ([t isEqualToString: NSPasteboardTypeString])
     return QTEXT;
-  if ([t isEqualToString: NSFilenamesPboardType])
+  if ([t isEqualToString:
+#if NS_USE_NSPasteboardTypeFileURL != 0
+           NSPasteboardTypeFileURL
+#else
+           NSFilenamesPboardType
+#endif
+       ])
     return QFILE_NAME;
   if ([t isEqualToString: NSPasteboardTypeTabularText])
     return QTEXT;
@@ -467,7 +473,12 @@ Updated by Christian Limpach (chris@nice.ch)
 	     [NSNumber numberWithLong:0], NXPrimaryPboard,
 	     [NSNumber numberWithLong:0], NXSecondaryPboard,
 	     [NSNumber numberWithLong:0], NSPasteboardTypeString,
-	     [NSNumber numberWithLong:0], NSFilenamesPboardType,
+	     [NSNumber numberWithLong:0],
+#if NS_USE_NSPasteboardTypeFileURL != 0
+                                          NSPasteboardTypeFileURL,
+#else
+                                          NSFilenamesPboardType,
+#endif
 	     [NSNumber numberWithLong:0], NSPasteboardTypeTabularText,
 	 nil] retain];
 }
diff --git a/src/nsterm.h b/src/nsterm.h
index 2c9d8e85ba..eae1d0725e 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -39,6 +39,15 @@
 typedef float EmacsCGFloat;
 #endif
 
+/* NSFilenamesPboardType is deprecated in macOS 10.14, but
+   NSPasteboardTypeFileURL is only available in 10.13 (and GNUstep
+   probably lacks it too). */
+#if defined NS_IMPL_COCOA && MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
+#define NS_USE_NSPasteboardTypeFileURL 1
+#else
+#define NS_USE_NSPasteboardTypeFileURL 0
+#endif
+
 /* ==========================================================================
 
    Trace support
diff --git a/src/nsterm.m b/src/nsterm.m
index 2defb9e2ee..c5815ce8d1 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -5602,7 +5602,11 @@ Needs to be here because ns_initialize_display_info () uses AppKit classes.
   ns_drag_types = [[NSArray arrayWithObjects:
                             NSPasteboardTypeString,
                             NSPasteboardTypeTabularText,
+#if NS_USE_NSPasteboardTypeFileURL != 0
+                            NSPasteboardTypeFileURL,
+#else
                             NSFilenamesPboardType,
+#endif
                             NSPasteboardTypeURL, nil] retain];
 
   /* If fullscreen is in init/default-frame-alist, focus isn't set
@@ -8533,9 +8537,19 @@ -(BOOL)performDragOperation: (id <NSDraggingInfo>) sender
     {
       return NO;
     }
-  /* FIXME: NSFilenamesPboardType is deprecated in 10.14, but the
-     NSURL method can only handle one file at a time.  Stick with the
-     existing code at the moment.  */
+#if NS_USE_NSPasteboardTypeFileURL != 0
+  else if ([type isEqualToString: NSPasteboardTypeFileURL])
+    {
+      type_sym = Qfile;
+
+      NSArray *urls = [pb readObjectsForClasses: @[[NSURL self]]
+                                        options: nil];
+      NSEnumerator *uenum = [urls objectEnumerator];
+      NSURL *url;
+      while ((url = [uenum nextObject]))
+        strings = Fcons ([[url path] lispString], strings);
+    }
+#else  // !NS_USE_NSPasteboardTypeFileURL
   else if ([type isEqualToString: NSFilenamesPboardType])
     {
       NSArray *files;
@@ -8551,6 +8565,7 @@ -(BOOL)performDragOperation: (id <NSDraggingInfo>) sender
       while ( (file = [fenum nextObject]) )
         strings = Fcons ([file lispString], strings);
     }
+#endif   // !NS_USE_NSPasteboardTypeFileURL
   else if ([type isEqualToString: NSPasteboardTypeURL])
     {
       NSURL *url = [NSURL URLFromPasteboard: pb];
-- 
2.21.1 (Apple Git-122.3)


  reply	other threads:[~2021-01-10 16:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-13 15:32 bug#33035: 27.0.50; Deprecated macOS functions Philipp
2020-08-16 17:45 ` Lars Ingebrigtsen
2021-01-10 13:25 ` Mattias Engdegård
2021-01-10 15:43   ` Alan Third
2021-01-10 16:22     ` Alan Third
2021-01-10 16:53       ` Mattias Engdegård [this message]
2021-01-18 12:03         ` Mattias Engdegård
2021-01-18 20:58           ` Alan Third
2021-01-10 16:22     ` Mattias Engdegård

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8CE304B6-BBB8-4B2D-A1E9-BAC6EDCE1706@acm.org \
    --to=mattiase@acm.org \
    --cc=33035@debbugs.gnu.org \
    --cc=alan@idiocy.org \
    --cc=larsi@gnus.org \
    --cc=p.stephani2@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).