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.

This commit is contained in:
Pietro Gagliardi 2017-05-19 16:40:52 -04:00
parent 90962e18c4
commit dd54469677
7 changed files with 65 additions and 9 deletions

View File

@ -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

View File

@ -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;
}

50
darwin/future.m Normal file
View File

@ -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;
}

View File

@ -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];

View File

@ -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 <Cocoa/Cocoa.h>
#include <dlfcn.h> // 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);

View File

@ -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];

View File

@ -5,7 +5,7 @@
#define GDK_VERSION_MAX_ALLOWED GDK_VERSION_3_10
#include <gtk/gtk.h>
#include <math.h>
#include <dlfcn.h> // see drawtext.c
#include <dlfcn.h> // see future.c
#include <langinfo.h>
#include <string.h>
#include <stdlib.h>