early-access version 1617
This commit is contained in:
35
externals/SDL/src/video/cocoa/SDL_cocoaevents.m
vendored
35
externals/SDL/src/video/cocoa/SDL_cocoaevents.m
vendored
@@ -26,13 +26,15 @@
|
||||
|
||||
#include "SDL_cocoavideo.h"
|
||||
#include "../../events/SDL_events_c.h"
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_hints.h"
|
||||
|
||||
/* This define was added in the 10.9 SDK. */
|
||||
#ifndef kIOPMAssertPreventUserIdleDisplaySleep
|
||||
#define kIOPMAssertPreventUserIdleDisplaySleep kIOPMAssertionTypePreventUserIdleDisplaySleep
|
||||
#endif
|
||||
#ifndef NSAppKitVersionNumber10_8
|
||||
#define NSAppKitVersionNumber10_8 1187
|
||||
#endif
|
||||
|
||||
@interface SDLApplication : NSApplication
|
||||
|
||||
@@ -117,6 +119,7 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
|
||||
}
|
||||
|
||||
- (id)init;
|
||||
- (void)localeDidChange:(NSNotification *)notification;
|
||||
@end
|
||||
|
||||
@implementation SDLAppDelegate : NSObject
|
||||
@@ -137,6 +140,11 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
|
||||
selector:@selector(focusSomeWindow:)
|
||||
name:NSApplicationDidBecomeActiveNotification
|
||||
object:nil];
|
||||
|
||||
[center addObserver:self
|
||||
selector:@selector(localeDidChange:)
|
||||
name:NSCurrentLocaleDidChangeNotification
|
||||
object:nil];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -148,6 +156,7 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
|
||||
|
||||
[center removeObserver:self name:NSWindowWillCloseNotification object:nil];
|
||||
[center removeObserver:self name:NSApplicationDidBecomeActiveNotification object:nil];
|
||||
[center removeObserver:self name:NSCurrentLocaleDidChangeNotification object:nil];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
@@ -226,6 +235,11 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
|
||||
}
|
||||
}
|
||||
|
||||
- (void)localeDidChange:(NSNotification *)notification;
|
||||
{
|
||||
SDL_SendLocaleChangedEvent();
|
||||
}
|
||||
|
||||
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
||||
{
|
||||
return (BOOL)SDL_SendDropFile(NULL, [filename UTF8String]) && SDL_SendDropComplete(NULL);
|
||||
@@ -248,10 +262,24 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
[[NSAppleEventManager sharedAppleEventManager]
|
||||
setEventHandler:self
|
||||
andSelector:@selector(handleURLEvent:withReplyEvent:)
|
||||
forEventClass:kInternetEventClass
|
||||
andEventID:kAEGetURL];
|
||||
|
||||
/* If we call this before NSApp activation, macOS might print a complaint
|
||||
* about ApplePersistenceIgnoreState. */
|
||||
[SDLApplication registerUserDefaults];
|
||||
}
|
||||
|
||||
- (void)handleURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
|
||||
{
|
||||
NSString* path = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
|
||||
SDL_SendDropFile(NULL, [path UTF8String]);
|
||||
SDL_SendDropComplete(NULL);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static SDLAppDelegate *appDelegate = nil;
|
||||
@@ -280,7 +308,10 @@ LoadMainMenuNibIfAvailable(void)
|
||||
NSDictionary *infoDict;
|
||||
NSString *mainNibFileName;
|
||||
bool success = false;
|
||||
|
||||
|
||||
if (floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_8) {
|
||||
return false;
|
||||
}
|
||||
infoDict = [[NSBundle mainBundle] infoDictionary];
|
||||
if (infoDict) {
|
||||
mainNibFileName = [infoDict valueForKey:@"NSMainNibFile"];
|
||||
|
@@ -113,7 +113,7 @@ Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
||||
int i;
|
||||
for (i = 0; i < messageboxdata->numbuttons; ++i) {
|
||||
const SDL_MessageBoxButtonData *sdlButton;
|
||||
NSButton *button;
|
||||
NSButton *button;
|
||||
|
||||
if (messageboxdata->flags & SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT) {
|
||||
sdlButton = &messageboxdata->buttons[messageboxdata->numbuttons - 1 - i];
|
||||
@@ -142,8 +142,8 @@ Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
||||
if (clicked >= NSAlertFirstButtonReturn) {
|
||||
clicked -= NSAlertFirstButtonReturn;
|
||||
if (messageboxdata->flags & SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT) {
|
||||
clicked = messageboxdata->numbuttons - 1 - clicked;
|
||||
}
|
||||
clicked = messageboxdata->numbuttons - 1 - clicked;
|
||||
}
|
||||
*buttonid = buttons[clicked].buttonid;
|
||||
} else {
|
||||
returnValue = SDL_SetError("Did not get a valid `clicked button' id: %ld", (long)clicked);
|
||||
|
@@ -48,6 +48,7 @@
|
||||
windowID:(Uint32)windowID;
|
||||
|
||||
- (void)updateDrawableSize;
|
||||
- (NSView *)hitTest:(NSPoint)point;
|
||||
|
||||
/* Override superclass tag so this class can set it. */
|
||||
@property (assign, readonly) NSInteger tag;
|
||||
@@ -59,8 +60,8 @@
|
||||
|
||||
SDL_MetalView Cocoa_Metal_CreateView(_THIS, SDL_Window * window);
|
||||
void Cocoa_Metal_DestroyView(_THIS, SDL_MetalView view);
|
||||
|
||||
void Cocoa_Metal_GetDrawableSize(SDL_Window * window, int * w, int * h);
|
||||
void *Cocoa_Metal_GetLayer(_THIS, SDL_MetalView view);
|
||||
void Cocoa_Metal_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h);
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_METAL) */
|
||||
|
||||
|
@@ -24,12 +24,12 @@
|
||||
* Thanks to Alex Szpakowski, @slime73 on GitHub, for his gist showing
|
||||
* how to add a CAMetalLayer backed view.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#import "SDL_cocoametalview.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_METAL)
|
||||
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_events.h"
|
||||
|
||||
static int SDLCALL
|
||||
@@ -123,6 +123,10 @@ SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
|
||||
metalLayer.drawableSize = NSSizeToCGSize(backingSize);
|
||||
}
|
||||
|
||||
- (NSView *)hitTest:(NSPoint)point {
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
SDL_MetalView
|
||||
@@ -157,8 +161,15 @@ Cocoa_Metal_DestroyView(_THIS, SDL_MetalView view)
|
||||
[metalview removeFromSuperview];
|
||||
}}
|
||||
|
||||
void *
|
||||
Cocoa_Metal_GetLayer(_THIS, SDL_MetalView view)
|
||||
{ @autoreleasepool {
|
||||
SDL_cocoametalview *cocoaview = (__bridge SDL_cocoametalview *)view;
|
||||
return (__bridge void *)cocoaview.layer;
|
||||
}}
|
||||
|
||||
void
|
||||
Cocoa_Metal_GetDrawableSize(SDL_Window * window, int * w, int * h)
|
||||
Cocoa_Metal_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
|
||||
{ @autoreleasepool {
|
||||
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
|
||||
NSView *view = data->nswindow.contentView;
|
||||
|
@@ -19,7 +19,6 @@
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
#include "SDL_assert.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_COCOA
|
||||
|
||||
@@ -198,8 +197,9 @@ GetDisplayMode(_THIS, CGDisplayModeRef vidmode, CFArrayRef modelist, CVDisplayLi
|
||||
int pixelH = (int) CGDisplayModeGetPixelHeight(vidmode);
|
||||
|
||||
CFIndex modescount = CFArrayGetCount(modelist);
|
||||
int i;
|
||||
|
||||
for (int i = 0; i < modescount; i++) {
|
||||
for (i = 0; i < modescount; i++) {
|
||||
CGDisplayModeRef othermode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modelist, i);
|
||||
uint32_t otherioflags = CGDisplayModeGetIOFlags(othermode);
|
||||
|
||||
@@ -389,7 +389,7 @@ Cocoa_InitModes(_THIS)
|
||||
display.desktop_mode = mode;
|
||||
display.current_mode = mode;
|
||||
display.driverdata = displaydata;
|
||||
SDL_AddVideoDisplay(&display);
|
||||
SDL_AddVideoDisplay(&display, SDL_FALSE);
|
||||
SDL_free(display.name);
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,6 @@
|
||||
|
||||
#if SDL_VIDEO_DRIVER_COCOA
|
||||
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_cocoamouse.h"
|
||||
#include "SDL_cocoamousetap.h"
|
||||
|
@@ -49,6 +49,8 @@ struct SDL_GLDriverData
|
||||
- (void)scheduleUpdate;
|
||||
- (void)updateIfNeeded;
|
||||
- (void)setWindow:(SDL_Window *)window;
|
||||
- (SDL_Window*)window;
|
||||
- (void)explicitUpdate;
|
||||
|
||||
@end
|
||||
|
||||
|
47
externals/SDL/src/video/cocoa/SDL_cocoaopengl.m
vendored
47
externals/SDL/src/video/cocoa/SDL_cocoaopengl.m
vendored
@@ -63,10 +63,10 @@
|
||||
/* This should only be called on the thread on which a user is using the context. */
|
||||
- (void)updateIfNeeded
|
||||
{
|
||||
int value = SDL_AtomicSet(&self->dirty, 0);
|
||||
const int value = SDL_AtomicSet(&self->dirty, 0);
|
||||
if (value > 0) {
|
||||
/* We call the real underlying update here, since -[SDLOpenGLContext update] just calls us. */
|
||||
[super update];
|
||||
[self explicitUpdate];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,17 +97,6 @@
|
||||
SDL_WindowData *windowdata = (SDL_WindowData *)newWindow->driverdata;
|
||||
NSView *contentview = windowdata->sdlContentView;
|
||||
|
||||
/* This should never be nil since sdlContentView is only nil if the
|
||||
window was created via SDL_CreateWindowFrom, and SDL doesn't allow
|
||||
OpenGL contexts to be created in that case. However, it doesn't hurt
|
||||
to check. */
|
||||
if (contentview == nil) {
|
||||
/* Prefer to access the cached content view above instead of this,
|
||||
since as of Xcode 11 + SDK 10.15, [window contentView] causes
|
||||
Apple's Main Thread Checker to output a warning. */
|
||||
contentview = [windowdata->nswindow contentView];
|
||||
}
|
||||
|
||||
/* Now sign up for scheduled updates for the new window. */
|
||||
NSMutableArray *contexts = windowdata->nscontexts;
|
||||
@synchronized (contexts) {
|
||||
@@ -115,9 +104,13 @@
|
||||
}
|
||||
|
||||
if ([self view] != contentview) {
|
||||
[self setView:contentview];
|
||||
if ([NSThread isMainThread]) {
|
||||
[self setView:contentview];
|
||||
} else {
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{ [self setView:contentview]; });
|
||||
}
|
||||
if (self == [NSOpenGLContext currentContext]) {
|
||||
[self update];
|
||||
[self explicitUpdate];
|
||||
} else {
|
||||
[self scheduleUpdate];
|
||||
}
|
||||
@@ -125,13 +118,27 @@
|
||||
} else {
|
||||
[self clearDrawable];
|
||||
if (self == [NSOpenGLContext currentContext]) {
|
||||
[self update];
|
||||
[self explicitUpdate];
|
||||
} else {
|
||||
[self scheduleUpdate];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (SDL_Window*)window
|
||||
{
|
||||
return self->window;
|
||||
}
|
||||
|
||||
- (void)explicitUpdate
|
||||
{
|
||||
if ([NSThread isMainThread]) {
|
||||
[super update];
|
||||
} else {
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{ [super update]; });
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -348,8 +355,10 @@ Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
|
||||
{
|
||||
if (context) {
|
||||
SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
|
||||
[nscontext setWindow:window];
|
||||
[nscontext updateIfNeeded];
|
||||
if ([nscontext window] != window) {
|
||||
[nscontext setWindow:window];
|
||||
[nscontext updateIfNeeded];
|
||||
}
|
||||
[nscontext makeCurrentContext];
|
||||
} else {
|
||||
[NSOpenGLContext clearCurrentContext];
|
||||
@@ -362,7 +371,7 @@ void
|
||||
Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
|
||||
{
|
||||
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
||||
NSView *contentView = [windata->nswindow contentView];
|
||||
NSView *contentView = windata->sdlContentView;
|
||||
NSRect viewport = [contentView bounds];
|
||||
|
||||
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
|
||||
|
@@ -25,7 +25,6 @@
|
||||
#include "SDL_cocoavideo.h"
|
||||
#include "SDL_cocoaopengles.h"
|
||||
#include "SDL_cocoaopengl.h"
|
||||
#include "SDL_log.h"
|
||||
|
||||
/* EGL implementation of SDL OpenGL support */
|
||||
|
||||
@@ -110,10 +109,12 @@ Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
|
||||
|
||||
|
||||
if (_this->egl_data == NULL) {
|
||||
SDL_assert(!_this->gl_config.driver_loaded);
|
||||
if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, 0) < 0) {
|
||||
SDL_EGL_UnloadLibrary(_this);
|
||||
return -1;
|
||||
}
|
||||
_this->gl_config.driver_loaded = 1;
|
||||
}
|
||||
|
||||
/* Create the GLES window surface */
|
||||
|
10
externals/SDL/src/video/cocoa/SDL_cocoashape.m
vendored
10
externals/SDL/src/video/cocoa/SDL_cocoashape.m
vendored
@@ -18,7 +18,6 @@
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_COCOA
|
||||
@@ -27,7 +26,6 @@
|
||||
#include "SDL_shape.h"
|
||||
#include "SDL_cocoashape.h"
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "SDL_assert.h"
|
||||
|
||||
SDL_WindowShaper*
|
||||
Cocoa_CreateShaper(SDL_Window* window)
|
||||
@@ -37,14 +35,14 @@ Cocoa_CreateShaper(SDL_Window* window)
|
||||
|
||||
[windata->nswindow setStyleMask:NSWindowStyleMaskBorderless];
|
||||
|
||||
SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper));
|
||||
SDL_WindowShaper* result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper));
|
||||
result->window = window;
|
||||
result->mode.mode = ShapeModeDefault;
|
||||
result->mode.parameters.binarizationCutoff = 1;
|
||||
result->userx = result->usery = 0;
|
||||
window->shaper = result;
|
||||
|
||||
SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData));
|
||||
SDL_ShapeData* data = (SDL_ShapeData *)SDL_malloc(sizeof(SDL_ShapeData));
|
||||
result->driverdata = data;
|
||||
data->context = [windata->nswindow graphicsContext];
|
||||
data->saved = SDL_FALSE;
|
||||
@@ -88,10 +86,10 @@ Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowSha
|
||||
[NSGraphicsContext setCurrentContext:data->context];
|
||||
|
||||
[[NSColor clearColor] set];
|
||||
NSRectFill([[windata->nswindow contentView] frame]);
|
||||
NSRectFill([windata->sdlContentView frame]);
|
||||
data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
|
||||
|
||||
closure.view = [windata->nswindow contentView];
|
||||
closure.view = windata->sdlContentView;
|
||||
closure.path = [NSBezierPath bezierPath];
|
||||
closure.window = shaper->window;
|
||||
SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
|
||||
|
11
externals/SDL/src/video/cocoa/SDL_cocoavideo.m
vendored
11
externals/SDL/src/video/cocoa/SDL_cocoavideo.m
vendored
@@ -28,7 +28,6 @@
|
||||
#include "SDL_cocoashape.h"
|
||||
#include "SDL_cocoavulkan.h"
|
||||
#include "SDL_cocoametalview.h"
|
||||
#include "SDL_assert.h"
|
||||
|
||||
/* Initialization/Query functions */
|
||||
static int Cocoa_VideoInit(_THIS);
|
||||
@@ -36,12 +35,6 @@ static void Cocoa_VideoQuit(_THIS);
|
||||
|
||||
/* Cocoa driver bootstrap functions */
|
||||
|
||||
static int
|
||||
Cocoa_Available(void)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
|
||||
static void
|
||||
Cocoa_DeleteDevice(SDL_VideoDevice * device)
|
||||
{
|
||||
@@ -146,6 +139,8 @@ Cocoa_CreateDevice(int devindex)
|
||||
#if SDL_VIDEO_METAL
|
||||
device->Metal_CreateView = Cocoa_Metal_CreateView;
|
||||
device->Metal_DestroyView = Cocoa_Metal_DestroyView;
|
||||
device->Metal_GetLayer = Cocoa_Metal_GetLayer;
|
||||
device->Metal_GetDrawableSize = Cocoa_Metal_GetDrawableSize;
|
||||
#endif
|
||||
|
||||
device->StartTextInput = Cocoa_StartTextInput;
|
||||
@@ -163,7 +158,7 @@ Cocoa_CreateDevice(int devindex)
|
||||
|
||||
VideoBootStrap COCOA_bootstrap = {
|
||||
"cocoa", "SDL Cocoa video driver",
|
||||
Cocoa_Available, Cocoa_CreateDevice
|
||||
Cocoa_CreateDevice
|
||||
};
|
||||
|
||||
|
||||
|
@@ -29,7 +29,6 @@
|
||||
|
||||
#include "SDL_cocoavideo.h"
|
||||
#include "SDL_cocoawindow.h"
|
||||
#include "SDL_assert.h"
|
||||
|
||||
#include "SDL_loadso.h"
|
||||
#include "SDL_cocoametalview.h"
|
||||
@@ -236,7 +235,7 @@ SDL_bool Cocoa_Vulkan_CreateSurface(_THIS,
|
||||
|
||||
void Cocoa_Vulkan_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h)
|
||||
{
|
||||
Cocoa_Metal_GetDrawableSize(window, w, h);
|
||||
Cocoa_Metal_GetDrawableSize(_this, window, w, h);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -113,7 +113,7 @@ struct SDL_WindowData
|
||||
{
|
||||
SDL_Window *window;
|
||||
NSWindow *nswindow;
|
||||
NSView *sdlContentView; /* nil if window is created via CreateWindowFrom */
|
||||
NSView *sdlContentView;
|
||||
NSMutableArray *nscontexts;
|
||||
SDL_bool created;
|
||||
SDL_bool inWindowFullscreenTransition;
|
||||
|
74
externals/SDL/src/video/cocoa/SDL_cocoawindow.m
vendored
74
externals/SDL/src/video/cocoa/SDL_cocoawindow.m
vendored
@@ -41,7 +41,6 @@
|
||||
#include "SDL_cocoamousetap.h"
|
||||
#include "SDL_cocoaopengl.h"
|
||||
#include "SDL_cocoaopengles.h"
|
||||
#include "SDL_assert.h"
|
||||
|
||||
/* #define DEBUG_COCOAWINDOW */
|
||||
|
||||
@@ -57,6 +56,9 @@
|
||||
#ifndef MAC_OS_X_VERSION_10_12
|
||||
#define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask
|
||||
#endif
|
||||
#ifndef NSAppKitVersionNumber10_14
|
||||
#define NSAppKitVersionNumber10_14 1671
|
||||
#endif
|
||||
|
||||
@interface SDLWindow : NSWindow <NSDraggingDestination>
|
||||
/* These are needed for borderless/fullscreen windows */
|
||||
@@ -297,15 +299,15 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
|
||||
NSWindow *nswindow = data->nswindow;
|
||||
|
||||
/* The view responder chain gets messed with during setStyleMask */
|
||||
if ([[nswindow contentView] nextResponder] == data->listener) {
|
||||
[[nswindow contentView] setNextResponder:nil];
|
||||
if ([data->sdlContentView nextResponder] == data->listener) {
|
||||
[data->sdlContentView setNextResponder:nil];
|
||||
}
|
||||
|
||||
[nswindow setStyleMask:style];
|
||||
|
||||
/* The view responder chain gets messed with during setStyleMask */
|
||||
if ([[nswindow contentView] nextResponder] != data->listener) {
|
||||
[[nswindow contentView] setNextResponder:data->listener];
|
||||
if ([data->sdlContentView nextResponder] != data->listener) {
|
||||
[data->sdlContentView setNextResponder:data->listener];
|
||||
}
|
||||
|
||||
return SDL_TRUE;
|
||||
@@ -318,7 +320,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
|
||||
{
|
||||
NSNotificationCenter *center;
|
||||
NSWindow *window = data->nswindow;
|
||||
NSView *view = [window contentView];
|
||||
NSView *view = data->sdlContentView;
|
||||
|
||||
_data = data;
|
||||
observingVisible = YES;
|
||||
@@ -912,11 +914,9 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
|
||||
keypresses; it won't toggle the mod state if you send a keyrelease. */
|
||||
const SDL_bool osenabled = ([theEvent modifierFlags] & NSEventModifierFlagCapsLock) ? SDL_TRUE : SDL_FALSE;
|
||||
const SDL_bool sdlenabled = (SDL_GetModState() & KMOD_CAPS) ? SDL_TRUE : SDL_FALSE;
|
||||
if (!osenabled && sdlenabled) {
|
||||
SDL_ToggleModState(KMOD_CAPS, SDL_FALSE);
|
||||
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK);
|
||||
} else if (osenabled && !sdlenabled) {
|
||||
if (osenabled ^ sdlenabled) {
|
||||
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK);
|
||||
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK);
|
||||
}
|
||||
}
|
||||
- (void)keyDown:(NSEvent *)theEvent
|
||||
@@ -1360,7 +1360,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
|
||||
@end
|
||||
|
||||
static int
|
||||
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
|
||||
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, NSView *nsview, SDL_bool created)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
|
||||
@@ -1376,11 +1376,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
|
||||
data->created = created;
|
||||
data->videodata = videodata;
|
||||
data->nscontexts = [[NSMutableArray alloc] init];
|
||||
|
||||
/* Only store this for windows created by us since the content view might
|
||||
* get replaced from under us otherwise, and we only need it when the
|
||||
* window is guaranteed to be created by us (OpenGL contexts). */
|
||||
data->sdlContentView = created ? [nswindow contentView] : nil;
|
||||
data->sdlContentView = nsview;
|
||||
|
||||
/* Create an event listener for the window */
|
||||
data->listener = [[Cocoa_WindowListener alloc] init];
|
||||
@@ -1541,7 +1537,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
||||
[nswindow setContentView:contentView];
|
||||
[contentView release];
|
||||
|
||||
if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
|
||||
if (SetupWindowData(_this, window, nswindow, contentView, SDL_TRUE) < 0) {
|
||||
[nswindow release];
|
||||
return -1;
|
||||
}
|
||||
@@ -1571,7 +1567,19 @@ int
|
||||
Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSWindow *nswindow = (NSWindow *) data;
|
||||
NSView* nsview = nil;
|
||||
NSWindow *nswindow = nil;
|
||||
|
||||
if ([(id)data isKindOfClass:[NSWindow class]]) {
|
||||
nswindow = (NSWindow*)data;
|
||||
nsview = [nswindow contentView];
|
||||
} else if ([(id)data isKindOfClass:[NSView class]]) {
|
||||
nsview = (NSView*)data;
|
||||
nswindow = [nsview window];
|
||||
} else {
|
||||
SDL_assert(false);
|
||||
}
|
||||
|
||||
NSString *title;
|
||||
|
||||
/* Query the title from the existing window */
|
||||
@@ -1580,7 +1588,22 @@ Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
|
||||
window->title = SDL_strdup([title UTF8String]);
|
||||
}
|
||||
|
||||
return SetupWindowData(_this, window, nswindow, SDL_FALSE);
|
||||
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
/* Note: as of the macOS 10.15 SDK, this defaults to YES instead of NO when
|
||||
* the NSHighResolutionCapable boolean is set in Info.plist. */
|
||||
if ([nsview respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
|
||||
BOOL highdpi = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
|
||||
[nsview setWantsBestResolutionOpenGLSurface:highdpi];
|
||||
}
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
return SetupWindowData(_this, window, nswindow, nsview, SDL_FALSE);
|
||||
}}
|
||||
|
||||
void
|
||||
@@ -1795,8 +1818,8 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
|
||||
NSRect rect;
|
||||
|
||||
/* The view responder chain gets messed with during setStyleMask */
|
||||
if ([[nswindow contentView] nextResponder] == data->listener) {
|
||||
[[nswindow contentView] setNextResponder:nil];
|
||||
if ([data->sdlContentView nextResponder] == data->listener) {
|
||||
[data->sdlContentView setNextResponder:nil];
|
||||
}
|
||||
|
||||
if (fullscreen) {
|
||||
@@ -1812,10 +1835,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
|
||||
/* Hack to fix origin on Mac OS X 10.4
|
||||
This is no longer needed as of Mac OS X 10.15, according to bug 4822.
|
||||
*/
|
||||
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
||||
NSOperatingSystemVersion version = { 10, 15, 0 };
|
||||
if (![processInfo respondsToSelector:@selector(isOperatingSystemAtLeastVersion:)] ||
|
||||
![processInfo isOperatingSystemAtLeastVersion:version]) {
|
||||
if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_14) {
|
||||
NSRect screenRect = [[nswindow screen] frame];
|
||||
if (screenRect.size.height >= 1.0f) {
|
||||
rect.origin.y += (screenRect.size.height - rect.size.height);
|
||||
@@ -1845,8 +1865,8 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
|
||||
}
|
||||
|
||||
/* The view responder chain gets messed with during setStyleMask */
|
||||
if ([[nswindow contentView] nextResponder] != data->listener) {
|
||||
[[nswindow contentView] setNextResponder:data->listener];
|
||||
if ([data->sdlContentView nextResponder] != data->listener) {
|
||||
[data->sdlContentView setNextResponder:data->listener];
|
||||
}
|
||||
|
||||
s_moveHack = 0;
|
||||
|
Reference in New Issue
Block a user