From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#27810: NS runtime feature detection Date: Thu, 10 Aug 2017 22:04:57 +0100 Message-ID: <20170810210457.GA85019@breton.holly.idiocy.org> References: <20170723121701.GA3730@breton.holly.idiocy.org> <508a4930-feab-588b-0ab9-f55a10ea85ec@aurox.ch> <20170724204404.GA20189@breton.holly.idiocy.org> <20170726215746.GA59679@breton.holly.idiocy.org> <20170801220339.GA57816@breton.holly.idiocy.org> <87dde5f1-0010-584e-2dad-4f0fe932f1fa@aurox.ch> <20170806212929.GA62061@breton.holly.idiocy.org> <5d8b81c3-9a45-d59f-8dd1-c0ccc0a19c78@aurox.ch> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="mP3DRpeJDSE+ciuQ" Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1502399185 740 195.159.176.226 (10 Aug 2017 21:06:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 10 Aug 2017 21:06:25 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) Cc: Anders Lindgren , 27810@debbugs.gnu.org To: "Charles A. Roelli" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Aug 10 23:06:18 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dfuej-0007zg-Fm for geb-bug-gnu-emacs@m.gmane.org; Thu, 10 Aug 2017 23:06:14 +0200 Original-Received: from localhost ([::1]:55297 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfuep-0002IA-Nn for geb-bug-gnu-emacs@m.gmane.org; Thu, 10 Aug 2017 17:06:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33696) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfuec-0002Fn-3t for bug-gnu-emacs@gnu.org; Thu, 10 Aug 2017 17:06:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfueY-0007dT-II for bug-gnu-emacs@gnu.org; Thu, 10 Aug 2017 17:06:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:46110) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dfueY-0007d6-86 for bug-gnu-emacs@gnu.org; Thu, 10 Aug 2017 17:06:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dfueX-0003ti-SP for bug-gnu-emacs@gnu.org; Thu, 10 Aug 2017 17:06:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 10 Aug 2017 21:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27810 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 27810-submit@debbugs.gnu.org id=B27810.150239911614927 (code B ref 27810); Thu, 10 Aug 2017 21:06:01 +0000 Original-Received: (at 27810) by debbugs.gnu.org; 10 Aug 2017 21:05:16 +0000 Original-Received: from localhost ([127.0.0.1]:54791 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dfudj-0003sd-PU for submit@debbugs.gnu.org; Thu, 10 Aug 2017 17:05:15 -0400 Original-Received: from mail-wm0-f41.google.com ([74.125.82.41]:38845) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dfude-0003s2-7j for 27810@debbugs.gnu.org; Thu, 10 Aug 2017 17:05:09 -0400 Original-Received: by mail-wm0-f41.google.com with SMTP id f15so32608809wmg.1 for <27810@debbugs.gnu.org>; Thu, 10 Aug 2017 14:05:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=gm/LzBDPXTusF5H/lCyvu9A6kzL4TEAv/ot3RlIrxEk=; b=E6C1r9tBHYBTHRb6UuKih2j/ou5OzFSpuuazia6m62/v5BUjM1mPk7fuKBTkZt6CQH zpnxIub2dM29TO7VxR3nSvnQroIJkp+fiDZRWwYEfWUi0t/aA7+tdjY/vDTIm4XBYz3x KtSNhKwEPFMF6L4y09wkoonWOonbyiLg1b/pmZ6Kmz3cfGAc/0gGnZ24ALDlykH6m/J/ tNwu5KV21ZbnqrsY7lLyIiXkr3y1EfhEnAeTfx+TYQrldWiA/bxVhVXXRGmjfqYLPz5i 1FkN6hafkPxZlFIO6BgfqJTrb9KDsN1dlBL1j2ZvvWiQPjJvnZTBnkNiQ5xrldtWpyNT /kxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=gm/LzBDPXTusF5H/lCyvu9A6kzL4TEAv/ot3RlIrxEk=; b=qY+n/r9OoR3aGIQjKVIf35ngYvnd1tdH+z6eanmMiPF8TVxIL8ncfCgX5IFt10t9qo k7tUN+u4DaNpMT4BEoA2H5LkpAJd8SQd1T6Isc/NeBoq6uuRfEwxXqrm2dwVapjQ+sX4 Ck5LVt03EMQdKp7I1a8WUsHSuB2RkeQglr8DToygPy0+TPunv8L+6jtCtL23we4OUkRP Jbx1qPVc6clTVyfFi/ygfEmKN2fz5rSgQ2EQny7ZWjLSgi05zK7j7DXfTgBXB8uEEEYS dtDAtzBbLz37kesjd37yE1rSZ5Dy+T3A5puxDfwR8YMIz4bB8jzO1Jk4XXakDtkSS9GJ Dr8g== X-Gm-Message-State: AHYfb5hGicMEbboyAPt1JW9+txyGPXqqNWByhSjfobpwD9nI6fLt1K9Q 6Okz9UJ1sfxOKQ== X-Received: by 10.28.65.137 with SMTP id o131mr8406735wma.54.1502399100257; Thu, 10 Aug 2017 14:05:00 -0700 (PDT) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-8ddc-b80d-a658-c5ed.holly.idiocy.org. [2001:8b0:3f8:8129:8ddc:b80d:a658:c5ed]) by smtp.gmail.com with ESMTPSA id 9sm7998112wmo.35.2017.08.10.14.04.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Aug 2017 14:04:58 -0700 (PDT) Content-Disposition: inline In-Reply-To: <5d8b81c3-9a45-d59f-8dd1-c0ccc0a19c78@aurox.ch> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:135627 Archived-At: --mP3DRpeJDSE+ciuQ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Mon, Aug 07, 2017 at 09:23:10PM +0200, Charles A. Roelli wrote: > On 06/08/2017 23:29, Alan Third wrote: > > I believe we can make this slightly neater: > > > > enum NSScrollerStyle { > > NSScrollerStyleLegacy = 0, > > NSScrollerStyleOverlay = 1 > > }; > > Strange, it doesn't work here: We’ll just go with what works, then. > > I’ve done a bit more reading up on this and I think I’ve misunderstood > > how this works, and probably mislead you. > > > > It seems these functions need to be declared as weak in the definition > > of the library they’re supposed to be in. If we declare them in the > > Emacs code‐base then the linker, reasonably, expects the functions to > > be in the Emacs code‐base. > > Maybe I'm also confused. I thought we would be able to do this, > since: > > - At link time, the symbol is marked as a weak reference, to be > resolved at runtime. > > - At runtime, the dynamic linker resolves the reference to the weak > symbol, setting it to NULL if it isn't available. Normally the > definition of the function will be found in a dynamic library that > is part of macOS (as far as I understand). > > The Apple compiler/linker should be capable of doing this, supposedly, > as long as you give the magical -Wl,-U,_symbol command line arguments > to the linker. See also https://stackoverflow.com/a/34983229. That’s quite a good description. I guess that we want to do what you’re suggesting, then. I’m not sure how, though. I’ll try to have a look through configure.ac to see if I can work it out sometime over the weekend. > I'd like to check, but wouldn't I need to either: > > a) Statically link libraries Emacs depends on, or > b) Include the dependent libraries in the app bundle? Yes, I suppose so. I kind of assumed it would statically link at least some of them, but I guess not. I’ve had a look at the build scripts for emacsformacosx.com, but I don’t understand what they’re doing. I’ve attached what I have so far, which I think includes all your changes except for the requirements for linker arguments. Unfortunately master doesn’t build here now because of some other problem so it’s untested. -- Alan Third --mP3DRpeJDSE+ciuQ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Allow-use-of-run-time-OS-version-checks-on-macOS-bug.patch" >From c4945387576a4fa80f6d4daf34199deba003f171 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Thu, 6 Jul 2017 23:10:49 +0100 Subject: [PATCH] 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. (firstRectForCharacterRange): Explicit cast to (EmacsWindow *). * src/nsfns.m (ns_screen_name): Use run-time OS version checks. * src/macfont.m (macfont_draw): Use run-time OS version checks and Explicit cast to (EmacsWindow *). * src/nsmenu.m (menuWillOpen): Use run-time OS version checks. --- src/macfont.h | 4 +- src/macfont.m | 24 +++++--- src/nsfns.m | 83 +++++++++++++------------ src/nsmenu.m | 9 ++- src/nsterm.h | 64 +++++++++++--------- src/nsterm.m | 191 ++++++++++++++++++++++++++++++++++++++-------------------- 6 files changed, 232 insertions(+), 143 deletions(-) diff --git a/src/macfont.h b/src/macfont.h index 32899908be..abb37cd8a6 100644 --- a/src/macfont.h +++ b/src/macfont.h @@ -45,12 +45,12 @@ struct mac_glyph_layout CGGlyph glyph_id; }; -#if MAC_OS_X_VERSION_MAX_ALLOWED < 1080 +#if !defined (MAC_OS_X_VERSION_10_8) enum { kCTFontTraitItalic = kCTFontItalicTrait, kCTFontTraitBold = kCTFontBoldTrait, kCTFontTraitMonoSpace = kCTFontMonoSpaceTrait, -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 && defined (MAC_OS_X_VERSION_10_7) kCTFontTraitColorGlyphs = kCTFontColorGlyphsTrait #else kCTFontTraitColorGlyphs = (1 << 13) diff --git a/src/macfont.m b/src/macfont.m index 4d310e47ae..a79feac8f0 100644 --- a/src/macfont.m +++ b/src/macfont.m @@ -2869,11 +2869,19 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no and synthetic bold looks thinner on such environments. Apple says there are no plans to address this issue (rdar://11644870) currently. So we add a workaround. */ -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 - CGContextSetLineWidth (context, synthetic_bold_factor * font_size - * [[FRAME_NS_VIEW(f) window] backingScaleFactor]); -#else - CGContextSetLineWidth (context, synthetic_bold_factor * font_size); +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + if ([[FRAME_NS_VIEW(f) window] respondsToSelector: + @selector(backingScaleFactor)]) +#endif + CGContextSetLineWidth (context, synthetic_bold_factor * font_size + * [(EmacsWindow *) [FRAME_NS_VIEW(f) window] backingScaleFactor]); +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + else +#endif +#endif +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + CGContextSetLineWidth (context, synthetic_bold_factor * font_size); #endif CG_SET_STROKE_COLOR_WITH_FACE_FOREGROUND (context, face, f); } @@ -2883,7 +2891,7 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no CGContextSetTextMatrix (context, atfm); CGContextSetTextPosition (context, text_position.x, text_position.y); -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 +#if defined (MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 if (macfont_info->color_bitmap_p #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 && CTFontDrawGlyphs != NULL @@ -2897,7 +2905,7 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no } } else -#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 */ +#endif /* defined (MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 */ { CGContextSetFont (context, macfont_info->cgfont); CGContextSetFontSize (context, font_size); @@ -3892,7 +3900,7 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no { CFArrayRef result = NULL; -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080 +#if defined (MAC_OS_X_VERSION_10_8) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1080 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1080 if (CTFontCopyDefaultCascadeListForLanguages != NULL) #endif diff --git a/src/nsfns.m b/src/nsfns.m index 36748cebb8..3f20c8e9e9 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -1592,7 +1592,7 @@ Frames are listed from topmost (first) to bottommost (last). */) } #ifdef NS_IMPL_COCOA -#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_9 +#if MAC_OS_X_VERSION_MAX_ALLOWED > 1090 && defined (MAC_OS_X_VERSION_10_9) #define MODAL_OK_RESPONSE NSModalResponseOK #endif #endif @@ -2512,52 +2512,61 @@ and GNUstep implementations ("distributor-specific release { char *name = NULL; -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 - mach_port_t masterPort; - io_iterator_t it; - io_object_t obj; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090 + if (CGDisplayIOServicePort == NULL) +#endif + { + mach_port_t masterPort; + io_iterator_t it; + io_object_t obj; - // CGDisplayIOServicePort is deprecated. Do it another (harder) way. + /* CGDisplayIOServicePort is deprecated. Do it another (harder) way. - if (IOMasterPort (MACH_PORT_NULL, &masterPort) != kIOReturnSuccess - || IOServiceGetMatchingServices (masterPort, - IOServiceMatching ("IONDRVDevice"), - &it) != kIOReturnSuccess) - return name; + Is this code OK for macOS < 10.9, and GNUstep? I suspect it is, + in which case is it worth keeping the other method in here? */ - /* Must loop until we find a name. Many devices can have the same unit - number (represents different GPU parts), but only one has a name. */ - while (! name && (obj = IOIteratorNext (it))) - { - CFMutableDictionaryRef props; - const void *val; - - if (IORegistryEntryCreateCFProperties (obj, - &props, - kCFAllocatorDefault, - kNilOptions) == kIOReturnSuccess - && props != nil - && (val = CFDictionaryGetValue(props, @"IOFBDependentIndex"))) + if (IOMasterPort (MACH_PORT_NULL, &masterPort) != kIOReturnSuccess + || IOServiceGetMatchingServices (masterPort, + IOServiceMatching ("IONDRVDevice"), + &it) != kIOReturnSuccess) + return name; + + /* Must loop until we find a name. Many devices can have the same unit + number (represents different GPU parts), but only one has a name. */ + while (! name && (obj = IOIteratorNext (it))) { - unsigned nr = [(NSNumber *)val unsignedIntegerValue]; - if (nr == CGDisplayUnitNumber (did)) - name = ns_get_name_from_ioreg (obj); + CFMutableDictionaryRef props; + const void *val; + + if (IORegistryEntryCreateCFProperties (obj, + &props, + kCFAllocatorDefault, + kNilOptions) == kIOReturnSuccess + && props != nil + && (val = CFDictionaryGetValue(props, @"IOFBDependentIndex"))) + { + unsigned nr = [(NSNumber *)val unsignedIntegerValue]; + if (nr == CGDisplayUnitNumber (did)) + name = ns_get_name_from_ioreg (obj); + } + + CFRelease (props); + IOObjectRelease (obj); } - CFRelease (props); - IOObjectRelease (obj); + IOObjectRelease (it); } - - IOObjectRelease (it); - -#else - - name = ns_get_name_from_ioreg (CGDisplayIOServicePort (did)); - +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090 + else +#endif +#endif /* #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090 */ +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090 + name = ns_get_name_from_ioreg (CGDisplayIOServicePort (did)); #endif return name; } -#endif +#endif /* NS_IMPL_COCOA */ static Lisp_Object ns_make_monitor_attribute_list (struct MonitorInfo *monitors, diff --git a/src/nsmenu.m b/src/nsmenu.m index 37a1a62d6d..93e06707c0 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m @@ -532,9 +532,14 @@ - (void)menuWillOpen:(NSMenu *)menu { ++trackingMenu; -#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 // On 10.6 we get repeated calls, only the one for NSSystemDefined is "real". - if ([[NSApp currentEvent] type] != NSSystemDefined) return; + if ( +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 + NSAppKitVersionNumber < NSAppKitVersionNumber10_7 && +#endif + [[NSApp currentEvent] type] != NSEventTypeSystemDefined) + return; #endif /* When dragging from one menu to another, we get willOpen followed by didClose, diff --git a/src/nsterm.h b/src/nsterm.h index 0f1b36db7b..750b6fe1fe 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -25,30 +25,6 @@ along with GNU Emacs. If not, see . */ #include "sysselect.h" #ifdef HAVE_NS - -#ifdef NS_IMPL_COCOA -#ifndef MAC_OS_X_VERSION_10_6 -#define MAC_OS_X_VERSION_10_6 1060 -#endif -#ifndef MAC_OS_X_VERSION_10_7 -#define MAC_OS_X_VERSION_10_7 1070 -#endif -#ifndef MAC_OS_X_VERSION_10_8 -#define MAC_OS_X_VERSION_10_8 1080 -#endif -#ifndef MAC_OS_X_VERSION_10_9 -#define MAC_OS_X_VERSION_10_9 1090 -#endif -#ifndef MAC_OS_X_VERSION_10_12 -#define MAC_OS_X_VERSION_10_12 101200 -#endif - -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 -#define HAVE_NATIVE_FS -#endif - -#endif /* NS_IMPL_COCOA */ - #ifdef __OBJC__ /* CGFloat on GNUstep may be 4 or 8 byte, but functions expect float* for some @@ -62,6 +38,27 @@ typedef CGFloat EmacsCGFloat; typedef float EmacsCGFloat; #endif +/* macOS 10.7 introduces some new constants, enums and methods. + Forward declare them when building on macOS 10.6. */ +#if !defined (MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 +#define NSFullScreenWindowMask (1 << 14) +#define NSWindowCollectionBehaviorFullScreenPrimary (1 << 7) +#define NSApplicationPresentationFullScreen (1 << 10) +#define NSApplicationPresentationAutoHideToolbar (1 << 11) +#define NSAppKitVersionNumber10_7 1138 + +// As in https://chromium.googlesource.com/chromium/blink/+/master/Source/platform/mac/NSScrollerImpDetails.h. +enum { + NSScrollerStyleLegacy = 0, + NSScrollerStyleOverlay = 1 +}; +typedef NSInteger NSScrollerStyle; + +@interface NSScroller(NSObject) ++ (CGFloat)scrollerWidthForControlSize:(NSControlSize)controlSize scrollerStyle:(NSScrollerStyle)scrollerStyle; +@end +#endif /* !defined (MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 */ + /* ========================================================================== Trace support @@ -471,7 +468,7 @@ typedef id instancetype; - (void) toggleFullScreen: (id) sender; - (BOOL) fsIsNative; - (BOOL) isFullscreen; -#ifdef HAVE_NATIVE_FS +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 - (void) updateCollectionBehavior; #endif @@ -494,6 +491,10 @@ typedef id instancetype; { NSPoint grabOffset; } +#if !defined (MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 +- (NSRect)convertRectToScreen:(NSRect)rect; +@property(readonly) CGFloat backingScaleFactor; +#endif @end @@ -1276,8 +1277,7 @@ extern char gnustep_base_version[]; /* version tracking */ #define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX)) /* macOS 10.12 deprecates a bunch of constants. */ -#if !defined (NS_IMPL_COCOA) || \ - MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12 +#if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_12) #define NSEventModifierFlagCommand NSCommandKeyMask #define NSEventModifierFlagControl NSControlKeyMask #define NSEventModifierFlagHelp NSHelpKeyMask @@ -1303,6 +1303,7 @@ extern char gnustep_base_version[]; /* version tracking */ #define NSEventTypeKeyUp NSKeyUp #define NSEventTypeFlagsChanged NSFlagsChanged #define NSEventMaskAny NSAnyEventMask +#define NSEventTypeSystemDefined NSSystemDefined #define NSWindowStyleMaskBorderless NSBorderlessWindowMask #define NSWindowStyleMaskClosable NSClosableWindowMask #define NSWindowStyleMaskFullScreen NSFullScreenWindowMask @@ -1317,6 +1318,13 @@ extern char gnustep_base_version[]; /* version tracking */ #ifdef __OBJC__ typedef NSUInteger NSWindowStyleMask; #endif -#endif +/* Window tabbing mode enums are new too. */ +enum NSWindowTabbingMode + { + NSWindowTabbingModeAutomatic, + NSWindowTabbingModePreferred, + NSWindowTabbingModeDisallowed + }; +#endif #endif /* HAVE_NS */ diff --git a/src/nsterm.m b/src/nsterm.m index 36d906a7ce..e0a977b927 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -136,14 +136,18 @@ @implementation NSColor (EmacsColor) + (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha { -#ifdef NS_IMPL_COCOA -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 - if (ns_use_srgb_colorspace) - return [NSColor colorWithSRGBRed: red - green: green - blue: blue - alpha: alpha]; +#if defined (NS_IMPL_COCOA) \ + && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 + if (ns_use_srgb_colorspace +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + && [NSColor respondsToSelector: + @selector(colorWithSRGBRed:green:blue:alpha:)] #endif + ) + return [NSColor colorWithSRGBRed: red + green: green + blue: blue + alpha: alpha]; #endif return [NSColor colorWithCalibratedRed: red green: green @@ -153,11 +157,18 @@ + (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green - (NSColor *)colorUsingDefaultColorSpace { -#ifdef NS_IMPL_COCOA -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 - if (ns_use_srgb_colorspace) - return [self colorUsingColorSpace: [NSColorSpace sRGBColorSpace]]; + /* FIXMES: We're checking for colorWithSRGBRed here so this will + only work in the same place as in the method above. It should + really be a check whether we're on macOS 10.7 or above. */ +#if defined (NS_IMPL_COCOA) \ + && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 + if (ns_use_srgb_colorspace +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + && [NSColor respondsToSelector: + @selector(colorWithSRGBRed:green:blue:alpha:)] #endif + ) + return [self colorUsingColorSpace: [NSColorSpace sRGBColorSpace]]; #endif return [self colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; } @@ -4140,7 +4151,7 @@ in certain situations (rapid incoming events). } } -#ifdef HAVE_NATIVE_FS +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 static void check_native_fs () { @@ -4242,7 +4253,7 @@ in certain situations (rapid incoming events). NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_read_socket"); -#ifdef HAVE_NATIVE_FS +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 check_native_fs (); #endif @@ -4324,7 +4335,7 @@ in certain situations (rapid incoming events). NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_select"); -#ifdef HAVE_NATIVE_FS +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 check_native_fs (); #endif @@ -5563,8 +5574,7 @@ - (void) terminate: (id)sender NSString *defaultButton, NSString *alternateButton) { -#if !defined (NS_IMPL_COCOA) || \ - MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9 +#ifdef NS_IMPL_GNUSTEP return NSRunAlertPanel(title, msgFormat, defaultButton, alternateButton, nil) == NSAlertDefaultReturn; #else @@ -6325,14 +6335,27 @@ - (NSRect)firstRectForCharacterRange: (NSRange)theRange +FRAME_LINE_HEIGHT (emacsframe)); pt = [self convertPoint: pt toView: nil]; -#if !defined (NS_IMPL_COCOA) || \ - MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 - pt = [[self window] convertBaseToScreen: pt]; - rect.origin = pt; -#else - rect.origin = pt; - rect = [[self window] convertRectToScreen: rect]; + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + if ([[self window] respondsToSelector: @selector(convertRectToScreen:)]) + { #endif + rect.origin = pt; + rect = [(EmacsWindow *) [self window] convertRectToScreen: rect]; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + } + else +#endif +#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 */ +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 \ + || defined (NS_IMPL_GNUSTEP) + { + pt = [[self window] convertBaseToScreen: pt]; + rect.origin = pt; + } +#endif + return rect; } @@ -6988,11 +7011,15 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f scrollbarsNeedingUpdate = 0; fs_state = FULLSCREEN_NONE; fs_before_fs = next_maximized = -1; -#ifdef HAVE_NATIVE_FS - fs_is_native = ns_use_native_fullscreen; -#else + fs_is_native = NO; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_7) #endif + fs_is_native = ns_use_native_fullscreen; +#endif + maximized_width = maximized_height = -1; nonfs_window = nil; @@ -7023,7 +7050,10 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f backing: NSBackingStoreBuffered defer: YES]; -#ifdef HAVE_NATIVE_FS +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_7) +#endif [win setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; #endif @@ -7032,9 +7062,11 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f [win setAcceptsMouseMovedEvents: YES]; [win setDelegate: self]; -#if !defined (NS_IMPL_COCOA) || \ - MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9 - [win useOptimizedDrawing: YES]; +#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MIN_REQUIRED <= 1090 +#if MAC_OS_X_VERSION_MAX_ALLOWED > 1090 + if ([win respondsToSelector: @selector(useOptimizedDrawing:)]) +#endif + [win useOptimizedDrawing: YES]; #endif [[win contentView] addSubview: self]; @@ -7094,9 +7126,12 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f if ([col alphaComponent] != (EmacsCGFloat) 1.0) [win setOpaque: NO]; -#if !defined (NS_IMPL_COCOA) || \ - MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9 - [self allocateGState]; +#if !defined (NS_IMPL_COCOA) \ + || MAC_OS_X_VERSION_MIN_REQUIRED <= 1090 +#if MAC_OS_X_VERSION_MAX_ALLOWED > 1090 + if ([self respondsToSelector: @selector(allocateGState)]) +#endif + [self allocateGState]; #endif [NSApp registerServicesMenuSendTypes: ns_send_types returnTypes: [NSArray array]]; @@ -7104,9 +7139,12 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f /* macOS Sierra automatically enables tabbed windows. We can't allow this to be enabled until it's available on a Free system. Currently it only happens by accident and is buggy anyway. */ -#if defined (NS_IMPL_COCOA) && \ - MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 - [win setTabbingMode: NSWindowTabbingModeDisallowed]; +#if defined (NS_IMPL_COCOA) \ + && MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 101200 + if ([win respondsToSelector: @selector(setTabbingMode:)]) +#endif + [win setTabbingMode: NSWindowTabbingModeDisallowed]; #endif ns_window_num++; @@ -7323,7 +7361,7 @@ - (void)windowDidMiniaturize: sender } } -#ifdef HAVE_NATIVE_FS +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 - (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions: (NSApplicationPresentationOptions)proposedOptions @@ -7361,8 +7399,8 @@ - (void)windowDidEnterFullScreen /* provided for direct calls */ else { BOOL tbar_visible = FRAME_EXTERNAL_TOOL_BAR (emacsframe) ? YES : NO; -#ifdef NS_IMPL_COCOA -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 \ + && MAC_OS_X_VERSION_MIN_REQUIRED <= 1070 unsigned val = (unsigned)[NSApp presentationOptions]; // Mac OS X 10.7 bug fix, the menu won't appear without this. @@ -7378,7 +7416,6 @@ - (void)windowDidEnterFullScreen /* provided for direct calls */ [NSApp setPresentationOptions: options]; } #endif -#endif [toolbar setVisible:tbar_visible]; } } @@ -7417,7 +7454,7 @@ - (void)windowDidExitFullScreen /* provided for direct calls */ } [self setFSValue: fs_before_fs]; fs_before_fs = -1; -#ifdef HAVE_NATIVE_FS +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 [self updateCollectionBehavior]; #endif if (FRAME_EXTERNAL_TOOL_BAR (emacsframe)) @@ -7449,7 +7486,7 @@ - (BOOL)isFullscreen } else { -#ifdef HAVE_NATIVE_FS +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 res = (([[self window] styleMask] & NSWindowStyleMaskFullScreen) != 0); #else res = NO; @@ -7462,7 +7499,7 @@ - (BOOL)isFullscreen return res; } -#ifdef HAVE_NATIVE_FS +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 - (void)updateCollectionBehavior { NSTRACE ("[EmacsView updateCollectionBehavior]"); @@ -7477,7 +7514,10 @@ - (void)updateCollectionBehavior b &= ~NSWindowCollectionBehaviorFullScreenPrimary; [win setCollectionBehavior: b]; - fs_is_native = ns_use_native_fullscreen; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_7) +#endif + fs_is_native = ns_use_native_fullscreen; } } #endif @@ -7494,8 +7534,11 @@ - (void)toggleFullScreen: (id)sender if (fs_is_native) { -#ifdef HAVE_NATIVE_FS - [[self window] toggleFullScreen:sender]; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + if ([[self window] respondsToSelector: @selector(toggleFullScreen:)]) +#endif + [[self window] toggleFullScreen:sender]; #endif return; } @@ -7512,10 +7555,13 @@ - (void)toggleFullScreen: (id)sender { NSScreen *screen = [w screen]; -#if defined (NS_IMPL_COCOA) && \ - MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 +#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1090 /* Hide ghost menu bar on secondary monitor? */ - if (! onFirstScreen) + if (! onFirstScreen +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090 + && [NSScreen respondsToSelector: @selector(screensHaveSeparateSpaces)] +#endif + ) onFirstScreen = [NSScreen screensHaveSeparateSpaces]; #endif /* Hide dock and menubar if we are on the primary screen. */ @@ -7543,9 +7589,12 @@ - (void)toggleFullScreen: (id)sender [fw setTitle:[w title]]; [fw setDelegate:self]; [fw setAcceptsMouseMovedEvents: YES]; -#if !defined (NS_IMPL_COCOA) || \ - MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9 - [fw useOptimizedDrawing: YES]; +#if !defined (NS_IMPL_COCOA) \ + || MAC_OS_X_VERSION_MIN_REQUIRED <= 1090 +#if MAC_OS_X_VERSION_MAX_ALLOWED > 1090 + if ([fw respondsToSelector: @selector(useOptimizedDrawing:)]) +#endif + [fw useOptimizedDrawing: YES]; #endif [fw setBackgroundColor: col]; if ([col alphaComponent] != (EmacsCGFloat) 1.0) @@ -8106,10 +8155,14 @@ - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen NSTRACE_ARG_RECT (frameRect)); #ifdef NS_IMPL_COCOA -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090 // If separate spaces is on, it is like each screen is independent. There is // no spanning of frames across screens. - if ([NSScreen screensHaveSeparateSpaces]) + if ( +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090 + [NSScreen respondsToSelector: @selector(screensHaveSeparateSpaces)] && +#endif + [NSScreen screensHaveSeparateSpaces]) { NSTRACE_MSG ("Screens have separate spaces"); frameRect = [super constrainFrameRect:frameRect toScreen:screen]; @@ -8117,7 +8170,8 @@ - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen return frameRect; } else -#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 */ +#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1090 */ + // Check that the proposed frameRect is visible in at least one // screen. If it is not, ask the system to reposition it (only // for non-child windows). @@ -8323,12 +8377,21 @@ + (CGFloat) scrollerWidth /* TODO: if we want to allow variable widths, this is the place to do it, however neither GNUstep nor Cocoa support it very well */ CGFloat r; -#if !defined (NS_IMPL_COCOA) || \ - MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 - r = [NSScroller scrollerWidth]; -#else - r = [NSScroller scrollerWidthForControlSize: NSControlSizeRegular - scrollerStyle: NSScrollerStyleLegacy]; +#if defined (NS_IMPL_COCOA) \ + && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + if ([NSScroller respondsToSelector: + @selector(scrollerWidthForControlSize:scrollerStyle:)]) +#endif + r = [NSScroller scrollerWidthForControlSize: NSControlSizeRegular + scrollerStyle: NSScrollerStyleLegacy]; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + else +#endif +#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 */ +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 \ + || defined (NS_IMPL_GNUSTEP) + r = [NSScroller scrollerWidth]; #endif return r; } @@ -9015,12 +9078,8 @@ Convert an X font name (XLFD) to an NS font name. doc: /*Non-nil means to use native fullscreen on Mac OS X 10.7 and later. Nil means use fullscreen the old (< 10.7) way. The old way works better with multiple monitors, but lacks tool bar. This variable is ignored on -Mac OS X < 10.7. Default is t for 10.7 and later, nil otherwise. */); -#ifdef HAVE_NATIVE_FS +Mac OS X < 10.7. Default is t. */); ns_use_native_fullscreen = YES; -#else - ns_use_native_fullscreen = NO; -#endif ns_last_use_native_fullscreen = ns_use_native_fullscreen; DEFVAR_BOOL ("ns-use-fullscreen-animation", ns_use_fullscreen_animation, -- 2.12.0 --mP3DRpeJDSE+ciuQ--