From dd544696774a1bb620c44758cf050992429e09d0 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 19 May 2017 16:40:52 -0400 Subject: [PATCH] Set up a future system for OS X like we have on GTK+ and moved everything we already have to it. You'll notice we also set up a loader for what we're going to use this for: using OpenType attributes directly on OS X. --- darwin/CMakeLists.txt | 1 + darwin/autolayout.m | 4 +--- darwin/future.m | 50 ++++++++++++++++++++++++++++++++++++++++++ darwin/main.m | 1 + darwin/uipriv_darwin.h | 8 +++++++ darwin/winmoveresize.m | 8 +++---- unix/uipriv_unix.h | 2 +- 7 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 darwin/future.m diff --git a/darwin/CMakeLists.txt b/darwin/CMakeLists.txt index e260f266..0591643b 100644 --- a/darwin/CMakeLists.txt +++ b/darwin/CMakeLists.txt @@ -22,6 +22,7 @@ list(APPEND _LIBUI_SOURCES darwin/fontbutton.m darwin/fontmatch.m darwin/form.m + darwin/future.m darwin/graphemes.m darwin/grid.m darwin/group.m diff --git a/darwin/autolayout.m b/darwin/autolayout.m index 9964155f..3bf4acb7 100644 --- a/darwin/autolayout.m +++ b/darwin/autolayout.m @@ -12,9 +12,7 @@ NSLayoutConstraint *mkConstraint(id view1, NSLayoutAttribute attr1, NSLayoutRela attribute:attr2 multiplier:multiplier constant:c]; - // apparently only added in 10.9 - if ([constraint respondsToSelector:@selector(setIdentifier:)]) - [((id) constraint) setIdentifier:desc]; + FUTURE_NSLayoutConstraint_setIdentifier(constraint, desc); return constraint; } diff --git a/darwin/future.m b/darwin/future.m new file mode 100644 index 00000000..45208756 --- /dev/null +++ b/darwin/future.m @@ -0,0 +1,50 @@ +// 19 may 2017 +#import "uipriv_darwin.h" + +// functions and constants FROM THE FUTURE! + +// TODO add weight constants here? + +// added in OS X 10.10; we need 10.8 +CFStringRef FUTURE_kCTFontOpenTypeFeatureTag = NULL; +CFStringRef FUTURE_kCTFontOpenTypeFeatureValue = NULL; + +// note that we treat any error as "the symbols aren't there" (and don't care if dlclose() failed) +void loadFutures(void) +{ + void *handle; + + // dlsym() walks the dependency chain, so opening the current process should be sufficient + handle = dlopen(NULL, RTLD_LAZY); + if (handle == NULL) + return; +#define GET(var, fn) *((void **) (&var)) = dlsym(handle, #fn) + GET(FUTURE_kCTFontOpenTypeFeatureTag, kCTFontOpenTypeFeatureTag); + GET(FUTURE_kCTFontOpenTypeFeatureValue, kCTFontOpenTypeFeatureValue); + dlclose(handle); +} + +// wrappers for methods that exist in the future that we can check for with respondsToSelector: +// keep them in one place for convenience + +// apparently only added in 10.9; we need 10.8 +void FUTURE_NSLayoutConstraint_setIdentifier(NSLayoutConstraint *constraint, NSString *identifier) +{ + id cid = (id) constraint; + + if ([constraint respondsToSelector:@selector(setIdentifier:)]) + [cid setIdentifier:identifier]; +} + +// added in 10.11; we need 10.8 +// return whether this was done because we recreate its effects if not (see winmoveresize.m) +BOOL FUTURE_NSWindow_performWindowDragWithEvent(NSWindow *w, NSEvent *initialEvent) +{ + id cw = (id) w; + + if ([w respondsToSelector:@selector(performWindowDragWithEvent:)]) { + [cw performWindowDragWithEvent:initialEvent]; + return YES; + } + return NO; +} diff --git a/darwin/main.m b/darwin/main.m index 440343bc..60acecaf 100644 --- a/darwin/main.m +++ b/darwin/main.m @@ -119,6 +119,7 @@ const char *uiInit(uiInitOptions *o) [realNSApp() setDelegate:delegate]; initAlloc(); + loadFutures(); // always do this so we always have an application menu appDelegate().menuManager = [[menuManager new] autorelease]; diff --git a/darwin/uipriv_darwin.h b/darwin/uipriv_darwin.h index fe65f201..01594f48 100644 --- a/darwin/uipriv_darwin.h +++ b/darwin/uipriv_darwin.h @@ -2,6 +2,7 @@ #define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_8 #define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_8 #import +#include // see future.m #import "../ui.h" #import "../ui_darwin.h" #import "../common/uipriv.h" @@ -163,3 +164,10 @@ extern void openTypeToAAT(uiOpenTypeFeatures *otf, void (*doAAT)(uint16_t type, (x8tox32(b) << 16) | \ (x8tox32(c) << 8) | \ x8tox32(d)) + +// future.m +extern CFStringRef FUTURE_kCTFontOpenTypeFeatureTag; +extern CFStringRef FUTURE_kCTFontOpenTypeFeatureValue; +extern void loadFutures(void); +extern void FUTURE_NSLayoutConstraint_setIdentifier(NSLayoutConstraint *constraint, NSString *identifier); +extern BOOL FUTURE_NSWindow_performWindowDragWithEvent(NSWindow *w, NSEvent *initialEvent); diff --git a/darwin/winmoveresize.m b/darwin/winmoveresize.m index 9145b7bb..2753b93b 100644 --- a/darwin/winmoveresize.m +++ b/darwin/winmoveresize.m @@ -48,12 +48,10 @@ void doManualMove(NSWindow *w, NSEvent *initialEvent) BOOL (^handleEvent)(NSEvent *e); __block BOOL done; - // this is only available on 10.11 and newer (LONGTERM FUTURE) - // but use it if available; this lets us use the real OS dragging code, which means we can take advantage of OS features like Spaces - if ([w respondsToSelector:@selector(performWindowDragWithEvent:)]) { - [((id) w) performWindowDragWithEvent:initialEvent]; + // 10.11 gives us a method to handle this for us + // use it if available; this lets us use the real OS dragging code, which means we can take advantage of OS features like Spaces + if (FUTURE_NSWindow_performWindowDragWithEvent(w, initialEvent)) return; - } mdp.w = w; mdp.initialFrame = [mdp.w frame]; diff --git a/unix/uipriv_unix.h b/unix/uipriv_unix.h index cb5bf281..c80e8cc6 100644 --- a/unix/uipriv_unix.h +++ b/unix/uipriv_unix.h @@ -5,7 +5,7 @@ #define GDK_VERSION_MAX_ALLOWED GDK_VERSION_3_10 #include #include -#include // see drawtext.c +#include // see future.c #include #include #include