From e5e474baaec391fe2a84fab1ebae978d9355dc2f Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sun, 22 May 2022 11:02:24 +0800 Subject: [PATCH] Fix compiler warnings on Mac OS X 10.12 * configure.ac: Check for Mac OS X 12 and link with UniformTypeIdentifiers.framework. * src/nsfns.m (IOMasterPort): Define to `IOMainPort' on Mac OS X 12. (ns_implicitly_set_icon_type, Fns_read_file_name): * src/nsxwidget.m: ([XwWebView initWithFrame:configuration:xwidget:]): Fix uses of obsolete things. --- configure.ac | 13 +++++++++++++ src/nsfns.m | 38 ++++++++++++++++++++++++++++++++++++-- src/nsxwidget.m | 3 +++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 3d5eb7f9c44..1d2d1f190bf 100644 --- a/configure.ac +++ b/configure.ac @@ -2081,6 +2081,16 @@ Either fix this, or re-configure with the option '--without-ns'.])]) fi fi + AC_CACHE_CHECK([for Mac OS X 12.0 or later], + [emacs_cv_macosx_12_0], + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 120000 +Mac OS X 12.x or later. +#endif + ]])], [emacs_cv_macosx_12_0=no], + [emacs_cv_macosx_12_0=yes])) + if test "${with_native_image_api}" = yes; then AC_DEFINE(HAVE_NATIVE_IMAGE_API, 1, [Define to use native OS APIs for images.]) NATIVE_IMAGE_API="yes (ns)" @@ -6216,6 +6226,9 @@ case "$opsys" in if test "$NS_IMPL_COCOA" = "yes"; then libs_nsgui="$libs_nsgui -framework IOKit -framework Carbon \ -framework IOSurface -framework QuartzCore" + if test "$emacs_cv_macosx_12_0" = "yes"; then + libs_nsgui="$libs_nsgui -framework UniformTypeIdentifiers" + fi fi else libs_nsgui= diff --git a/src/nsfns.m b/src/nsfns.m index f82665a3000..a2f9c26b550 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -47,6 +47,13 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu) #ifdef NS_IMPL_COCOA #include #include "macfont.h" + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 120000 +#include +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 120000 +#define IOMasterPort IOMainPort +#endif +#endif #endif #ifdef HAVE_NS @@ -789,11 +796,13 @@ ns_implicitly_set_icon_type (struct frame *f) Lisp_Object chain, elt; NSAutoreleasePool *pool; BOOL setMini = YES; + NSWorkspace *workspace; NSTRACE ("ns_implicitly_set_icon_type"); block_input (); pool = [[NSAutoreleasePool alloc] init]; + workspace = [NSWorkspace sharedWorkspace]; if (f->output_data.ns->miniimage && [[NSString stringWithLispString:f->name] isEqualToString: [(NSImage *)f->output_data.ns->miniimage name]]) @@ -838,7 +847,19 @@ ns_implicitly_set_icon_type (struct frame *f) if (image == nil) { - image = [[[NSWorkspace sharedWorkspace] iconForFileType: @"text"] retain]; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 120000 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000 + if ([workspace respondsToSelector: @selector (iconForContentType:)]) +#endif + image = [[workspace iconForContentType: + [UTType typeWithIdentifier: @"text"]] retain]; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000 + else +#endif +#endif +#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000 + image = [[workspace iconForFileType: @"text"] retain]; +#endif setMini = NO; } @@ -1757,7 +1778,20 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */) ns_fd_data.ret = NO; #ifdef NS_IMPL_COCOA if (! NILP (mustmatch) || ! NILP (dir_only_p)) - [panel setAllowedFileTypes: nil]; + { +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 120000 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000 + if ([panel respondsToSelector: @selector (setAllowedContentTypes:)]) +#endif + [panel setAllowedContentTypes: [NSArray array]]; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000 + else +#endif +#endif +#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000 + [panel setAllowedFileTypes: nil]; +#endif + } if (dirS) [panel setDirectoryURL: [NSURL fileURLWithPath: dirS]]; if (initS && NILP (Ffile_directory_p (init))) [panel setNameFieldStringValue: [initS lastPathComponent]]; diff --git a/src/nsxwidget.m b/src/nsxwidget.m index f79873235cb..be0eba0bcb1 100644 --- a/src/nsxwidget.m +++ b/src/nsxwidget.m @@ -69,10 +69,13 @@ along with GNU Emacs. If not, see . */ [configuration.preferences setValue:@YES forKey:@"developerExtrasEnabled"]; +#if 0 /* Plugins are not supported by Mac OS X anymore. */ Lisp_Object enablePlugins = Fintern (build_string ("xwidget-webkit-enable-plugins"), Qnil); + if (!EQ (Fsymbol_value (enablePlugins), Qnil)) configuration.preferences.plugInsEnabled = YES; +#endif self = [super initWithFrame:frame configuration:configuration]; if (self) -- 2.39.2