aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Third2017-07-06 23:10:49 +0100
committerAlan Third2017-08-16 20:56:55 +0100
commit69f2b755f44a5e447b3ad482ce0b409764fa10e6 (patch)
tree10765f8a1a48d03ed87f02321f0928e21c2567cf /src
parent3505b77ad7b54e5208685b6e229c76387120d5a1 (diff)
downloademacs-69f2b755f44a5e447b3ad482ce0b409764fa10e6.tar.gz
emacs-69f2b755f44a5e447b3ad482ce0b409764fa10e6.zip
Allow use of run-time OS version checks on macOS (bug#27810)
* src/nsterm.h (NSWindowTabbingMode): Define in pre-Sierra macOS. (MAC_OS_X_VERSION_10_6, MAC_OS_X_VERSION_10_7, MAC_OS_X_VERSION_10_8, MAC_OS_X_VERSION_10_9, MAC_OS_X_VERSION_10_12, HAVE_NATIVE_FS): Remove defines. (NSWindowStyleMaskFullScreen, NSWindowCollectionBehaviorFullScreenPrimary, NSApplicationPresentationFullScreen, NSApplicationPresentationAutoHideToolbar): Define in macOS 10.6. * src/nsterm.m (colorForEmacsRed, colorUsingDefaultColorSpace, check_native_fs, ns_read_socket, ns_select, runAlertPanel, initFrameFromEmacs, windowDidMiniaturize, windowDidEnterFullScreen, windowDidExitFullScreen, isFullscreen, updateCollectionBehavior, toggleFullScreen, constrainFrameRect, scrollerWidth, syms_of_nsterm): Allow use of run-time checks and replace version check macros. * src/nsfns.m (ns_screen_name): Use run-time OS version checks. * src/macfont.m (macfont_draw): Use run-time OS version checks. * src/nsmenu.m (menuWillOpen): Use run-time OS version checks. Co-authored-by: Charles A. Roelli <charles@aurox.ch>
Diffstat (limited to 'src')
-rw-r--r--src/macfont.m18
-rw-r--r--src/nsfns.m83
-rw-r--r--src/nsmenu.m9
-rw-r--r--src/nsterm.h48
-rw-r--r--src/nsterm.m191
5 files changed, 211 insertions, 138 deletions
diff --git a/src/macfont.m b/src/macfont.m
index 4d310e47aec..19145f92c0a 100644
--- a/src/macfont.m
+++ b/src/macfont.m
@@ -2869,11 +2869,19 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y,
2869 and synthetic bold looks thinner on such environments. 2869 and synthetic bold looks thinner on such environments.
2870 Apple says there are no plans to address this issue 2870 Apple says there are no plans to address this issue
2871 (rdar://11644870) currently. So we add a workaround. */ 2871 (rdar://11644870) currently. So we add a workaround. */
2872#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 2872#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
2873 CGContextSetLineWidth (context, synthetic_bold_factor * font_size 2873#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
2874 * [[FRAME_NS_VIEW(f) window] backingScaleFactor]); 2874 if ([[FRAME_NS_VIEW(f) window] respondsToSelector:
2875#else 2875 @selector(backingScaleFactor)])
2876 CGContextSetLineWidth (context, synthetic_bold_factor * font_size); 2876#endif
2877 CGContextSetLineWidth (context, synthetic_bold_factor * font_size
2878 * [[FRAME_NS_VIEW(f) window] backingScaleFactor]);
2879#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
2880 else
2881#endif
2882#endif
2883#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
2884 CGContextSetLineWidth (context, synthetic_bold_factor * font_size);
2877#endif 2885#endif
2878 CG_SET_STROKE_COLOR_WITH_FACE_FOREGROUND (context, face, f); 2886 CG_SET_STROKE_COLOR_WITH_FACE_FOREGROUND (context, face, f);
2879 } 2887 }
diff --git a/src/nsfns.m b/src/nsfns.m
index 36748cebb8b..e19e4e2641a 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -1592,7 +1592,7 @@ ns_run_file_dialog (void)
1592} 1592}
1593 1593
1594#ifdef NS_IMPL_COCOA 1594#ifdef NS_IMPL_COCOA
1595#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_9 1595#if MAC_OS_X_VERSION_MAX_ALLOWED > 1090
1596#define MODAL_OK_RESPONSE NSModalResponseOK 1596#define MODAL_OK_RESPONSE NSModalResponseOK
1597#endif 1597#endif
1598#endif 1598#endif
@@ -2512,52 +2512,61 @@ ns_screen_name (CGDirectDisplayID did)
2512{ 2512{
2513 char *name = NULL; 2513 char *name = NULL;
2514 2514
2515#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 2515#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090
2516 mach_port_t masterPort; 2516#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
2517 io_iterator_t it; 2517 if (CGDisplayIOServicePort == NULL)
2518 io_object_t obj; 2518#endif
2519 {
2520 mach_port_t masterPort;
2521 io_iterator_t it;
2522 io_object_t obj;
2519 2523
2520 // CGDisplayIOServicePort is deprecated. Do it another (harder) way. 2524 /* CGDisplayIOServicePort is deprecated. Do it another (harder) way.
2521 2525
2522 if (IOMasterPort (MACH_PORT_NULL, &masterPort) != kIOReturnSuccess 2526 Is this code OK for macOS < 10.9, and GNUstep? I suspect it is,
2523 || IOServiceGetMatchingServices (masterPort, 2527 in which case is it worth keeping the other method in here? */
2524 IOServiceMatching ("IONDRVDevice"),
2525 &it) != kIOReturnSuccess)
2526 return name;
2527 2528
2528 /* Must loop until we find a name. Many devices can have the same unit 2529 if (IOMasterPort (MACH_PORT_NULL, &masterPort) != kIOReturnSuccess
2529 number (represents different GPU parts), but only one has a name. */ 2530 || IOServiceGetMatchingServices (masterPort,
2530 while (! name && (obj = IOIteratorNext (it))) 2531 IOServiceMatching ("IONDRVDevice"),
2531 { 2532 &it) != kIOReturnSuccess)
2532 CFMutableDictionaryRef props; 2533 return name;
2533 const void *val; 2534
2534 2535 /* Must loop until we find a name. Many devices can have the same unit
2535 if (IORegistryEntryCreateCFProperties (obj, 2536 number (represents different GPU parts), but only one has a name. */
2536 &props, 2537 while (! name && (obj = IOIteratorNext (it)))
2537 kCFAllocatorDefault,
2538 kNilOptions) == kIOReturnSuccess
2539 && props != nil
2540 && (val = CFDictionaryGetValue(props, @"IOFBDependentIndex")))
2541 { 2538 {
2542 unsigned nr = [(NSNumber *)val unsignedIntegerValue]; 2539 CFMutableDictionaryRef props;
2543 if (nr == CGDisplayUnitNumber (did)) 2540 const void *val;
2544 name = ns_get_name_from_ioreg (obj); 2541
2542 if (IORegistryEntryCreateCFProperties (obj,
2543 &props,
2544 kCFAllocatorDefault,
2545 kNilOptions) == kIOReturnSuccess
2546 && props != nil
2547 && (val = CFDictionaryGetValue(props, @"IOFBDependentIndex")))
2548 {
2549 unsigned nr = [(NSNumber *)val unsignedIntegerValue];
2550 if (nr == CGDisplayUnitNumber (did))
2551 name = ns_get_name_from_ioreg (obj);
2552 }
2553
2554 CFRelease (props);
2555 IOObjectRelease (obj);
2545 } 2556 }
2546 2557
2547 CFRelease (props); 2558 IOObjectRelease (it);
2548 IOObjectRelease (obj);
2549 } 2559 }
2550 2560#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
2551 IOObjectRelease (it); 2561 else
2552 2562#endif
2553#else 2563#endif /* #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090 */
2554 2564#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
2555 name = ns_get_name_from_ioreg (CGDisplayIOServicePort (did)); 2565 name = ns_get_name_from_ioreg (CGDisplayIOServicePort (did));
2556
2557#endif 2566#endif
2558 return name; 2567 return name;
2559} 2568}
2560#endif 2569#endif /* NS_IMPL_COCOA */
2561 2570
2562static Lisp_Object 2571static Lisp_Object
2563ns_make_monitor_attribute_list (struct MonitorInfo *monitors, 2572ns_make_monitor_attribute_list (struct MonitorInfo *monitors,
diff --git a/src/nsmenu.m b/src/nsmenu.m
index 37a1a62d6d3..93e06707c07 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -532,9 +532,14 @@ x_activate_menubar (struct frame *f)
532{ 532{
533 ++trackingMenu; 533 ++trackingMenu;
534 534
535#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 535#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
536 // On 10.6 we get repeated calls, only the one for NSSystemDefined is "real". 536 // On 10.6 we get repeated calls, only the one for NSSystemDefined is "real".
537 if ([[NSApp currentEvent] type] != NSSystemDefined) return; 537 if (
538#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
539 NSAppKitVersionNumber < NSAppKitVersionNumber10_7 &&
540#endif
541 [[NSApp currentEvent] type] != NSEventTypeSystemDefined)
542 return;
538#endif 543#endif
539 544
540 /* When dragging from one menu to another, we get willOpen followed by didClose, 545 /* When dragging from one menu to another, we get willOpen followed by didClose,
diff --git a/src/nsterm.h b/src/nsterm.h
index 67c0d42ac18..0ac8043e264 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -25,30 +25,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
25#include "sysselect.h" 25#include "sysselect.h"
26 26
27#ifdef HAVE_NS 27#ifdef HAVE_NS
28
29#ifdef NS_IMPL_COCOA
30#ifndef MAC_OS_X_VERSION_10_6
31#define MAC_OS_X_VERSION_10_6 1060
32#endif
33#ifndef MAC_OS_X_VERSION_10_7
34#define MAC_OS_X_VERSION_10_7 1070
35#endif
36#ifndef MAC_OS_X_VERSION_10_8
37#define MAC_OS_X_VERSION_10_8 1080
38#endif
39#ifndef MAC_OS_X_VERSION_10_9
40#define MAC_OS_X_VERSION_10_9 1090
41#endif
42#ifndef MAC_OS_X_VERSION_10_12
43#define MAC_OS_X_VERSION_10_12 101200
44#endif
45
46#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
47#define HAVE_NATIVE_FS
48#endif
49
50#endif /* NS_IMPL_COCOA */
51
52#ifdef __OBJC__ 28#ifdef __OBJC__
53 29
54/* CGFloat on GNUstep may be 4 or 8 byte, but functions expect float* for some 30/* CGFloat on GNUstep may be 4 or 8 byte, but functions expect float* for some
@@ -471,7 +447,7 @@ typedef id instancetype;
471- (void) toggleFullScreen: (id) sender; 447- (void) toggleFullScreen: (id) sender;
472- (BOOL) fsIsNative; 448- (BOOL) fsIsNative;
473- (BOOL) isFullscreen; 449- (BOOL) isFullscreen;
474#ifdef HAVE_NATIVE_FS 450#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
475- (void) updateCollectionBehavior; 451- (void) updateCollectionBehavior;
476#endif 452#endif
477 453
@@ -1277,9 +1253,17 @@ extern char gnustep_base_version[]; /* version tracking */
1277 ? (min) : (((x)>(max)) ? (max) : (x))) 1253 ? (min) : (((x)>(max)) ? (max) : (x)))
1278#define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX)) 1254#define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX))
1279 1255
1256/* macOS 10.7 introduces some new constants. */
1257#if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_7)
1258#define NSFullScreenWindowMask (1 << 14)
1259#define NSWindowCollectionBehaviorFullScreenPrimary (1 << 7)
1260#define NSApplicationPresentationFullScreen (1 << 10)
1261#define NSApplicationPresentationAutoHideToolbar (1 << 11)
1262#define NSAppKitVersionNumber10_7 1138
1263#endif /* !defined (MAC_OS_X_VERSION_10_7) */
1264
1280/* macOS 10.12 deprecates a bunch of constants. */ 1265/* macOS 10.12 deprecates a bunch of constants. */
1281#if !defined (NS_IMPL_COCOA) || \ 1266#if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_12)
1282 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
1283#define NSEventModifierFlagCommand NSCommandKeyMask 1267#define NSEventModifierFlagCommand NSCommandKeyMask
1284#define NSEventModifierFlagControl NSControlKeyMask 1268#define NSEventModifierFlagControl NSControlKeyMask
1285#define NSEventModifierFlagHelp NSHelpKeyMask 1269#define NSEventModifierFlagHelp NSHelpKeyMask
@@ -1305,6 +1289,7 @@ extern char gnustep_base_version[]; /* version tracking */
1305#define NSEventTypeKeyUp NSKeyUp 1289#define NSEventTypeKeyUp NSKeyUp
1306#define NSEventTypeFlagsChanged NSFlagsChanged 1290#define NSEventTypeFlagsChanged NSFlagsChanged
1307#define NSEventMaskAny NSAnyEventMask 1291#define NSEventMaskAny NSAnyEventMask
1292#define NSEventTypeSystemDefined NSSystemDefined
1308#define NSWindowStyleMaskBorderless NSBorderlessWindowMask 1293#define NSWindowStyleMaskBorderless NSBorderlessWindowMask
1309#define NSWindowStyleMaskClosable NSClosableWindowMask 1294#define NSWindowStyleMaskClosable NSClosableWindowMask
1310#define NSWindowStyleMaskFullScreen NSFullScreenWindowMask 1295#define NSWindowStyleMaskFullScreen NSFullScreenWindowMask
@@ -1319,6 +1304,13 @@ extern char gnustep_base_version[]; /* version tracking */
1319#ifdef __OBJC__ 1304#ifdef __OBJC__
1320typedef NSUInteger NSWindowStyleMask; 1305typedef NSUInteger NSWindowStyleMask;
1321#endif 1306#endif
1322#endif
1323 1307
1308/* Window tabbing mode enums are new too. */
1309enum NSWindowTabbingMode
1310 {
1311 NSWindowTabbingModeAutomatic,
1312 NSWindowTabbingModePreferred,
1313 NSWindowTabbingModeDisallowed
1314 };
1315#endif
1324#endif /* HAVE_NS */ 1316#endif /* HAVE_NS */
diff --git a/src/nsterm.m b/src/nsterm.m
index 36d906a7cec..95092b29c89 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -136,14 +136,18 @@ char const * nstrace_fullscreen_type_name (int fs_type)
136+ (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green 136+ (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green
137 blue:(CGFloat)blue alpha:(CGFloat)alpha 137 blue:(CGFloat)blue alpha:(CGFloat)alpha
138{ 138{
139#ifdef NS_IMPL_COCOA 139#if defined (NS_IMPL_COCOA) \
140#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 140 && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
141 if (ns_use_srgb_colorspace) 141 if (ns_use_srgb_colorspace
142 return [NSColor colorWithSRGBRed: red 142#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
143 green: green 143 && [NSColor respondsToSelector:
144 blue: blue 144 @selector(colorWithSRGBRed:green:blue:alpha:)]
145 alpha: alpha];
146#endif 145#endif
146 )
147 return [NSColor colorWithSRGBRed: red
148 green: green
149 blue: blue
150 alpha: alpha];
147#endif 151#endif
148 return [NSColor colorWithCalibratedRed: red 152 return [NSColor colorWithCalibratedRed: red
149 green: green 153 green: green
@@ -153,11 +157,18 @@ char const * nstrace_fullscreen_type_name (int fs_type)
153 157
154- (NSColor *)colorUsingDefaultColorSpace 158- (NSColor *)colorUsingDefaultColorSpace
155{ 159{
156#ifdef NS_IMPL_COCOA 160 /* FIXMES: We're checking for colorWithSRGBRed here so this will
157#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 161 only work in the same place as in the method above. It should
158 if (ns_use_srgb_colorspace) 162 really be a check whether we're on macOS 10.7 or above. */
159 return [self colorUsingColorSpace: [NSColorSpace sRGBColorSpace]]; 163#if defined (NS_IMPL_COCOA) \
164 && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
165 if (ns_use_srgb_colorspace
166#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
167 && [NSColor respondsToSelector:
168 @selector(colorWithSRGBRed:green:blue:alpha:)]
160#endif 169#endif
170 )
171 return [self colorUsingColorSpace: [NSColorSpace sRGBColorSpace]];
161#endif 172#endif
162 return [self colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; 173 return [self colorUsingColorSpaceName: NSCalibratedRGBColorSpace];
163} 174}
@@ -4140,7 +4151,7 @@ ns_send_appdefined (int value)
4140 } 4151 }
4141} 4152}
4142 4153
4143#ifdef HAVE_NATIVE_FS 4154#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
4144static void 4155static void
4145check_native_fs () 4156check_native_fs ()
4146{ 4157{
@@ -4242,7 +4253,7 @@ ns_read_socket (struct terminal *terminal, struct input_event *hold_quit)
4242 4253
4243 NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_read_socket"); 4254 NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_read_socket");
4244 4255
4245#ifdef HAVE_NATIVE_FS 4256#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
4246 check_native_fs (); 4257 check_native_fs ();
4247#endif 4258#endif
4248 4259
@@ -4324,7 +4335,7 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
4324 4335
4325 NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_select"); 4336 NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_select");
4326 4337
4327#ifdef HAVE_NATIVE_FS 4338#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
4328 check_native_fs (); 4339 check_native_fs ();
4329#endif 4340#endif
4330 4341
@@ -5563,8 +5574,7 @@ runAlertPanel(NSString *title,
5563 NSString *defaultButton, 5574 NSString *defaultButton,
5564 NSString *alternateButton) 5575 NSString *alternateButton)
5565{ 5576{
5566#if !defined (NS_IMPL_COCOA) || \ 5577#ifdef NS_IMPL_GNUSTEP
5567 MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9
5568 return NSRunAlertPanel(title, msgFormat, defaultButton, alternateButton, nil) 5578 return NSRunAlertPanel(title, msgFormat, defaultButton, alternateButton, nil)
5569 == NSAlertDefaultReturn; 5579 == NSAlertDefaultReturn;
5570#else 5580#else
@@ -6325,14 +6335,27 @@ not_in_argv (NSString *arg)
6325 +FRAME_LINE_HEIGHT (emacsframe)); 6335 +FRAME_LINE_HEIGHT (emacsframe));
6326 6336
6327 pt = [self convertPoint: pt toView: nil]; 6337 pt = [self convertPoint: pt toView: nil];
6328#if !defined (NS_IMPL_COCOA) || \ 6338
6329 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 6339#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
6330 pt = [[self window] convertBaseToScreen: pt]; 6340#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
6331 rect.origin = pt; 6341 if ([[self window] respondsToSelector: @selector(convertRectToScreen:)])
6332#else 6342 {
6333 rect.origin = pt;
6334 rect = [[self window] convertRectToScreen: rect];
6335#endif 6343#endif
6344 rect.origin = pt;
6345 rect = [(EmacsWindow *) [self window] convertRectToScreen: rect];
6346#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
6347 }
6348 else
6349#endif
6350#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 */
6351#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 \
6352 || defined (NS_IMPL_GNUSTEP)
6353 {
6354 pt = [[self window] convertBaseToScreen: pt];
6355 rect.origin = pt;
6356 }
6357#endif
6358
6336 return rect; 6359 return rect;
6337} 6360}
6338 6361
@@ -6988,11 +7011,15 @@ not_in_argv (NSString *arg)
6988 scrollbarsNeedingUpdate = 0; 7011 scrollbarsNeedingUpdate = 0;
6989 fs_state = FULLSCREEN_NONE; 7012 fs_state = FULLSCREEN_NONE;
6990 fs_before_fs = next_maximized = -1; 7013 fs_before_fs = next_maximized = -1;
6991#ifdef HAVE_NATIVE_FS 7014
6992 fs_is_native = ns_use_native_fullscreen;
6993#else
6994 fs_is_native = NO; 7015 fs_is_native = NO;
7016#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
7017#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
7018 if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_7)
6995#endif 7019#endif
7020 fs_is_native = ns_use_native_fullscreen;
7021#endif
7022
6996 maximized_width = maximized_height = -1; 7023 maximized_width = maximized_height = -1;
6997 nonfs_window = nil; 7024 nonfs_window = nil;
6998 7025
@@ -7023,7 +7050,10 @@ not_in_argv (NSString *arg)
7023 backing: NSBackingStoreBuffered 7050 backing: NSBackingStoreBuffered
7024 defer: YES]; 7051 defer: YES];
7025 7052
7026#ifdef HAVE_NATIVE_FS 7053#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
7054#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
7055 if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_7)
7056#endif
7027 [win setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; 7057 [win setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
7028#endif 7058#endif
7029 7059
@@ -7032,9 +7062,11 @@ not_in_argv (NSString *arg)
7032 7062
7033 [win setAcceptsMouseMovedEvents: YES]; 7063 [win setAcceptsMouseMovedEvents: YES];
7034 [win setDelegate: self]; 7064 [win setDelegate: self];
7035#if !defined (NS_IMPL_COCOA) || \ 7065#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
7036 MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9 7066#if MAC_OS_X_VERSION_MAX_ALLOWED > 1090
7037 [win useOptimizedDrawing: YES]; 7067 if ([win respondsToSelector: @selector(useOptimizedDrawing:)])
7068#endif
7069 [win useOptimizedDrawing: YES];
7038#endif 7070#endif
7039 7071
7040 [[win contentView] addSubview: self]; 7072 [[win contentView] addSubview: self];
@@ -7094,9 +7126,12 @@ not_in_argv (NSString *arg)
7094 if ([col alphaComponent] != (EmacsCGFloat) 1.0) 7126 if ([col alphaComponent] != (EmacsCGFloat) 1.0)
7095 [win setOpaque: NO]; 7127 [win setOpaque: NO];
7096 7128
7097#if !defined (NS_IMPL_COCOA) || \ 7129#if !defined (NS_IMPL_COCOA) \
7098 MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9 7130 || MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
7099 [self allocateGState]; 7131#if MAC_OS_X_VERSION_MAX_ALLOWED > 1090
7132 if ([self respondsToSelector: @selector(allocateGState)])
7133#endif
7134 [self allocateGState];
7100#endif 7135#endif
7101 [NSApp registerServicesMenuSendTypes: ns_send_types 7136 [NSApp registerServicesMenuSendTypes: ns_send_types
7102 returnTypes: [NSArray array]]; 7137 returnTypes: [NSArray array]];
@@ -7104,9 +7139,12 @@ not_in_argv (NSString *arg)
7104 /* macOS Sierra automatically enables tabbed windows. We can't 7139 /* macOS Sierra automatically enables tabbed windows. We can't
7105 allow this to be enabled until it's available on a Free system. 7140 allow this to be enabled until it's available on a Free system.
7106 Currently it only happens by accident and is buggy anyway. */ 7141 Currently it only happens by accident and is buggy anyway. */
7107#if defined (NS_IMPL_COCOA) && \ 7142#if defined (NS_IMPL_COCOA) \
7108 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 7143 && MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
7109 [win setTabbingMode: NSWindowTabbingModeDisallowed]; 7144#if MAC_OS_X_VERSION_MIN_REQUIRED < 101200
7145 if ([win respondsToSelector: @selector(setTabbingMode:)])
7146#endif
7147 [win setTabbingMode: NSWindowTabbingModeDisallowed];
7110#endif 7148#endif
7111 7149
7112 ns_window_num++; 7150 ns_window_num++;
@@ -7323,7 +7361,7 @@ not_in_argv (NSString *arg)
7323 } 7361 }
7324} 7362}
7325 7363
7326#ifdef HAVE_NATIVE_FS 7364#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
7327- (NSApplicationPresentationOptions)window:(NSWindow *)window 7365- (NSApplicationPresentationOptions)window:(NSWindow *)window
7328 willUseFullScreenPresentationOptions: 7366 willUseFullScreenPresentationOptions:
7329 (NSApplicationPresentationOptions)proposedOptions 7367 (NSApplicationPresentationOptions)proposedOptions
@@ -7361,8 +7399,8 @@ not_in_argv (NSString *arg)
7361 else 7399 else
7362 { 7400 {
7363 BOOL tbar_visible = FRAME_EXTERNAL_TOOL_BAR (emacsframe) ? YES : NO; 7401 BOOL tbar_visible = FRAME_EXTERNAL_TOOL_BAR (emacsframe) ? YES : NO;
7364#ifdef NS_IMPL_COCOA 7402#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 \
7365#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 7403 && MAC_OS_X_VERSION_MIN_REQUIRED <= 1070
7366 unsigned val = (unsigned)[NSApp presentationOptions]; 7404 unsigned val = (unsigned)[NSApp presentationOptions];
7367 7405
7368 // Mac OS X 10.7 bug fix, the menu won't appear without this. 7406 // Mac OS X 10.7 bug fix, the menu won't appear without this.
@@ -7378,7 +7416,6 @@ not_in_argv (NSString *arg)
7378 [NSApp setPresentationOptions: options]; 7416 [NSApp setPresentationOptions: options];
7379 } 7417 }
7380#endif 7418#endif
7381#endif
7382 [toolbar setVisible:tbar_visible]; 7419 [toolbar setVisible:tbar_visible];
7383 } 7420 }
7384} 7421}
@@ -7417,7 +7454,7 @@ not_in_argv (NSString *arg)
7417 } 7454 }
7418 [self setFSValue: fs_before_fs]; 7455 [self setFSValue: fs_before_fs];
7419 fs_before_fs = -1; 7456 fs_before_fs = -1;
7420#ifdef HAVE_NATIVE_FS 7457#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
7421 [self updateCollectionBehavior]; 7458 [self updateCollectionBehavior];
7422#endif 7459#endif
7423 if (FRAME_EXTERNAL_TOOL_BAR (emacsframe)) 7460 if (FRAME_EXTERNAL_TOOL_BAR (emacsframe))
@@ -7449,7 +7486,7 @@ not_in_argv (NSString *arg)
7449 } 7486 }
7450 else 7487 else
7451 { 7488 {
7452#ifdef HAVE_NATIVE_FS 7489#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
7453 res = (([[self window] styleMask] & NSWindowStyleMaskFullScreen) != 0); 7490 res = (([[self window] styleMask] & NSWindowStyleMaskFullScreen) != 0);
7454#else 7491#else
7455 res = NO; 7492 res = NO;
@@ -7462,7 +7499,7 @@ not_in_argv (NSString *arg)
7462 return res; 7499 return res;
7463} 7500}
7464 7501
7465#ifdef HAVE_NATIVE_FS 7502#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
7466- (void)updateCollectionBehavior 7503- (void)updateCollectionBehavior
7467{ 7504{
7468 NSTRACE ("[EmacsView updateCollectionBehavior]"); 7505 NSTRACE ("[EmacsView updateCollectionBehavior]");
@@ -7477,7 +7514,10 @@ not_in_argv (NSString *arg)
7477 b &= ~NSWindowCollectionBehaviorFullScreenPrimary; 7514 b &= ~NSWindowCollectionBehaviorFullScreenPrimary;
7478 7515
7479 [win setCollectionBehavior: b]; 7516 [win setCollectionBehavior: b];
7480 fs_is_native = ns_use_native_fullscreen; 7517#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
7518 if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_7)
7519#endif
7520 fs_is_native = ns_use_native_fullscreen;
7481 } 7521 }
7482} 7522}
7483#endif 7523#endif
@@ -7494,8 +7534,11 @@ not_in_argv (NSString *arg)
7494 7534
7495 if (fs_is_native) 7535 if (fs_is_native)
7496 { 7536 {
7497#ifdef HAVE_NATIVE_FS 7537#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
7498 [[self window] toggleFullScreen:sender]; 7538#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
7539 if ([[self window] respondsToSelector: @selector(toggleFullScreen:)])
7540#endif
7541 [[self window] toggleFullScreen:sender];
7499#endif 7542#endif
7500 return; 7543 return;
7501 } 7544 }
@@ -7512,10 +7555,13 @@ not_in_argv (NSString *arg)
7512 { 7555 {
7513 NSScreen *screen = [w screen]; 7556 NSScreen *screen = [w screen];
7514 7557
7515#if defined (NS_IMPL_COCOA) && \ 7558#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1090
7516 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
7517 /* Hide ghost menu bar on secondary monitor? */ 7559 /* Hide ghost menu bar on secondary monitor? */
7518 if (! onFirstScreen) 7560 if (! onFirstScreen
7561#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
7562 && [NSScreen respondsToSelector: @selector(screensHaveSeparateSpaces)]
7563#endif
7564 )
7519 onFirstScreen = [NSScreen screensHaveSeparateSpaces]; 7565 onFirstScreen = [NSScreen screensHaveSeparateSpaces];
7520#endif 7566#endif
7521 /* Hide dock and menubar if we are on the primary screen. */ 7567 /* Hide dock and menubar if we are on the primary screen. */
@@ -7543,9 +7589,12 @@ not_in_argv (NSString *arg)
7543 [fw setTitle:[w title]]; 7589 [fw setTitle:[w title]];
7544 [fw setDelegate:self]; 7590 [fw setDelegate:self];
7545 [fw setAcceptsMouseMovedEvents: YES]; 7591 [fw setAcceptsMouseMovedEvents: YES];
7546#if !defined (NS_IMPL_COCOA) || \ 7592#if !defined (NS_IMPL_COCOA) \
7547 MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9 7593 || MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
7548 [fw useOptimizedDrawing: YES]; 7594#if MAC_OS_X_VERSION_MAX_ALLOWED > 1090
7595 if ([fw respondsToSelector: @selector(useOptimizedDrawing:)])
7596#endif
7597 [fw useOptimizedDrawing: YES];
7549#endif 7598#endif
7550 [fw setBackgroundColor: col]; 7599 [fw setBackgroundColor: col];
7551 if ([col alphaComponent] != (EmacsCGFloat) 1.0) 7600 if ([col alphaComponent] != (EmacsCGFloat) 1.0)
@@ -8106,10 +8155,14 @@ not_in_argv (NSString *arg)
8106 NSTRACE_ARG_RECT (frameRect)); 8155 NSTRACE_ARG_RECT (frameRect));
8107 8156
8108#ifdef NS_IMPL_COCOA 8157#ifdef NS_IMPL_COCOA
8109#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 8158#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090
8110 // If separate spaces is on, it is like each screen is independent. There is 8159 // If separate spaces is on, it is like each screen is independent. There is
8111 // no spanning of frames across screens. 8160 // no spanning of frames across screens.
8112 if ([NSScreen screensHaveSeparateSpaces]) 8161 if (
8162#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
8163 [NSScreen respondsToSelector: @selector(screensHaveSeparateSpaces)] &&
8164#endif
8165 [NSScreen screensHaveSeparateSpaces])
8113 { 8166 {
8114 NSTRACE_MSG ("Screens have separate spaces"); 8167 NSTRACE_MSG ("Screens have separate spaces");
8115 frameRect = [super constrainFrameRect:frameRect toScreen:screen]; 8168 frameRect = [super constrainFrameRect:frameRect toScreen:screen];
@@ -8117,7 +8170,8 @@ not_in_argv (NSString *arg)
8117 return frameRect; 8170 return frameRect;
8118 } 8171 }
8119 else 8172 else
8120#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 */ 8173#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1090 */
8174
8121 // Check that the proposed frameRect is visible in at least one 8175 // Check that the proposed frameRect is visible in at least one
8122 // screen. If it is not, ask the system to reposition it (only 8176 // screen. If it is not, ask the system to reposition it (only
8123 // for non-child windows). 8177 // for non-child windows).
@@ -8323,12 +8377,21 @@ not_in_argv (NSString *arg)
8323 /* TODO: if we want to allow variable widths, this is the place to do it, 8377 /* TODO: if we want to allow variable widths, this is the place to do it,
8324 however neither GNUstep nor Cocoa support it very well */ 8378 however neither GNUstep nor Cocoa support it very well */
8325 CGFloat r; 8379 CGFloat r;
8326#if !defined (NS_IMPL_COCOA) || \ 8380#if defined (NS_IMPL_COCOA) \
8327 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 8381 && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
8328 r = [NSScroller scrollerWidth]; 8382#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
8329#else 8383 if ([NSScroller respondsToSelector:
8330 r = [NSScroller scrollerWidthForControlSize: NSControlSizeRegular 8384 @selector(scrollerWidthForControlSize:scrollerStyle:)])
8331 scrollerStyle: NSScrollerStyleLegacy]; 8385#endif
8386 r = [NSScroller scrollerWidthForControlSize: NSControlSizeRegular
8387 scrollerStyle: NSScrollerStyleLegacy];
8388#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
8389 else
8390#endif
8391#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 */
8392#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 \
8393 || defined (NS_IMPL_GNUSTEP)
8394 r = [NSScroller scrollerWidth];
8332#endif 8395#endif
8333 return r; 8396 return r;
8334} 8397}
@@ -9015,12 +9078,8 @@ Only works on Mac OS X 10.6 or later. */);
9015 doc: /*Non-nil means to use native fullscreen on Mac OS X 10.7 and later. 9078 doc: /*Non-nil means to use native fullscreen on Mac OS X 10.7 and later.
9016Nil means use fullscreen the old (< 10.7) way. The old way works better with 9079Nil means use fullscreen the old (< 10.7) way. The old way works better with
9017multiple monitors, but lacks tool bar. This variable is ignored on 9080multiple monitors, but lacks tool bar. This variable is ignored on
9018Mac OS X < 10.7. Default is t for 10.7 and later, nil otherwise. */); 9081Mac OS X < 10.7. Default is t. */);
9019#ifdef HAVE_NATIVE_FS
9020 ns_use_native_fullscreen = YES; 9082 ns_use_native_fullscreen = YES;
9021#else
9022 ns_use_native_fullscreen = NO;
9023#endif
9024 ns_last_use_native_fullscreen = ns_use_native_fullscreen; 9083 ns_last_use_native_fullscreen = ns_use_native_fullscreen;
9025 9084
9026 DEFVAR_BOOL ("ns-use-fullscreen-animation", ns_use_fullscreen_animation, 9085 DEFVAR_BOOL ("ns-use-fullscreen-animation", ns_use_fullscreen_animation,