Use bridged pointers to Objective C objects in C structures

Fixes https://github.com/libsdl-org/SDL/issues/7244
main
Sam Lantinga 2023-02-22 21:51:51 -08:00
parent 0fe1e9f3a7
commit 6c9e199f73
31 changed files with 150 additions and 177 deletions

View File

@ -31,34 +31,10 @@ typedef struct SDL_WindowShaper SDL_WindowShaper;
typedef struct SDL_ShapeDriver SDL_ShapeDriver; typedef struct SDL_ShapeDriver SDL_ShapeDriver;
typedef struct SDL_VideoDisplay SDL_VideoDisplay; typedef struct SDL_VideoDisplay SDL_VideoDisplay;
typedef struct SDL_VideoDevice SDL_VideoDevice; typedef struct SDL_VideoDevice SDL_VideoDevice;
#if defined(SDL_VIDEO_DRIVER_COCOA)
#ifdef __OBJC__
@class SDL_VideoData;
@class SDL_WindowData;
#else
typedef struct _SDL_VideoData SDL_VideoData;
typedef struct _SDL_WindowData SDL_WindowData;
#endif
typedef struct SDL_DisplayData SDL_DisplayData;
typedef struct SDL_DisplayModeData SDL_DisplayModeData;
#elif defined(SDL_VIDEO_DRIVER_UIKIT)
#ifdef __OBJC__
@class SDL_VideoData;
@class SDL_WindowData;
@class SDL_DisplayData;
@class SDL_DisplayModeData;
#else
typedef struct _SDL_VideoData SDL_VideoData;
typedef struct _SDL_WindowData SDL_WindowData;
typedef struct _SDL_DisplayData SDL_DisplayData;
typedef struct _SDL_DisplayModeData SDL_DisplayModeData;
#endif
#else
typedef struct SDL_VideoData SDL_VideoData; typedef struct SDL_VideoData SDL_VideoData;
typedef struct SDL_DisplayData SDL_DisplayData; typedef struct SDL_DisplayData SDL_DisplayData;
typedef struct SDL_DisplayModeData SDL_DisplayModeData; typedef struct SDL_DisplayModeData SDL_DisplayModeData;
typedef struct SDL_WindowData SDL_WindowData; typedef struct SDL_WindowData SDL_WindowData;
#endif /* SDL_VIDEO_DRIVER_COCOA || SDL_VIDEO_DRIVER_UIKIT */
/* Define the SDL window-shaper structure */ /* Define the SDL window-shaper structure */
struct SDL_WindowShaper struct SDL_WindowShaper

View File

@ -24,11 +24,11 @@
#define SDL_cocoaclipboard_h_ #define SDL_cocoaclipboard_h_
/* Forward declaration */ /* Forward declaration */
@class SDL_VideoData; @class SDL_CocoaVideoData;
extern int Cocoa_SetClipboardText(_THIS, const char *text); extern int Cocoa_SetClipboardText(_THIS, const char *text);
extern char *Cocoa_GetClipboardText(_THIS); extern char *Cocoa_GetClipboardText(_THIS);
extern SDL_bool Cocoa_HasClipboardText(_THIS); extern SDL_bool Cocoa_HasClipboardText(_THIS);
extern void Cocoa_CheckClipboardUpdate(SDL_VideoData *data); extern void Cocoa_CheckClipboardUpdate(SDL_CocoaVideoData *data);
#endif /* SDL_cocoaclipboard_h_ */ #endif /* SDL_cocoaclipboard_h_ */

View File

@ -28,7 +28,7 @@
int Cocoa_SetClipboardText(_THIS, const char *text) int Cocoa_SetClipboardText(_THIS, const char *text)
{ {
@autoreleasepool { @autoreleasepool {
SDL_VideoData *data = _this->driverdata; SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->driverdata;
NSPasteboard *pasteboard; NSPasteboard *pasteboard;
NSString *format = NSPasteboardTypeString; NSString *format = NSPasteboardTypeString;
NSString *nsstr = [NSString stringWithUTF8String:text]; NSString *nsstr = [NSString stringWithUTF8String:text];
@ -86,7 +86,7 @@ Cocoa_HasClipboardText(_THIS)
return result; return result;
} }
void Cocoa_CheckClipboardUpdate(SDL_VideoData *data) void Cocoa_CheckClipboardUpdate(SDL_CocoaVideoData *data)
{ {
@autoreleasepool { @autoreleasepool {
NSPasteboard *pasteboard; NSPasteboard *pasteboard;

View File

@ -35,7 +35,7 @@ static SDL_Window *FindSDLWindowForNSWindow(NSWindow *win)
SDL_VideoDevice *device = SDL_GetVideoDevice(); SDL_VideoDevice *device = SDL_GetVideoDevice();
if (device && device->windows) { if (device && device->windows) {
for (sdlwindow = device->windows; sdlwindow; sdlwindow = sdlwindow->next) { for (sdlwindow = device->windows; sdlwindow; sdlwindow = sdlwindow->next) {
NSWindow *nswindow = sdlwindow->driverdata.nswindow; NSWindow *nswindow = ((__bridge SDL_CocoaWindowData *)sdlwindow->driverdata).nswindow;
if (win == nswindow) { if (win == nswindow) {
return sdlwindow; return sdlwindow;
} }
@ -557,7 +557,7 @@ void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window)
location:NSMakePoint(0, 0) location:NSMakePoint(0, 0)
modifierFlags:0 modifierFlags:0
timestamp:0.0 timestamp:0.0
windowNumber:window->driverdata.window_number windowNumber:((__bridge SDL_CocoaWindowData *)window->driverdata).window_number
context:nil context:nil
subtype:0 subtype:0
data1:0 data1:0
@ -570,7 +570,7 @@ void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window)
int Cocoa_SuspendScreenSaver(_THIS) int Cocoa_SuspendScreenSaver(_THIS)
{ {
@autoreleasepool { @autoreleasepool {
SDL_VideoData *data = _this->driverdata; SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->driverdata;
if (data.screensaver_assertion) { if (data.screensaver_assertion) {
IOPMAssertionRelease(data.screensaver_assertion); IOPMAssertionRelease(data.screensaver_assertion);

View File

@ -228,7 +228,7 @@ static void HandleModifiers(_THIS, unsigned short scancode, unsigned int modifie
} }
} }
static void UpdateKeymap(SDL_VideoData *data, SDL_bool send_event) static void UpdateKeymap(SDL_CocoaVideoData *data, SDL_bool send_event)
{ {
TISInputSourceRef key_layout; TISInputSourceRef key_layout;
const void *chr_data; const void *chr_data;
@ -294,7 +294,7 @@ cleanup:
void Cocoa_InitKeyboard(_THIS) void Cocoa_InitKeyboard(_THIS)
{ {
SDL_VideoData *data = _this->driverdata; SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->driverdata;
UpdateKeymap(data, SDL_FALSE); UpdateKeymap(data, SDL_FALSE);
@ -314,11 +314,11 @@ void Cocoa_StartTextInput(_THIS)
{ {
@autoreleasepool { @autoreleasepool {
NSView *parentView; NSView *parentView;
SDL_VideoData *data = _this->driverdata; SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->driverdata;
SDL_Window *window = SDL_GetKeyboardFocus(); SDL_Window *window = SDL_GetKeyboardFocus();
NSWindow *nswindow = nil; NSWindow *nswindow = nil;
if (window) { if (window) {
nswindow = window->driverdata.nswindow; nswindow = ((__bridge SDL_CocoaWindowData *)window->driverdata).nswindow;
} }
parentView = [nswindow contentView]; parentView = [nswindow contentView];
@ -345,7 +345,7 @@ void Cocoa_StartTextInput(_THIS)
void Cocoa_StopTextInput(_THIS) void Cocoa_StopTextInput(_THIS)
{ {
@autoreleasepool { @autoreleasepool {
SDL_VideoData *data = _this->driverdata; SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->driverdata;
if (data && data.fieldEdit) { if (data && data.fieldEdit) {
[data.fieldEdit removeFromSuperview]; [data.fieldEdit removeFromSuperview];
@ -356,7 +356,7 @@ void Cocoa_StopTextInput(_THIS)
int Cocoa_SetTextInputRect(_THIS, const SDL_Rect *rect) int Cocoa_SetTextInputRect(_THIS, const SDL_Rect *rect)
{ {
SDL_VideoData *data = _this->driverdata; SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->driverdata;
[data.fieldEdit setInputRect:rect]; [data.fieldEdit setInputRect:rect];
return 0; return 0;
} }
@ -365,7 +365,7 @@ void Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
{ {
unsigned short scancode; unsigned short scancode;
SDL_Scancode code; SDL_Scancode code;
SDL_VideoData *data = _this ? _this->driverdata : nil; SDL_CocoaVideoData *data = _this ? ((__bridge SDL_CocoaVideoData *)_this->driverdata) : nil;
if (!data) { if (!data) {
return; /* can happen when returning from fullscreen Space on shutdown */ return; /* can happen when returning from fullscreen Space on shutdown */
} }

View File

@ -42,7 +42,7 @@
/* Retain the NSWindow because we'll show the alert later on the main thread */ /* Retain the NSWindow because we'll show the alert later on the main thread */
if (window) { if (window) {
nswindow = window->driverdata.nswindow; nswindow = ((__bridge SDL_CocoaWindowData *)window->driverdata).nswindow;
} else { } else {
nswindow = nil; nswindow = nil;
} }

View File

@ -133,7 +133,7 @@ SDL_MetalView
Cocoa_Metal_CreateView(_THIS, SDL_Window *window) Cocoa_Metal_CreateView(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSView *view = data.nswindow.contentView; NSView *view = data.nswindow.contentView;
BOOL highDPI = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0; BOOL highDPI = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
Uint32 windowID = SDL_GetWindowID(window); Uint32 windowID = SDL_GetWindowID(window);

View File

@ -363,7 +363,7 @@ void Cocoa_InitModes(_THIS)
int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
{ {
SDL_DisplayData *displaydata = display->driverdata; SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
CGRect cgrect; CGRect cgrect;
cgrect = CGDisplayBounds(displaydata->display); cgrect = CGDisplayBounds(displaydata->display);
@ -376,7 +376,7 @@ int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
int Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) int Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
{ {
SDL_DisplayData *displaydata = display->driverdata; SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
const CGDirectDisplayID cgdisplay = displaydata->display; const CGDirectDisplayID cgdisplay = displaydata->display;
NSArray *screens = [NSScreen screens]; NSArray *screens = [NSScreen screens];
NSScreen *screen = nil; NSScreen *screen = nil;
@ -408,7 +408,7 @@ int Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rec
int Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay *display) int Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
{ {
SDL_DisplayData *data = display->driverdata; SDL_DisplayData *data = (SDL_DisplayData *)display->driverdata;
CVDisplayLinkRef link = NULL; CVDisplayLinkRef link = NULL;
CFArrayRef modes; CFArrayRef modes;
CFDictionaryRef dict = NULL; CFDictionaryRef dict = NULL;
@ -485,7 +485,7 @@ static CGError SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayMo
int Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode) int Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
{ {
SDL_DisplayData *displaydata = display->driverdata; SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
SDL_DisplayModeData *data = (SDL_DisplayModeData *)mode->driverdata; SDL_DisplayModeData *data = (SDL_DisplayModeData *)mode->driverdata;
CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken; CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;
CGError result; CGError result;

View File

@ -253,7 +253,7 @@ static int Cocoa_WarpMouseGlobal(float x, float y)
CGPoint point; CGPoint point;
SDL_Mouse *mouse = SDL_GetMouse(); SDL_Mouse *mouse = SDL_GetMouse();
if (mouse->focus) { if (mouse->focus) {
SDL_WindowData *data = mouse->focus->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)mouse->focus->driverdata;
if ([data.listener isMovingOrFocusClickPending]) { if ([data.listener isMovingOrFocusClickPending]) {
DLog("Postponing warp, window being moved or focused."); DLog("Postponing warp, window being moved or focused.");
[data.listener setPendingMoveX:x Y:y]; [data.listener setPendingMoveX:x Y:y];
@ -298,7 +298,7 @@ static int Cocoa_SetRelativeMouseMode(SDL_bool enabled)
{ {
CGError result; CGError result;
SDL_Window *window; SDL_Window *window;
SDL_WindowData *data; SDL_CocoaWindowData *data;
if (enabled) { if (enabled) {
DLog("Turning on."); DLog("Turning on.");
result = CGAssociateMouseAndMouseCursorPosition(NO); result = CGAssociateMouseAndMouseCursorPosition(NO);
@ -321,7 +321,7 @@ static int Cocoa_SetRelativeMouseMode(SDL_bool enabled)
/* We will re-apply the non-relative mode when the window finishes being moved, /* We will re-apply the non-relative mode when the window finishes being moved,
* if it is being moved right now. * if it is being moved right now.
*/ */
data = window->driverdata; data = (__bridge SDL_CocoaWindowData *)window->driverdata;
if ([data.listener isMovingOrFocusClickPending]) { if ([data.listener isMovingOrFocusClickPending]) {
return 0; return 0;
} }
@ -402,7 +402,7 @@ static void Cocoa_HandleTitleButtonEvent(_THIS, NSEvent *event)
} }
for (window = _this->windows; window; window = window->next) { for (window = _this->windows; window; window = window->next) {
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
if (data && data.nswindow == nswindow) { if (data && data.nswindow == nswindow) {
switch ([event type]) { switch ([event type]) {
case NSEventTypeLeftMouseDown: case NSEventTypeLeftMouseDown:

View File

@ -138,7 +138,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
- (void)setWindow:(SDL_Window *)newWindow - (void)setWindow:(SDL_Window *)newWindow
{ {
if (self->window) { if (self->window) {
SDL_WindowData *oldwindowdata = self->window->driverdata; SDL_CocoaWindowData *oldwindowdata = (__bridge SDL_CocoaWindowData *)self->window->driverdata;
/* Make sure to remove us from the old window's context list, or we'll get scheduled updates from it too. */ /* Make sure to remove us from the old window's context list, or we'll get scheduled updates from it too. */
NSMutableArray *contexts = oldwindowdata.nscontexts; NSMutableArray *contexts = oldwindowdata.nscontexts;
@ -150,7 +150,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
self->window = newWindow; self->window = newWindow;
if (newWindow) { if (newWindow) {
SDL_WindowData *windowdata = newWindow->driverdata; SDL_CocoaWindowData *windowdata = (__bridge SDL_CocoaWindowData *)newWindow->driverdata;
NSView *contentview = windowdata.sdlContentView; NSView *contentview = windowdata.sdlContentView;
/* Now sign up for scheduled updates for the new window. */ /* Now sign up for scheduled updates for the new window. */
@ -254,7 +254,7 @@ SDL_GLContext Cocoa_GL_CreateContext(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window);
SDL_DisplayData *displaydata = display->driverdata; SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
NSOpenGLPixelFormatAttribute attr[32]; NSOpenGLPixelFormatAttribute attr[32];
NSOpenGLPixelFormat *fmt; NSOpenGLPixelFormat *fmt;
SDLOpenGLContext *context; SDLOpenGLContext *context;
@ -482,7 +482,7 @@ int Cocoa_GL_SwapWindow(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)SDL_GL_GetCurrentContext(); SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)SDL_GL_GetCurrentContext();
SDL_VideoData *videodata = _this->driverdata; SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->driverdata;
const int setting = SDL_AtomicGet(&nscontext->swapIntervalSetting); const int setting = SDL_AtomicGet(&nscontext->swapIntervalSetting);
if (setting == 0) { if (setting == 0) {

View File

@ -62,7 +62,7 @@ Cocoa_GLES_CreateContext(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_GLContext context; SDL_GLContext context;
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
#if SDL_VIDEO_OPENGL_CGL #if SDL_VIDEO_OPENGL_CGL
if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) { if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
@ -103,14 +103,14 @@ int Cocoa_GLES_DeleteContext(_THIS, SDL_GLContext context)
int Cocoa_GLES_SwapWindow(_THIS, SDL_Window *window) int Cocoa_GLES_SwapWindow(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
return SDL_EGL_SwapBuffers(_this, window->driverdata.egl_surface); return SDL_EGL_SwapBuffers(_this, ((__bridge SDL_CocoaWindowData *)window->driverdata).egl_surface);
} }
} }
int Cocoa_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) int Cocoa_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
{ {
@autoreleasepool { @autoreleasepool {
return SDL_EGL_MakeCurrent(_this, window ? window->driverdata.egl_surface : EGL_NO_SURFACE, context); return SDL_EGL_MakeCurrent(_this, window ? ((__bridge SDL_CocoaWindowData *)window->driverdata).egl_surface : EGL_NO_SURFACE, context);
} }
} }
@ -119,7 +119,7 @@ int Cocoa_GLES_SetupWindow(_THIS, SDL_Window *window)
@autoreleasepool { @autoreleasepool {
NSView *v; NSView *v;
/* The current context is lost in here; save it and reset it. */ /* The current context is lost in here; save it and reset it. */
SDL_WindowData *windowdata = window->driverdata; SDL_CocoaWindowData *windowdata = (__bridge SDL_CocoaWindowData *)window->driverdata;
SDL_Window *current_win = SDL_GL_GetCurrentWindow(); SDL_Window *current_win = SDL_GL_GetCurrentWindow();
SDL_GLContext current_ctx = SDL_GL_GetCurrentContext(); SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
@ -151,7 +151,7 @@ SDL_EGLSurface
Cocoa_GLES_GetEGLSurface(_THIS, SDL_Window *window) Cocoa_GLES_GetEGLSurface(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
return window->driverdata.egl_surface; return ((__bridge SDL_CocoaWindowData *)window->driverdata).egl_surface;
} }
} }

View File

@ -45,7 +45,7 @@ Cocoa_CreateShaper(SDL_Window *window)
SDL_WindowShaper *result; SDL_WindowShaper *result;
SDL_ShapeData *data; SDL_ShapeData *data;
int resized_properly; int resized_properly;
SDL_WindowData *windata = window->driverdata; SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->driverdata;
result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper)); result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper));
if (!result) { if (!result) {
@ -90,7 +90,7 @@ int Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_Windo
{ {
@autoreleasepool { @autoreleasepool {
SDL_ShapeData *data = (__bridge SDL_ShapeData *)shaper->driverdata; SDL_ShapeData *data = (__bridge SDL_ShapeData *)shaper->driverdata;
SDL_WindowData *windata = shaper->window->driverdata; SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)shaper->window->driverdata;
SDL_CocoaClosure *closure; SDL_CocoaClosure *closure;
if (data.saved == SDL_TRUE) { if (data.saved == SDL_TRUE) {
[data.context restoreGraphicsState]; [data.context restoreGraphicsState];

View File

@ -96,7 +96,7 @@ DECLARE_ALERT_STYLE(Critical);
@class SDLTranslatorResponder; @class SDLTranslatorResponder;
@interface SDL_VideoData : NSObject @interface SDL_CocoaVideoData : NSObject
@property(nonatomic) int allow_spaces; @property(nonatomic) int allow_spaces;
@property(nonatomic) int trackpad_is_touch_only; @property(nonatomic) int trackpad_is_touch_only;
@property(nonatomic) unsigned int modifierFlags; @property(nonatomic) unsigned int modifierFlags;

View File

@ -32,7 +32,7 @@
#include "SDL_cocoametalview.h" #include "SDL_cocoametalview.h"
#include "SDL_cocoaopengles.h" #include "SDL_cocoaopengles.h"
@implementation SDL_VideoData @implementation SDL_CocoaVideoData
@end @end
@ -48,7 +48,7 @@ static void Cocoa_DeleteDevice(SDL_VideoDevice *device)
if (device->wakeup_lock) { if (device->wakeup_lock) {
SDL_DestroyMutex(device->wakeup_lock); SDL_DestroyMutex(device->wakeup_lock);
} }
device->driverdata = nil; CFBridgingRelease(device->driverdata);
SDL_free(device); SDL_free(device);
} }
} }
@ -57,14 +57,14 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void)
{ {
@autoreleasepool { @autoreleasepool {
SDL_VideoDevice *device; SDL_VideoDevice *device;
SDL_VideoData *data; SDL_CocoaVideoData *data;
Cocoa_RegisterApp(); Cocoa_RegisterApp();
/* Initialize all variables that we clean on shutdown */ /* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice));
if (device) { if (device) {
data = [[SDL_VideoData alloc] init]; data = [[SDL_CocoaVideoData alloc] init];
} else { } else {
data = nil; data = nil;
} }
@ -73,7 +73,7 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void)
SDL_free(device); SDL_free(device);
return NULL; return NULL;
} }
device->driverdata = data; device->driverdata = (SDL_VideoData *)CFBridgingRetain(data);
device->wakeup_lock = SDL_CreateMutex(); device->wakeup_lock = SDL_CreateMutex();
/* Set the function pointers */ /* Set the function pointers */
@ -189,7 +189,7 @@ VideoBootStrap COCOA_bootstrap = {
int Cocoa_VideoInit(_THIS) int Cocoa_VideoInit(_THIS)
{ {
@autoreleasepool { @autoreleasepool {
SDL_VideoData *data = _this->driverdata; SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->driverdata;
Cocoa_InitModes(_this); Cocoa_InitModes(_this);
Cocoa_InitKeyboard(_this); Cocoa_InitKeyboard(_this);
@ -212,7 +212,7 @@ int Cocoa_VideoInit(_THIS)
void Cocoa_VideoQuit(_THIS) void Cocoa_VideoQuit(_THIS)
{ {
@autoreleasepool { @autoreleasepool {
SDL_VideoData *data = _this->driverdata; SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->driverdata;
Cocoa_QuitModes(_this); Cocoa_QuitModes(_this);
Cocoa_QuitKeyboard(_this); Cocoa_QuitKeyboard(_this);
Cocoa_QuitMouse(_this); Cocoa_QuitMouse(_this);

View File

@ -262,7 +262,7 @@ SDL_bool Cocoa_Vulkan_CreateSurface(_THIS,
if (window->flags & SDL_WINDOW_FOREIGN) { if (window->flags & SDL_WINDOW_FOREIGN) {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
if (![data.sdlContentView.layer isKindOfClass:[CAMetalLayer class]]) { if (![data.sdlContentView.layer isKindOfClass:[CAMetalLayer class]]) {
[data.sdlContentView setLayer:[CAMetalLayer layer]]; [data.sdlContentView setLayer:[CAMetalLayer layer]];
} }

View File

@ -29,7 +29,7 @@
#include "../SDL_egl_c.h" #include "../SDL_egl_c.h"
#endif #endif
@class SDL_WindowData; @class SDL_CocoaWindowData;
typedef enum typedef enum
{ {
@ -41,10 +41,10 @@ typedef enum
@interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> @interface Cocoa_WindowListener : NSResponder <NSWindowDelegate>
{ {
/* SDL_WindowData owns this Listener and has a strong reference to it. /* SDL_CocoaWindowData owns this Listener and has a strong reference to it.
* To avoid reference cycles, we could have either a weak or an * To avoid reference cycles, we could have either a weak or an
* unretained ref to the WindowData. */ * unretained ref to the WindowData. */
__weak SDL_WindowData *_data; __weak SDL_CocoaWindowData *_data;
BOOL observingVisible; BOOL observingVisible;
BOOL wasCtrlLeft; BOOL wasCtrlLeft;
BOOL wasVisible; BOOL wasVisible;
@ -58,7 +58,7 @@ typedef enum
} }
- (BOOL)isTouchFromTrackpad:(NSEvent *)theEvent; - (BOOL)isTouchFromTrackpad:(NSEvent *)theEvent;
- (void)listen:(SDL_WindowData *)data; - (void)listen:(SDL_CocoaWindowData *)data;
- (void)pauseVisibleObservation; - (void)pauseVisibleObservation;
- (void)resumeVisibleObservation; - (void)resumeVisibleObservation;
- (BOOL)setFullscreenSpace:(BOOL)state; - (BOOL)setFullscreenSpace:(BOOL)state;
@ -120,9 +120,9 @@ typedef enum
/* *INDENT-ON* */ /* *INDENT-ON* */
@class SDLOpenGLContext; @class SDLOpenGLContext;
@class SDL_VideoData; @class SDL_CocoaVideoData;
@interface SDL_WindowData : NSObject @interface SDL_CocoaWindowData : NSObject
@property(nonatomic) SDL_Window *window; @property(nonatomic) SDL_Window *window;
@property(nonatomic) NSWindow *nswindow; @property(nonatomic) NSWindow *nswindow;
@property(nonatomic) NSView *sdlContentView; @property(nonatomic) NSView *sdlContentView;
@ -132,7 +132,7 @@ typedef enum
@property(nonatomic) NSInteger window_number; @property(nonatomic) NSInteger window_number;
@property(nonatomic) NSInteger flash_request; @property(nonatomic) NSInteger flash_request;
@property(nonatomic) Cocoa_WindowListener *listener; @property(nonatomic) Cocoa_WindowListener *listener;
@property(nonatomic) SDL_VideoData *videodata; @property(nonatomic) SDL_CocoaVideoData *videodata;
#if SDL_VIDEO_OPENGL_EGL #if SDL_VIDEO_OPENGL_EGL
@property(nonatomic) EGLSurface egl_surface; @property(nonatomic) EGLSurface egl_surface;
#endif #endif

View File

@ -63,7 +63,7 @@
#define NSAppKitVersionNumber10_14 1671 #define NSAppKitVersionNumber10_14 1671
#endif #endif
@implementation SDL_WindowData @implementation SDL_CocoaWindowData
@end @end
@ -239,7 +239,7 @@
/* !!! FIXME: is there a better way to do this? */ /* !!! FIXME: is there a better way to do this? */
if (_this) { if (_this) {
for (sdlwindow = _this->windows; sdlwindow; sdlwindow = sdlwindow->next) { for (sdlwindow = _this->windows; sdlwindow; sdlwindow = sdlwindow->next) {
NSWindow *nswindow = sdlwindow->driverdata.nswindow; NSWindow *nswindow = ((__bridge SDL_CocoaWindowData *)sdlwindow->driverdata).nswindow;
if (nswindow == self) { if (nswindow == self) {
break; break;
} }
@ -258,7 +258,7 @@ static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height; r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
} }
static void ScheduleContextUpdates(SDL_WindowData *data) static void ScheduleContextUpdates(SDL_CocoaWindowData *data)
{ {
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */ /* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
#if SDL_VIDEO_OPENGL #if SDL_VIDEO_OPENGL
@ -333,7 +333,7 @@ static NSUInteger GetWindowStyle(SDL_Window *window)
static SDL_bool SetWindowStyle(SDL_Window *window, NSUInteger style) static SDL_bool SetWindowStyle(SDL_Window *window, NSUInteger style)
{ {
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSWindow *nswindow = data.nswindow; NSWindow *nswindow = data.nswindow;
/* The view responder chain gets messed with during setStyleMask */ /* The view responder chain gets messed with during setStyleMask */
@ -353,7 +353,7 @@ static SDL_bool SetWindowStyle(SDL_Window *window, NSUInteger style)
static SDL_bool ShouldAdjustCoordinatesForGrab(SDL_Window *window) static SDL_bool ShouldAdjustCoordinatesForGrab(SDL_Window *window)
{ {
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
if (!data || [data.listener isMovingOrFocusClickPending]) { if (!data || [data.listener isMovingOrFocusClickPending]) {
return SDL_FALSE; return SDL_FALSE;
@ -410,7 +410,7 @@ static SDL_bool AdjustCoordinatesForGrab(SDL_Window *window, float x, float y, C
static void Cocoa_UpdateClipCursor(SDL_Window *window) static void Cocoa_UpdateClipCursor(SDL_Window *window)
{ {
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_13_2) { if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_13_2) {
NSWindow *nswindow = data.nswindow; NSWindow *nswindow = data.nswindow;
@ -463,7 +463,7 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
@implementation Cocoa_WindowListener @implementation Cocoa_WindowListener
- (void)listen:(SDL_WindowData *)data - (void)listen:(SDL_CocoaWindowData *)data
{ {
NSNotificationCenter *center; NSNotificationCenter *center;
NSWindow *window = data.nswindow; NSWindow *window = data.nswindow;
@ -564,7 +564,7 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
{ {
SDL_Window *window = _data.window; SDL_Window *window = _data.window;
NSWindow *nswindow = _data.nswindow; NSWindow *nswindow = _data.nswindow;
SDL_VideoData *videodata = window->driverdata.videodata; SDL_CocoaVideoData *videodata = ((__bridge SDL_CocoaWindowData *)window->driverdata).videodata;
if (!videodata.allow_spaces) { if (!videodata.allow_spaces) {
return NO; /* Spaces are forcibly disabled. */ return NO; /* Spaces are forcibly disabled. */
@ -1198,7 +1198,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
// the position in the currently-focused window. We don't (currently) send a mousemove // the position in the currently-focused window. We don't (currently) send a mousemove
// event for the background window, this just makes sure the button is reported at the // event for the background window, this just makes sure the button is reported at the
// correct position in its own event. // correct position in its own event.
if (focus && ([theEvent window] == focus->driverdata.nswindow)) { if (focus && ([theEvent window] == ((__bridge SDL_CocoaWindowData *)focus->driverdata).nswindow)) {
rc = SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, state, button, clicks); rc = SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, state, button, clicks);
} else { } else {
const int orig_x = mouse->x; const int orig_x = mouse->x;
@ -1384,7 +1384,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
- (BOOL)isTouchFromTrackpad:(NSEvent *)theEvent - (BOOL)isTouchFromTrackpad:(NSEvent *)theEvent
{ {
SDL_Window *window = _data.window; SDL_Window *window = _data.window;
SDL_VideoData *videodata = window->driverdata.videodata; SDL_CocoaVideoData *videodata = ((__bridge SDL_CocoaWindowData *)window->driverdata).videodata;
/* if this a MacBook trackpad, we'll make input look like a synthesized /* if this a MacBook trackpad, we'll make input look like a synthesized
event. This is backwards from reality, but better matches user event. This is backwards from reality, but better matches user
@ -1573,7 +1573,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
white until the app is ready to draw. In practice on modern macOS, this white until the app is ready to draw. In practice on modern macOS, this
only gets called for window creation and other extraordinary events. */ only gets called for window creation and other extraordinary events. */
self.layer.backgroundColor = CGColorGetConstantColor(kCGColorBlack); self.layer.backgroundColor = CGColorGetConstantColor(kCGColorBlack);
ScheduleContextUpdates(_sdlWindow->driverdata); ScheduleContextUpdates((__bridge SDL_CocoaWindowData *)_sdlWindow->driverdata);
SDL_SendWindowEvent(_sdlWindow, SDL_EVENT_WINDOW_EXPOSED, 0, 0); SDL_SendWindowEvent(_sdlWindow, SDL_EVENT_WINDOW_EXPOSED, 0, 0);
} }
@ -1604,11 +1604,11 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
static int SetupWindowData(_THIS, SDL_Window *window, NSWindow *nswindow, NSView *nsview, SDL_bool created) static int SetupWindowData(_THIS, SDL_Window *window, NSWindow *nswindow, NSView *nsview, SDL_bool created)
{ {
@autoreleasepool { @autoreleasepool {
SDL_VideoData *videodata = _this->driverdata; SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->driverdata;
SDL_WindowData *data; SDL_CocoaWindowData *data;
/* Allocate the window data */ /* Allocate the window data */
data = [[SDL_WindowData alloc] init]; data = [[SDL_CocoaWindowData alloc] init];
if (!data) { if (!data) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -1679,7 +1679,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, NSWindow *nswindow, NSView
SDL_SetKeyboardFocus(data.window); SDL_SetKeyboardFocus(data.window);
} }
/* SDL_WindowData will be holding a strong reference to the NSWindow, and /* SDL_CocoaWindowData will be holding a strong reference to the NSWindow, and
* it will also call [NSWindow close] in DestroyWindow before releasing the * it will also call [NSWindow close] in DestroyWindow before releasing the
* NSWindow, so the extra release provided by releasedWhenClosed isn't * NSWindow, so the extra release provided by releasedWhenClosed isn't
* necessary. */ * necessary. */
@ -1691,7 +1691,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, NSWindow *nswindow, NSView
[nswindow setOneShot:NO]; [nswindow setOneShot:NO];
/* All done! */ /* All done! */
window->driverdata = data; window->driverdata = (SDL_WindowData *)CFBridgingRetain(data);
return 0; return 0;
} }
} }
@ -1699,7 +1699,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, NSWindow *nswindow, NSView
int Cocoa_CreateWindow(_THIS, SDL_Window *window) int Cocoa_CreateWindow(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_VideoData *videodata = _this->driverdata; SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->driverdata;
NSWindow *nswindow; NSWindow *nswindow;
SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window);
NSRect rect; NSRect rect;
@ -1868,7 +1868,7 @@ void Cocoa_SetWindowTitle(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
const char *title = window->title ? window->title : ""; const char *title = window->title ? window->title : "";
NSWindow *nswindow = window->driverdata.nswindow; NSWindow *nswindow = ((__bridge SDL_CocoaWindowData *)window->driverdata).nswindow;
NSString *string = [[NSString alloc] initWithUTF8String:title]; NSString *string = [[NSString alloc] initWithUTF8String:title];
[nswindow setTitle:string]; [nswindow setTitle:string];
} }
@ -1892,7 +1892,7 @@ int Cocoa_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon)
void Cocoa_SetWindowPosition(_THIS, SDL_Window *window) void Cocoa_SetWindowPosition(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *windata = window->driverdata; SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSWindow *nswindow = windata.nswindow; NSWindow *nswindow = windata.nswindow;
NSRect rect; NSRect rect;
BOOL fullscreen; BOOL fullscreen;
@ -1917,7 +1917,7 @@ void Cocoa_SetWindowPosition(_THIS, SDL_Window *window)
void Cocoa_SetWindowSize(_THIS, SDL_Window *window) void Cocoa_SetWindowSize(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *windata = window->driverdata; SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSWindow *nswindow = windata.nswindow; NSWindow *nswindow = windata.nswindow;
NSRect rect; NSRect rect;
BOOL fullscreen; BOOL fullscreen;
@ -1946,7 +1946,7 @@ void Cocoa_SetWindowSize(_THIS, SDL_Window *window)
void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window *window) void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *windata = window->driverdata; SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSSize minSize; NSSize minSize;
minSize.width = window->min_w; minSize.width = window->min_w;
@ -1959,7 +1959,7 @@ void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window *window)
void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window *window) void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *windata = window->driverdata; SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSSize maxSize; NSSize maxSize;
maxSize.width = window->max_w; maxSize.width = window->max_w;
@ -1972,7 +1972,7 @@ void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window *window)
void Cocoa_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int *h) void Cocoa_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int *h)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *windata = window->driverdata; SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSView *contentView = windata.sdlContentView; NSView *contentView = windata.sdlContentView;
NSRect viewport = [contentView bounds]; NSRect viewport = [contentView bounds];
@ -1989,7 +1989,7 @@ void Cocoa_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int *h)
void Cocoa_ShowWindow(_THIS, SDL_Window *window) void Cocoa_ShowWindow(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *windowData = window->driverdata; SDL_CocoaWindowData *windowData = ((__bridge SDL_CocoaWindowData *)window->driverdata);
NSWindow *nswindow = windowData.nswindow; NSWindow *nswindow = windowData.nswindow;
if (![nswindow isMiniaturized]) { if (![nswindow isMiniaturized]) {
@ -2003,7 +2003,7 @@ void Cocoa_ShowWindow(_THIS, SDL_Window *window)
void Cocoa_HideWindow(_THIS, SDL_Window *window) void Cocoa_HideWindow(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
NSWindow *nswindow = window->driverdata.nswindow; NSWindow *nswindow = ((__bridge SDL_CocoaWindowData *)window->driverdata).nswindow;
[nswindow orderOut:nil]; [nswindow orderOut:nil];
} }
@ -2012,7 +2012,7 @@ void Cocoa_HideWindow(_THIS, SDL_Window *window)
void Cocoa_RaiseWindow(_THIS, SDL_Window *window) void Cocoa_RaiseWindow(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *windowData = window->driverdata; SDL_CocoaWindowData *windowData = ((__bridge SDL_CocoaWindowData *)window->driverdata);
NSWindow *nswindow = windowData.nswindow; NSWindow *nswindow = windowData.nswindow;
/* makeKeyAndOrderFront: has the side-effect of deminiaturizing and showing /* makeKeyAndOrderFront: has the side-effect of deminiaturizing and showing
@ -2030,7 +2030,7 @@ void Cocoa_RaiseWindow(_THIS, SDL_Window *window)
void Cocoa_MaximizeWindow(_THIS, SDL_Window *window) void Cocoa_MaximizeWindow(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *windata = window->driverdata; SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSWindow *nswindow = windata.nswindow; NSWindow *nswindow = windata.nswindow;
[nswindow zoom:nil]; [nswindow zoom:nil];
@ -2042,7 +2042,7 @@ void Cocoa_MaximizeWindow(_THIS, SDL_Window *window)
void Cocoa_MinimizeWindow(_THIS, SDL_Window *window) void Cocoa_MinimizeWindow(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSWindow *nswindow = data.nswindow; NSWindow *nswindow = data.nswindow;
if ([data.listener isInFullscreenSpaceTransition]) { if ([data.listener isInFullscreenSpaceTransition]) {
[data.listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE]; [data.listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
@ -2055,7 +2055,7 @@ void Cocoa_MinimizeWindow(_THIS, SDL_Window *window)
void Cocoa_RestoreWindow(_THIS, SDL_Window *window) void Cocoa_RestoreWindow(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
NSWindow *nswindow = window->driverdata.nswindow; NSWindow *nswindow = ((__bridge SDL_CocoaWindowData *)window->driverdata).nswindow;
if ([nswindow isMiniaturized]) { if ([nswindow isMiniaturized]) {
[nswindow deminiaturize:nil]; [nswindow deminiaturize:nil];
@ -2083,10 +2083,10 @@ void Cocoa_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable)
* The window will get permanently stuck if resizable is false. * The window will get permanently stuck if resizable is false.
* -flibit * -flibit
*/ */
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
Cocoa_WindowListener *listener = data.listener; Cocoa_WindowListener *listener = data.listener;
NSWindow *nswindow = data.nswindow; NSWindow *nswindow = data.nswindow;
SDL_VideoData *videodata = data.videodata; SDL_CocoaVideoData *videodata = data.videodata;
if (![listener isInFullscreenSpace]) { if (![listener isInFullscreenSpace]) {
SetWindowStyle(window, GetWindowStyle(window)); SetWindowStyle(window, GetWindowStyle(window));
} }
@ -2104,7 +2104,7 @@ void Cocoa_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable)
void Cocoa_SetWindowAlwaysOnTop(_THIS, SDL_Window *window, SDL_bool on_top) void Cocoa_SetWindowAlwaysOnTop(_THIS, SDL_Window *window, SDL_bool on_top)
{ {
@autoreleasepool { @autoreleasepool {
NSWindow *nswindow = window->driverdata.nswindow; NSWindow *nswindow = ((__bridge SDL_CocoaWindowData *)window->driverdata).nswindow;
if (on_top) { if (on_top) {
[nswindow setLevel:NSFloatingWindowLevel]; [nswindow setLevel:NSFloatingWindowLevel];
} else { } else {
@ -2116,7 +2116,7 @@ void Cocoa_SetWindowAlwaysOnTop(_THIS, SDL_Window *window, SDL_bool on_top)
void Cocoa_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen) void Cocoa_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSWindow *nswindow = data.nswindow; NSWindow *nswindow = data.nswindow;
NSRect rect; NSRect rect;
@ -2206,7 +2206,7 @@ void *
Cocoa_GetWindowICCProfile(_THIS, SDL_Window *window, size_t *size) Cocoa_GetWindowICCProfile(_THIS, SDL_Window *window, size_t *size)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSWindow *nswindow = data.nswindow; NSWindow *nswindow = data.nswindow;
NSScreen *screen = [nswindow screen]; NSScreen *screen = [nswindow screen];
NSData *iccProfileData = nil; NSData *iccProfileData = nil;
@ -2244,7 +2244,7 @@ SDL_DisplayID Cocoa_GetDisplayForWindow(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
NSScreen *screen; NSScreen *screen;
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
/* Not recognized via CHECK_WINDOW_MAGIC */ /* Not recognized via CHECK_WINDOW_MAGIC */
if (data == nil) { if (data == nil) {
@ -2284,7 +2284,7 @@ void Cocoa_SetWindowMouseRect(_THIS, SDL_Window *window)
void Cocoa_SetWindowMouseGrab(_THIS, SDL_Window *window, SDL_bool grabbed) void Cocoa_SetWindowMouseGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
Cocoa_UpdateClipCursor(window); Cocoa_UpdateClipCursor(window);
@ -2305,7 +2305,7 @@ void Cocoa_SetWindowMouseGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
void Cocoa_DestroyWindow(_THIS, SDL_Window *window) void Cocoa_DestroyWindow(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (SDL_CocoaWindowData *)CFBridgingRelease(window->driverdata);
if (data) { if (data) {
#if SDL_VIDEO_OPENGL #if SDL_VIDEO_OPENGL
@ -2341,14 +2341,14 @@ void Cocoa_DestroyWindow(_THIS, SDL_Window *window)
window->shaper = NULL; window->shaper = NULL;
} }
} }
window->driverdata = nil; window->driverdata = NULL;
} }
} }
int Cocoa_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info) int Cocoa_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
{ {
@autoreleasepool { @autoreleasepool {
NSWindow *nswindow = window->driverdata.nswindow; NSWindow *nswindow = ((__bridge SDL_CocoaWindowData *)window->driverdata).nswindow;
info->subsystem = SDL_SYSWM_COCOA; info->subsystem = SDL_SYSWM_COCOA;
info->info.cocoa.window = nswindow; info->info.cocoa.window = nswindow;
@ -2360,7 +2360,7 @@ SDL_bool
Cocoa_IsWindowInFullscreenSpace(SDL_Window *window) Cocoa_IsWindowInFullscreenSpace(SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
if ([data.listener isInFullscreenSpace]) { if ([data.listener isInFullscreenSpace]) {
return SDL_TRUE; return SDL_TRUE;
@ -2375,7 +2375,7 @@ Cocoa_SetWindowFullscreenSpace(SDL_Window *window, SDL_bool state)
{ {
@autoreleasepool { @autoreleasepool {
SDL_bool succeeded = SDL_FALSE; SDL_bool succeeded = SDL_FALSE;
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
if (data.inWindowFullscreenTransition) { if (data.inWindowFullscreenTransition) {
return SDL_FALSE; return SDL_FALSE;
@ -2424,7 +2424,7 @@ int Cocoa_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
void Cocoa_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept) void Cocoa_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
if (accept) { if (accept) {
[data.nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]]; [data.nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
} else { } else {
@ -2437,7 +2437,7 @@ int Cocoa_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation)
{ {
@autoreleasepool { @autoreleasepool {
/* Note that this is app-wide and not window-specific! */ /* Note that this is app-wide and not window-specific! */
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
if (data.flash_request) { if (data.flash_request) {
[NSApp cancelUserAttentionRequest:data.flash_request]; [NSApp cancelUserAttentionRequest:data.flash_request];
@ -2464,7 +2464,7 @@ int Cocoa_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation)
int Cocoa_SetWindowOpacity(_THIS, SDL_Window *window, float opacity) int Cocoa_SetWindowOpacity(_THIS, SDL_Window *window, float opacity)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
[data.nswindow setAlphaValue:opacity]; [data.nswindow setAlphaValue:opacity];
return 0; return 0;
} }

View File

@ -25,11 +25,7 @@
#include "SDL_offscreenvideo.h" #include "SDL_offscreenvideo.h"
#if defined(SDL_VIDEO_DRIVER_COCOA) || defined(SDL_VIDEO_DRIVER_UIKIT)
struct _SDL_WindowData
#else
struct SDL_WindowData struct SDL_WindowData
#endif
{ {
SDL_Window *sdl_window; SDL_Window *sdl_window;
#if SDL_VIDEO_OPENGL_EGL #if SDL_VIDEO_OPENGL_EGL

View File

@ -468,7 +468,7 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
if (_this) { if (_this) {
SDL_Window *window = NULL; SDL_Window *window = NULL;
for (window = _this->windows; window != NULL; window = window->next) { for (window = _this->windows; window != NULL; window = window->next) {
SDL_WindowData *data = window->driverdata; SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
if (data != nil) { if (data != nil) {
return data.uiwindow; return data.uiwindow;
} }

View File

@ -75,7 +75,7 @@ void UIKit_InitClipboard(_THIS)
{ {
#if !TARGET_OS_TV #if !TARGET_OS_TV
@autoreleasepool { @autoreleasepool {
SDL_VideoData *data = _this->driverdata; SDL_UIKitVideoData *data = (__bridge SDL_UIKitVideoData *)_this->driverdata;
NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
id observer = [center addObserverForName:UIPasteboardChangedNotification id observer = [center addObserverForName:UIPasteboardChangedNotification
@ -93,7 +93,7 @@ void UIKit_InitClipboard(_THIS)
void UIKit_QuitClipboard(_THIS) void UIKit_QuitClipboard(_THIS)
{ {
@autoreleasepool { @autoreleasepool {
SDL_VideoData *data = _this->driverdata; SDL_UIKitVideoData *data = (__bridge SDL_UIKitVideoData *)_this->driverdata;
if (data.pasteboardObserver != nil) { if (data.pasteboardObserver != nil) {
[[NSNotificationCenter defaultCenter] removeObserver:data.pasteboardObserver]; [[NSNotificationCenter defaultCenter] removeObserver:data.pasteboardObserver];

View File

@ -94,7 +94,7 @@ static BOOL UIKit_ShowMessageBoxAlertController(const SDL_MessageBoxData *messag
} }
if (messageboxdata->window) { if (messageboxdata->window) {
SDL_WindowData *data = messageboxdata->window->driverdata; SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)messageboxdata->window->driverdata;
window = data.uiwindow; window = data.uiwindow;
} }

View File

@ -78,7 +78,7 @@ SDL_MetalView
UIKit_Metal_CreateView(_THIS, SDL_Window *window) UIKit_Metal_CreateView(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
CGFloat scale = 1.0; CGFloat scale = 1.0;
SDL_uikitmetalview *metalview; SDL_uikitmetalview *metalview;

View File

@ -25,7 +25,7 @@
#include "SDL_uikitvideo.h" #include "SDL_uikitvideo.h"
@interface SDL_DisplayData : NSObject @interface SDL_UIKitDisplayData : NSObject
- (instancetype)initWithScreen:(UIScreen *)screen; - (instancetype)initWithScreen:(UIScreen *)screen;
@ -33,7 +33,7 @@
@end @end
@interface SDL_DisplayModeData : NSObject @interface SDL_UIKitDisplayModeData : NSObject
@property(nonatomic, strong) UIScreenMode *uiscreenmode; @property(nonatomic, strong) UIScreenMode *uiscreenmode;

View File

@ -28,7 +28,7 @@
#import <sys/utsname.h> #import <sys/utsname.h>
@implementation SDL_DisplayData @implementation SDL_UIKitDisplayData
- (instancetype)initWithScreen:(UIScreen *)screen - (instancetype)initWithScreen:(UIScreen *)screen
{ {
@ -42,7 +42,7 @@
@end @end
@implementation SDL_DisplayModeData @implementation SDL_UIKitDisplayModeData
@synthesize uiscreenmode; @synthesize uiscreenmode;
@ -96,11 +96,11 @@
static int UIKit_AllocateDisplayModeData(SDL_DisplayMode *mode, static int UIKit_AllocateDisplayModeData(SDL_DisplayMode *mode,
UIScreenMode *uiscreenmode) UIScreenMode *uiscreenmode)
{ {
SDL_DisplayModeData *data = nil; SDL_UIKitDisplayModeData *data = nil;
if (uiscreenmode != nil) { if (uiscreenmode != nil) {
/* Allocate the display mode data */ /* Allocate the display mode data */
data = [[SDL_DisplayModeData alloc] init]; data = [[SDL_UIKitDisplayModeData alloc] init];
if (!data) { if (!data) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@ -223,13 +223,13 @@ int UIKit_AddDisplay(UIScreen *uiscreen, SDL_bool send_event)
display.desktop_mode = mode; display.desktop_mode = mode;
/* Allocate the display data */ /* Allocate the display data */
SDL_DisplayData *data = [[SDL_DisplayData alloc] initWithScreen:uiscreen]; SDL_UIKitDisplayData *data = [[SDL_UIKitDisplayData alloc] initWithScreen:uiscreen];
if (!data) { if (!data) {
UIKit_FreeDisplayModeData(&display.desktop_mode); UIKit_FreeDisplayModeData(&display.desktop_mode);
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
display.driverdata = data; display.driverdata = (SDL_DisplayData *)CFBridgingRetain(data);
if (SDL_AddVideoDisplay(&display, send_event) == 0) { if (SDL_AddVideoDisplay(&display, send_event) == 0) {
return -1; return -1;
} }
@ -245,10 +245,10 @@ void UIKit_DelDisplay(UIScreen *uiscreen)
if (displays) { if (displays) {
for (i = 0; displays[i]; ++i) { for (i = 0; displays[i]; ++i) {
SDL_VideoDisplay *display = SDL_GetVideoDisplay(displays[i]); SDL_VideoDisplay *display = SDL_GetVideoDisplay(displays[i]);
SDL_DisplayData *data = display->driverdata; SDL_UIKitDisplayData *data = (__bridge SDL_UIKitDisplayData *)display->driverdata;
if (data && data.uiscreen == uiscreen) { if (data && data.uiscreen == uiscreen) {
display->driverdata = nil; CFRelease(display->driverdata);
SDL_DelVideoDisplay(displays[i], SDL_FALSE); SDL_DelVideoDisplay(displays[i], SDL_FALSE);
break; break;
} }
@ -292,7 +292,7 @@ int UIKit_InitModes(_THIS)
int UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay *display) int UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
{ {
@autoreleasepool { @autoreleasepool {
SDL_DisplayData *data = display->driverdata; SDL_UIKitDisplayData *data = (__bridge SDL_UIKitDisplayData *)display->driverdata;
SDL_bool isLandscape = UIKit_IsDisplayLandscape(data.uiscreen); SDL_bool isLandscape = UIKit_IsDisplayLandscape(data.uiscreen);
SDL_bool addRotation = (data.uiscreen == [UIScreen mainScreen]); SDL_bool addRotation = (data.uiscreen == [UIScreen mainScreen]);
@ -326,10 +326,10 @@ int UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode) int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
{ {
@autoreleasepool { @autoreleasepool {
SDL_DisplayData *data = display->driverdata; SDL_UIKitDisplayData *data = (__bridge SDL_UIKitDisplayData *)display->driverdata;
#if !TARGET_OS_TV #if !TARGET_OS_TV
SDL_DisplayModeData *modedata = (__bridge SDL_DisplayModeData *)mode->driverdata; SDL_UIKitDisplayModeData *modedata = (__bridge SDL_UIKitDisplayModeData *)mode->driverdata;
[data.uiscreen setCurrentMode:modedata.uiscreenmode]; [data.uiscreen setCurrentMode:modedata.uiscreenmode];
#endif #endif
@ -355,7 +355,7 @@ int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode
int UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) int UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
{ {
@autoreleasepool { @autoreleasepool {
SDL_DisplayData *data = display->driverdata; SDL_UIKitDisplayData *data = (__bridge SDL_UIKitDisplayData *)display->driverdata;
CGRect frame = data.uiscreen.bounds; CGRect frame = data.uiscreen.bounds;
/* the default function iterates displays to make a fake offset, /* the default function iterates displays to make a fake offset,
@ -389,8 +389,9 @@ void UIKit_QuitModes(_THIS)
UIKit_FreeDisplayModeData(mode); UIKit_FreeDisplayModeData(mode);
} }
if (display->driverdata) { if (display->driverdata != NULL) {
display->driverdata = nil; CFRelease(display->driverdata);
display->driverdata = NULL;
} }
} }
} }

View File

@ -113,7 +113,7 @@ SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window *window)
@autoreleasepool { @autoreleasepool {
SDLEAGLContext *context = nil; SDLEAGLContext *context = nil;
SDL_uikitopenglview *view; SDL_uikitopenglview *view;
SDL_WindowData *data = window->driverdata; SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
CGRect frame = UIKit_ComputeViewFrame(window, data.uiwindow.screen); CGRect frame = UIKit_ComputeViewFrame(window, data.uiwindow.screen);
EAGLSharegroup *sharegroup = nil; EAGLSharegroup *sharegroup = nil;
CGFloat scale = 1.0; CGFloat scale = 1.0;

View File

@ -27,7 +27,7 @@
#include <UIKit/UIKit.h> #include <UIKit/UIKit.h>
@interface SDL_VideoData : NSObject @interface SDL_UIKitVideoData : NSObject
@property(nonatomic, assign) id pasteboardObserver; @property(nonatomic, assign) id pasteboardObserver;

View File

@ -39,7 +39,7 @@
#define UIKITVID_DRIVER_NAME "uikit" #define UIKITVID_DRIVER_NAME "uikit"
@implementation SDL_VideoData @implementation SDL_UIKitVideoData
@end @end
@ -52,7 +52,7 @@ static void UIKit_VideoQuit(_THIS);
static void UIKit_DeleteDevice(SDL_VideoDevice *device) static void UIKit_DeleteDevice(SDL_VideoDevice *device)
{ {
@autoreleasepool { @autoreleasepool {
device->driverdata = nil; CFRelease(device->driverdata);
SDL_free(device); SDL_free(device);
} }
} }
@ -61,19 +61,19 @@ static SDL_VideoDevice *UIKit_CreateDevice(void)
{ {
@autoreleasepool { @autoreleasepool {
SDL_VideoDevice *device; SDL_VideoDevice *device;
SDL_VideoData *data; SDL_UIKitVideoData *data;
/* Initialize all variables that we clean on shutdown */ /* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice));
if (device) { if (device) {
data = [SDL_VideoData new]; data = [SDL_UIKitVideoData new];
} else { } else {
SDL_free(device); SDL_free(device);
SDL_OutOfMemory(); SDL_OutOfMemory();
return (0); return (0);
} }
device->driverdata = data; device->driverdata = (SDL_VideoData *)CFBridgingRetain(data);
/* Set the function pointers */ /* Set the function pointers */
device->VideoInit = UIKit_VideoInit; device->VideoInit = UIKit_VideoInit;
@ -184,7 +184,7 @@ UIKit_IsSystemVersionAtLeast(double version)
CGRect CGRect
UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen) UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
{ {
SDL_WindowData *data = window->driverdata; SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
CGRect frame = screen.bounds; CGRect frame = screen.bounds;
/* Use the UIWindow bounds instead of the UIScreen bounds, when possible. /* Use the UIWindow bounds instead of the UIScreen bounds, when possible.
@ -225,7 +225,7 @@ void UIKit_ForceUpdateHomeIndicator()
/* Force the main SDL window to re-evaluate home indicator state */ /* Force the main SDL window to re-evaluate home indicator state */
SDL_Window *focus = SDL_GetFocusWindow(); SDL_Window *focus = SDL_GetFocusWindow();
if (focus) { if (focus) {
SDL_WindowData *data = focus->driverdata; SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)focus->driverdata;
if (data != nil) { if (data != nil) {
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability-new" #pragma clang diagnostic ignored "-Wunguarded-availability-new"

View File

@ -94,7 +94,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
- (void)setSDLWindow:(SDL_Window *)window - (void)setSDLWindow:(SDL_Window *)window
{ {
SDL_WindowData *data = nil; SDL_UIKitWindowData *data = nil;
if (window == sdlwindow) { if (window == sdlwindow) {
return; return;
@ -103,7 +103,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
/* Remove ourself from the old window. */ /* Remove ourself from the old window. */
if (sdlwindow) { if (sdlwindow) {
SDL_uikitview *view = nil; SDL_uikitview *view = nil;
data = sdlwindow->driverdata; data = (__bridge SDL_UIKitWindowData *)sdlwindow->driverdata;
[data.views removeObject:self]; [data.views removeObject:self];
@ -122,7 +122,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
/* Add ourself to the new window. */ /* Add ourself to the new window. */
if (window) { if (window) {
data = window->driverdata; data = (__bridge SDL_UIKitWindowData *)window->driverdata;
/* Make sure the SDL window has a strong reference to this view. */ /* Make sure the SDL window has a strong reference to this view. */
[data.views addObject:self]; [data.views addObject:self];

View File

@ -156,7 +156,7 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)]; displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
#ifdef __IPHONE_10_3 #ifdef __IPHONE_10_3
SDL_WindowData *data = window->driverdata; SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
if ([displayLink respondsToSelector:@selector(preferredFramesPerSecond)] && data != nil && data.uiwindow != nil && [data.uiwindow.screen respondsToSelector:@selector(maximumFramesPerSecond)]) { if ([displayLink respondsToSelector:@selector(preferredFramesPerSecond)] && data != nil && data.uiwindow != nil && [data.uiwindow.screen respondsToSelector:@selector(maximumFramesPerSecond)]) {
displayLink.preferredFramesPerSecond = data.uiwindow.screen.maximumFramesPerSecond / animationInterval; displayLink.preferredFramesPerSecond = data.uiwindow.screen.maximumFramesPerSecond / animationInterval;
@ -513,7 +513,7 @@ static SDL_uikitviewcontroller *GetWindowViewController(SDL_Window *window)
return nil; return nil;
} }
SDL_WindowData *data = window->driverdata; SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
return data.viewcontroller; return data.viewcontroller;
} }

View File

@ -43,7 +43,7 @@ extern NSUInteger UIKit_GetSupportedOrientations(SDL_Window *window);
@class UIWindow; @class UIWindow;
@interface SDL_WindowData : NSObject @interface SDL_UIKitWindowData : NSObject
@property(nonatomic, strong) UIWindow *uiwindow; @property(nonatomic, strong) UIWindow *uiwindow;
@property(nonatomic, strong) SDL_uikitviewcontroller *viewcontroller; @property(nonatomic, strong) SDL_uikitviewcontroller *viewcontroller;

View File

@ -38,7 +38,7 @@
#include <Foundation/Foundation.h> #include <Foundation/Foundation.h>
@implementation SDL_WindowData @implementation SDL_UIKitWindowData
@synthesize uiwindow; @synthesize uiwindow;
@synthesize viewcontroller; @synthesize viewcontroller;
@ -82,19 +82,19 @@
static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created) static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created)
{ {
SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window);
SDL_DisplayData *displaydata = display->driverdata; SDL_UIKitDisplayData *displaydata = (__bridge SDL_UIKitDisplayData *)display->driverdata;
SDL_uikitview *view; SDL_uikitview *view;
CGRect frame = UIKit_ComputeViewFrame(window, displaydata.uiscreen); CGRect frame = UIKit_ComputeViewFrame(window, displaydata.uiscreen);
int width = (int)frame.size.width; int width = (int)frame.size.width;
int height = (int)frame.size.height; int height = (int)frame.size.height;
SDL_WindowData *data = [[SDL_WindowData alloc] init]; SDL_UIKitWindowData *data = [[SDL_UIKitWindowData alloc] init];
if (!data) { if (!data) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
window->driverdata = data; window->driverdata = (SDL_WindowData *)CFBridgingRetain(data);
data.uiwindow = uiwindow; data.uiwindow = uiwindow;
@ -153,7 +153,7 @@ int UIKit_CreateWindow(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window);
SDL_DisplayData *data = display->driverdata; SDL_UIKitDisplayData *data = (__bridge SDL_UIKitDisplayData *)display->driverdata;
SDL_Window *other; SDL_Window *other;
/* We currently only handle a single window per display on iOS */ /* We currently only handle a single window per display on iOS */
@ -171,7 +171,7 @@ int UIKit_CreateWindow(_THIS, SDL_Window *window)
if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) { if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) {
const SDL_DisplayMode *bestmode = SDL_GetClosestFullscreenDisplayMode(display->id, window->w, window->h, 0.0f); const SDL_DisplayMode *bestmode = SDL_GetClosestFullscreenDisplayMode(display->id, window->w, window->h, 0.0f);
if (bestmode) { if (bestmode) {
SDL_DisplayModeData *modedata = (__bridge SDL_DisplayModeData *)bestmode->driverdata; SDL_UIKitDisplayModeData *modedata = (__bridge SDL_UIKitDisplayModeData *)bestmode->driverdata;
[data.uiscreen setCurrentMode:modedata.uiscreenmode]; [data.uiscreen setCurrentMode:modedata.uiscreenmode];
/* desktop_mode doesn't change here (the higher level will /* desktop_mode doesn't change here (the higher level will
@ -210,7 +210,7 @@ int UIKit_CreateWindow(_THIS, SDL_Window *window)
void UIKit_SetWindowTitle(_THIS, SDL_Window *window) void UIKit_SetWindowTitle(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
data.viewcontroller.title = @(window->title); data.viewcontroller.title = @(window->title);
} }
} }
@ -218,12 +218,12 @@ void UIKit_SetWindowTitle(_THIS, SDL_Window *window)
void UIKit_ShowWindow(_THIS, SDL_Window *window) void UIKit_ShowWindow(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
[data.uiwindow makeKeyAndVisible]; [data.uiwindow makeKeyAndVisible];
/* Make this window the current mouse focus for touch input */ /* Make this window the current mouse focus for touch input */
SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window);
SDL_DisplayData *displaydata = display->driverdata; SDL_UIKitDisplayData *displaydata = (__bridge SDL_UIKitDisplayData *)display->driverdata;
if (displaydata.uiscreen == [UIScreen mainScreen]) { if (displaydata.uiscreen == [UIScreen mainScreen]) {
SDL_SetMouseFocus(window); SDL_SetMouseFocus(window);
SDL_SetKeyboardFocus(window); SDL_SetKeyboardFocus(window);
@ -234,7 +234,7 @@ void UIKit_ShowWindow(_THIS, SDL_Window *window)
void UIKit_HideWindow(_THIS, SDL_Window *window) void UIKit_HideWindow(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
data.uiwindow.hidden = YES; data.uiwindow.hidden = YES;
} }
} }
@ -250,7 +250,7 @@ void UIKit_RaiseWindow(_THIS, SDL_Window *window)
static void UIKit_UpdateWindowBorder(_THIS, SDL_Window *window) static void UIKit_UpdateWindowBorder(_THIS, SDL_Window *window)
{ {
SDL_WindowData *data = window->driverdata; SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
SDL_uikitviewcontroller *viewcontroller = data.viewcontroller; SDL_uikitviewcontroller *viewcontroller = data.viewcontroller;
#if !TARGET_OS_TV #if !TARGET_OS_TV
@ -301,7 +301,7 @@ void UIKit_UpdatePointerLock(_THIS, SDL_Window *window)
#if !TARGET_OS_TV #if !TARGET_OS_TV
#if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0 #if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
SDL_uikitviewcontroller *viewcontroller = data.viewcontroller; SDL_uikitviewcontroller *viewcontroller = data.viewcontroller;
if (@available(iOS 14.0, *)) { if (@available(iOS 14.0, *)) {
[viewcontroller setNeedsUpdateOfPrefersPointerLocked]; [viewcontroller setNeedsUpdateOfPrefersPointerLocked];
@ -315,7 +315,7 @@ void UIKit_DestroyWindow(_THIS, SDL_Window *window)
{ {
@autoreleasepool { @autoreleasepool {
if (window->driverdata != NULL) { if (window->driverdata != NULL) {
SDL_WindowData *data = window->driverdata; SDL_UIKitWindowData *data = (SDL_UIKitWindowData *)CFBridgingRelease(window->driverdata);
NSArray *views = nil; NSArray *views = nil;
[data.viewcontroller stopAnimation]; [data.viewcontroller stopAnimation];
@ -335,7 +335,7 @@ void UIKit_DestroyWindow(_THIS, SDL_Window *window)
data.uiwindow.rootViewController = nil; data.uiwindow.rootViewController = nil;
data.uiwindow.hidden = YES; data.uiwindow.hidden = YES;
window->driverdata = nil; window->driverdata = NULL;
} }
} }
} }
@ -343,7 +343,7 @@ void UIKit_DestroyWindow(_THIS, SDL_Window *window)
void UIKit_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int *h) void UIKit_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int *h)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *windata = window->driverdata; SDL_UIKitWindowData *windata = (__bridge SDL_UIKitWindowData *)window->driverdata;
UIView *view = windata.viewcontroller.view; UIView *view = windata.viewcontroller.view;
CGSize size = view.bounds.size; CGSize size = view.bounds.size;
CGFloat scale = 1.0; CGFloat scale = 1.0;
@ -362,7 +362,7 @@ void UIKit_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int *h)
int UIKit_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info) int UIKit_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
{ {
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
info->subsystem = SDL_SYSWM_UIKIT; info->subsystem = SDL_SYSWM_UIKIT;
info->info.uikit.window = data.uiwindow; info->info.uikit.window = data.uiwindow;
@ -388,7 +388,7 @@ UIKit_GetSupportedOrientations(SDL_Window *window)
NSUInteger orientationMask = 0; NSUInteger orientationMask = 0;
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
UIApplication *app = [UIApplication sharedApplication]; UIApplication *app = [UIApplication sharedApplication];
/* Get all possible valid orientations. If the app delegate doesn't tell /* Get all possible valid orientations. If the app delegate doesn't tell
@ -454,7 +454,7 @@ int SDL_iPhoneSetAnimationCallback(SDL_Window *window, int interval, void (*call
} }
@autoreleasepool { @autoreleasepool {
SDL_WindowData *data = window->driverdata; SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
[data.viewcontroller setAnimationCallback:interval [data.viewcontroller setAnimationCallback:interval
callback:callback callback:callback
callbackParam:callbackParam]; callbackParam:callbackParam];