From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "Charles A. Roelli" Newsgroups: gmane.emacs.bugs Subject: bug#27810: NS runtime feature detection Date: Sun, 6 Aug 2017 22:29:49 +0200 Message-ID: <87dde5f1-0010-584e-2dad-4f0fe932f1fa@aurox.ch> References: <20170718221629.GA55506@breton.holly.idiocy.org> <20170722112230.GA58424@breton.holly.idiocy.org> <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> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------FA7AFC1D6069133EFF3C8B56" X-Trace: blaine.gmane.org 1502051476 31656 195.159.176.226 (6 Aug 2017 20:31:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 6 Aug 2017 20:31:16 +0000 (UTC) User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 Cc: 27810@debbugs.gnu.org To: Alan Third , Anders Lindgren Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Aug 06 22:31:10 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 1deSCa-0007nB-PU for geb-bug-gnu-emacs@m.gmane.org; Sun, 06 Aug 2017 22:31:09 +0200 Original-Received: from localhost ([::1]:34257 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1deSCh-0004SK-4C for geb-bug-gnu-emacs@m.gmane.org; Sun, 06 Aug 2017 16:31:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1deSCZ-0004QI-Gv for bug-gnu-emacs@gnu.org; Sun, 06 Aug 2017 16:31:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1deSCU-0005yF-H7 for bug-gnu-emacs@gnu.org; Sun, 06 Aug 2017 16:31:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42326) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1deSCU-0005xX-4n for bug-gnu-emacs@gnu.org; Sun, 06 Aug 2017 16:31:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1deSCT-0007tG-T2 for bug-gnu-emacs@gnu.org; Sun, 06 Aug 2017 16:31:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Charles A. Roelli" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 06 Aug 2017 20:31: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.150205140730252 (code B ref 27810); Sun, 06 Aug 2017 20:31:01 +0000 Original-Received: (at 27810) by debbugs.gnu.org; 6 Aug 2017 20:30:07 +0000 Original-Received: from localhost ([127.0.0.1]:45003 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1deSBa-0007rI-AW for submit@debbugs.gnu.org; Sun, 06 Aug 2017 16:30:06 -0400 Original-Received: from sinyavsky.aurox.ch ([37.35.109.145]:54737) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1deSBW-0007px-VK for 27810@debbugs.gnu.org; Sun, 06 Aug 2017 16:30:04 -0400 Original-Received: from sinyavsky.aurox.ch (sinyavsky.aurox.ch [127.0.0.1]) by sinyavsky.aurox.ch (Postfix) with ESMTP id 22149224E3 for <27810@debbugs.gnu.org>; Sun, 6 Aug 2017 20:24:20 +0000 (UTC) Authentication-Results: sinyavsky.aurox.ch (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=aurox.ch DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aurox.ch; h= content-type:content-type:in-reply-to:mime-version:user-agent :date:date:message-id:from:from:references:to:subject:subject; s=dkim; t=1502051056; x=1502915057; bh=vNFQycsW6mY2ikdOzvipjYCl bKsicyQEdz7DJng0qZk=; b=fxB8af15ESWeq2RmfKpwl7UE/jc8u7qiIs/p/p/o vzfqP3DK5nB/HP3gd/zlG3rNL49Ktd46TsXn7urvvtEH5dr1gu5bTr1ZbTRg8TAH DQTmStdNP0S2MtYJ3AaG6pbVe5OAhLy5X2rlRem9olcVuJo4AZKpp0qs14P8qZNO 29M= X-Virus-Scanned: Debian amavisd-new at test.virtualizor.com Original-Received: from sinyavsky.aurox.ch ([127.0.0.1]) by sinyavsky.aurox.ch (sinyavsky.aurox.ch [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id LaejCOegDkoF for <27810@debbugs.gnu.org>; Sun, 6 Aug 2017 20:24:16 +0000 (UTC) Original-Received: from [192.168.1.120] (125.85.192.178.dynamic.wline.res.cust.swisscom.ch [178.192.85.125]) by sinyavsky.aurox.ch (Postfix) with ESMTPSA id 2EB76224D1; Sun, 6 Aug 2017 20:24:15 +0000 (UTC) In-Reply-To: <20170801220339.GA57816@breton.holly.idiocy.org> 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:135513 Archived-At: This is a multi-part message in MIME format. --------------FA7AFC1D6069133EFF3C8B56 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit I ran a simple configure/compile with your patch installed, which worked fine. I then tried: ./configure --with-ns CFLAGS=-DMAC_OS_X_VERSION_MIN_REQUIRED=1060 -DMAC_OS_X_VERSION_MAX_ALLOWED=101200 -g -O3 and ran into a few errors, which should be fixed with the attached patch applied on top of yours. I've written notes on some of the changed parts below. --- 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) We have to define these constants when compiling on macOS < 10.8, since they're used by macfont.m and only available on 10.8+. -#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) kCTFontColorGlyphsTrait is only defined on macOS 10.7+. --- a/src/macfont.m +++ b/src/macfont.m @@ -2875,7 +2875,7 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no @selector(backingScaleFactor)]) #endif CGContextSetLineWidth (context, synthetic_bold_factor * font_size - * [[FRAME_NS_VIEW(f) window] backingScaleFactor]); + * [(EmacsWindow *) [FRAME_NS_VIEW(f) window] backingScaleFactor]); Compiler needs a cast to EmacsWindow * here. I add the backing scale factor to the interface declaration of EmacsWindow here in nsterm.h: @@ -470,6 +499,10 @@ @interface EmacsWindow : NSWindow { 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 Next, in nsfns.m: --- 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 > 1090 +#if MAC_OS_X_VERSION_MAX_ALLOWED > 1090 && defined (MAC_OS_X_VERSION_10_9) #define MODAL_OK_RESPONSE NSModalResponseOK #endif #endif NSModelResponseOK is only defined on macOS 10.9+. The next ifndef clause takes care of the right define on macOS below 10.9. Next, in src/nsterm.h: +#define NSAppKitVersionNumber10_7 1138 New define, since it's referenced verbatim in nsterm.m:7017: #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_7) #endif New scroll styles in 10.7+: +enum { + NSScrollerStyleLegacy = 0, + NSScrollerStyleOverlay = 1 +}; +typedef NSInteger NSScrollerStyle; Add-on to the class declaration of NSScroller (not sure if this is the right way to do it). Otherwise the compiler errors out on compiling the 10.7+ call to scrollerWidthForControlSize: +@interface NSScroller(NSObject) ++ (CGFloat)scrollerWidthForControlSize:(NSControlSize)controlSize scrollerStyle:(NSScrollerStyle)scrollerStyle; +@end Forward declarations for functions used by macfont.m (declared as weak imports since they won't all be available unless we're on 10.8+): +void CTFontDrawGlyphs(CTFontRef font, const CGGlyph *glyphs, const CGPoint *positions, size_t count, CGContextRef context) __attribute__((weak_import)); +#endif + +#if !defined (MAC_OS_X_VERSION_10_8) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1080 +extern CFArrayRef CTFontCopyDefaultCascadeListForLanguages(CTFontRef font, CFArrayRef languagePrefList) __attribute__((weak_import)); The compiler issued no complaints here, but the linker would not link temacs unless the symbols were listed as permitted to be undefined, using this in src/Makefile: ## System-specific LDFLAGS. LD_SWITCH_SYSTEM= -Wl,-U,_CTFontCopyDefaultCascadeListForLanguages -Wl,-U,_CTFontDrawGlyphs I'm not sure where to integrate this in the source tree (and if we can conditionalize it based on what version of macOS we're building for). If they look okay, could you please integrate these changes into your patch? Thanks a lot for your help on this. On 02/08/2017 00:03, Alan Third wrote: > On Tue, Aug 01, 2017 at 05:38:03PM +0200, Anders Lindgren wrote: >> It's always a good idea to enable warnings when undefined preprocessor >> symbols are used. In gcc this is -Wundef and I gess it's the same in clang. > Unfortunately this produces an absolute ton of spurious warnings which > scroll off my terminal buffer. I think I’ve caught all the important > ones now, though. > > I’ve attached my latest go with this. I’ve removed the > MAC_OS_X_VERSION_10_XX macros with their numbers, as we can use the > existence of the macros to tell what platform we’re compiling on. Eg. > > #if !defined (MAC_OS_X_VERSION_10_7) \ > && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 > > I’ve also used the NSAppKitVersionNumber macros in a few places to do > runtime version detection. I’m not sure this is reliable. There are > two methods of finding the OS version definitively, which we can use > if we need to. > > I’ve got rid of the HAS_NATIVE_FS macro and tried to replace it with > other checks where required. It compiles on 10.12, but I’m not at all > convinced it will compile on 10.6. > > New 10.7 variables that need to be available on 10.6 when we’re > compiling for 10.7+ have been added near the bottom of nsterm.h. > > Overall it looks quite different in places, but the functionality > hasn’t really changed. --------------FA7AFC1D6069133EFF3C8B56 Content-Type: text/x-patch; name="0001-draft-macos-runtime-check.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-draft-macos-runtime-check.patch" diff --git a/src/macfont.h b/src/macfont.h index 3289990..abb37cd 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 19145f9..91ad520 100644 --- a/src/macfont.m +++ b/src/macfont.m @@ -2875,7 +2875,7 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no @selector(backingScaleFactor)]) #endif CGContextSetLineWidth (context, synthetic_bold_factor * font_size - * [[FRAME_NS_VIEW(f) window] backingScaleFactor]); + * [(EmacsWindow *) [FRAME_NS_VIEW(f) window] backingScaleFactor]); #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 else #endif diff --git a/src/nsfns.m b/src/nsfns.m index e19e4e2..3f20c8e 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 > 1090 +#if MAC_OS_X_VERSION_MAX_ALLOWED > 1090 && defined (MAC_OS_X_VERSION_10_9) #define MODAL_OK_RESPONSE NSModalResponseOK #endif #endif diff --git a/src/nsterm.h b/src/nsterm.h index a60f94e..7969a90 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -38,6 +38,35 @@ 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 + +void CTFontDrawGlyphs(CTFontRef font, const CGGlyph *glyphs, const CGPoint *positions, size_t count, CGContextRef context) __attribute__((weak_import)); +#endif + +#if !defined (MAC_OS_X_VERSION_10_8) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1080 +extern CFArrayRef CTFontCopyDefaultCascadeListForLanguages(CTFontRef font, CFArrayRef languagePrefList) __attribute__((weak_import)); +#define kCTFontUIFontUser 0 + +#endif + /* ========================================================================== Trace support @@ -470,6 +499,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 @@ -1251,14 +1284,6 @@ extern char gnustep_base_version[]; /* version tracking */ ? (min) : (((x)>(max)) ? (max) : (x))) #define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX)) -/* macOS 10.7 introduces some new constants. */ -#if !defined (MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 -#define NSWindowStyleMaskFullScreen (1 << 14) -#define NSWindowCollectionBehaviorFullScreenPrimary (1 << 7) -#define NSApplicationPresentationFullScreen (1 << 10) -#define NSApplicationPresentationAutoHideToolbar (1 << 11) -#endif - /* macOS 10.12 deprecates a bunch of constants. */ #if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_12) #define NSEventModifierFlagCommand NSCommandKeyMask diff --git a/src/nsterm.m b/src/nsterm.m index 1eaf94a..e0a977b 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -6342,7 +6342,7 @@ - (NSRect)firstRectForCharacterRange: (NSRange)theRange { #endif rect.origin = pt; - rect = [[self window] convertRectToScreen: rect]; + rect = [(EmacsWindow *) [self window] convertRectToScreen: rect]; #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 } else --------------FA7AFC1D6069133EFF3C8B56--