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_VideoDisplay SDL_VideoDisplay;
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_DisplayData SDL_DisplayData;
typedef struct SDL_DisplayModeData SDL_DisplayModeData;
typedef struct SDL_WindowData SDL_WindowData;
#endif /* SDL_VIDEO_DRIVER_COCOA || SDL_VIDEO_DRIVER_UIKIT */
/* Define the SDL window-shaper structure */
struct SDL_WindowShaper

View File

@ -24,11 +24,11 @@
#define SDL_cocoaclipboard_h_
/* Forward declaration */
@class SDL_VideoData;
@class SDL_CocoaVideoData;
extern int Cocoa_SetClipboardText(_THIS, const char *text);
extern char *Cocoa_GetClipboardText(_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_ */

View File

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

View File

@ -35,7 +35,7 @@ static SDL_Window *FindSDLWindowForNSWindow(NSWindow *win)
SDL_VideoDevice *device = SDL_GetVideoDevice();
if (device && device->windows) {
for (sdlwindow = device->windows; sdlwindow; sdlwindow = sdlwindow->next) {
NSWindow *nswindow = sdlwindow->driverdata.nswindow;
NSWindow *nswindow = ((__bridge SDL_CocoaWindowData *)sdlwindow->driverdata).nswindow;
if (win == nswindow) {
return sdlwindow;
}
@ -557,7 +557,7 @@ void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window)
location:NSMakePoint(0, 0)
modifierFlags:0
timestamp:0.0
windowNumber:window->driverdata.window_number
windowNumber:((__bridge SDL_CocoaWindowData *)window->driverdata).window_number
context:nil
subtype:0
data1:0
@ -570,7 +570,7 @@ void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window)
int Cocoa_SuspendScreenSaver(_THIS)
{
@autoreleasepool {
SDL_VideoData *data = _this->driverdata;
SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->driverdata;
if (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;
const void *chr_data;
@ -294,7 +294,7 @@ cleanup:
void Cocoa_InitKeyboard(_THIS)
{
SDL_VideoData *data = _this->driverdata;
SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->driverdata;
UpdateKeymap(data, SDL_FALSE);
@ -314,11 +314,11 @@ void Cocoa_StartTextInput(_THIS)
{
@autoreleasepool {
NSView *parentView;
SDL_VideoData *data = _this->driverdata;
SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->driverdata;
SDL_Window *window = SDL_GetKeyboardFocus();
NSWindow *nswindow = nil;
if (window) {
nswindow = window->driverdata.nswindow;
nswindow = ((__bridge SDL_CocoaWindowData *)window->driverdata).nswindow;
}
parentView = [nswindow contentView];
@ -345,7 +345,7 @@ void Cocoa_StartTextInput(_THIS)
void Cocoa_StopTextInput(_THIS)
{
@autoreleasepool {
SDL_VideoData *data = _this->driverdata;
SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->driverdata;
if (data && data.fieldEdit) {
[data.fieldEdit removeFromSuperview];
@ -356,7 +356,7 @@ void Cocoa_StopTextInput(_THIS)
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];
return 0;
}
@ -365,7 +365,7 @@ void Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
{
unsigned short scancode;
SDL_Scancode code;
SDL_VideoData *data = _this ? _this->driverdata : nil;
SDL_CocoaVideoData *data = _this ? ((__bridge SDL_CocoaVideoData *)_this->driverdata) : nil;
if (!data) {
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 */
if (window) {
nswindow = window->driverdata.nswindow;
nswindow = ((__bridge SDL_CocoaWindowData *)window->driverdata).nswindow;
} else {
nswindow = nil;
}

View File

@ -133,7 +133,7 @@ SDL_MetalView
Cocoa_Metal_CreateView(_THIS, SDL_Window *window)
{
@autoreleasepool {
SDL_WindowData *data = window->driverdata;
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSView *view = data.nswindow.contentView;
BOOL highDPI = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
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)
{
SDL_DisplayData *displaydata = display->driverdata;
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
CGRect cgrect;
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)
{
SDL_DisplayData *displaydata = display->driverdata;
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
const CGDirectDisplayID cgdisplay = displaydata->display;
NSArray *screens = [NSScreen screens];
NSScreen *screen = nil;
@ -408,7 +408,7 @@ int Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rec
int Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
{
SDL_DisplayData *data = display->driverdata;
SDL_DisplayData *data = (SDL_DisplayData *)display->driverdata;
CVDisplayLinkRef link = NULL;
CFArrayRef modes;
CFDictionaryRef dict = NULL;
@ -485,7 +485,7 @@ static CGError SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayMo
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;
CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;
CGError result;

View File

@ -253,7 +253,7 @@ static int Cocoa_WarpMouseGlobal(float x, float y)
CGPoint point;
SDL_Mouse *mouse = SDL_GetMouse();
if (mouse->focus) {
SDL_WindowData *data = mouse->focus->driverdata;
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)mouse->focus->driverdata;
if ([data.listener isMovingOrFocusClickPending]) {
DLog("Postponing warp, window being moved or focused.");
[data.listener setPendingMoveX:x Y:y];
@ -298,7 +298,7 @@ static int Cocoa_SetRelativeMouseMode(SDL_bool enabled)
{
CGError result;
SDL_Window *window;
SDL_WindowData *data;
SDL_CocoaWindowData *data;
if (enabled) {
DLog("Turning on.");
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,
* if it is being moved right now.
*/
data = window->driverdata;
data = (__bridge SDL_CocoaWindowData *)window->driverdata;
if ([data.listener isMovingOrFocusClickPending]) {
return 0;
}
@ -402,7 +402,7 @@ static void Cocoa_HandleTitleButtonEvent(_THIS, NSEvent *event)
}
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) {
switch ([event type]) {
case NSEventTypeLeftMouseDown:

View File

@ -138,7 +138,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
- (void)setWindow:(SDL_Window *)newWindow
{
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. */
NSMutableArray *contexts = oldwindowdata.nscontexts;
@ -150,7 +150,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
self->window = newWindow;
if (newWindow) {
SDL_WindowData *windowdata = newWindow->driverdata;
SDL_CocoaWindowData *windowdata = (__bridge SDL_CocoaWindowData *)newWindow->driverdata;
NSView *contentview = windowdata.sdlContentView;
/* Now sign up for scheduled updates for the new window. */
@ -254,7 +254,7 @@ SDL_GLContext Cocoa_GL_CreateContext(_THIS, SDL_Window *window)
{
@autoreleasepool {
SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window);
SDL_DisplayData *displaydata = display->driverdata;
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
NSOpenGLPixelFormatAttribute attr[32];
NSOpenGLPixelFormat *fmt;
SDLOpenGLContext *context;
@ -482,7 +482,7 @@ int Cocoa_GL_SwapWindow(_THIS, SDL_Window *window)
{
@autoreleasepool {
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);
if (setting == 0) {

View File

@ -62,7 +62,7 @@ Cocoa_GLES_CreateContext(_THIS, SDL_Window *window)
{
@autoreleasepool {
SDL_GLContext context;
SDL_WindowData *data = window->driverdata;
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
#if SDL_VIDEO_OPENGL_CGL
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)
{
@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)
{
@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 {
NSView *v;
/* 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_GLContext current_ctx = SDL_GL_GetCurrentContext();
@ -151,7 +151,7 @@ SDL_EGLSurface
Cocoa_GLES_GetEGLSurface(_THIS, SDL_Window *window)
{
@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_ShapeData *data;
int resized_properly;
SDL_WindowData *windata = window->driverdata;
SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->driverdata;
result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper));
if (!result) {
@ -90,7 +90,7 @@ int Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_Windo
{
@autoreleasepool {
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;
if (data.saved == SDL_TRUE) {
[data.context restoreGraphicsState];

View File

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

View File

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

View File

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

View File

@ -29,7 +29,7 @@
#include "../SDL_egl_c.h"
#endif
@class SDL_WindowData;
@class SDL_CocoaWindowData;
typedef enum
{
@ -41,10 +41,10 @@ typedef enum
@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
* unretained ref to the WindowData. */
__weak SDL_WindowData *_data;
__weak SDL_CocoaWindowData *_data;
BOOL observingVisible;
BOOL wasCtrlLeft;
BOOL wasVisible;
@ -58,7 +58,7 @@ typedef enum
}
- (BOOL)isTouchFromTrackpad:(NSEvent *)theEvent;
- (void)listen:(SDL_WindowData *)data;
- (void)listen:(SDL_CocoaWindowData *)data;
- (void)pauseVisibleObservation;
- (void)resumeVisibleObservation;
- (BOOL)setFullscreenSpace:(BOOL)state;
@ -120,9 +120,9 @@ typedef enum
/* *INDENT-ON* */
@class SDLOpenGLContext;
@class SDL_VideoData;
@class SDL_CocoaVideoData;
@interface SDL_WindowData : NSObject
@interface SDL_CocoaWindowData : NSObject
@property(nonatomic) SDL_Window *window;
@property(nonatomic) NSWindow *nswindow;
@property(nonatomic) NSView *sdlContentView;
@ -132,7 +132,7 @@ typedef enum
@property(nonatomic) NSInteger window_number;
@property(nonatomic) NSInteger flash_request;
@property(nonatomic) Cocoa_WindowListener *listener;
@property(nonatomic) SDL_VideoData *videodata;
@property(nonatomic) SDL_CocoaVideoData *videodata;
#if SDL_VIDEO_OPENGL_EGL
@property(nonatomic) EGLSurface egl_surface;
#endif

View File

@ -63,7 +63,7 @@
#define NSAppKitVersionNumber10_14 1671
#endif
@implementation SDL_WindowData
@implementation SDL_CocoaWindowData
@end
@ -239,7 +239,7 @@
/* !!! FIXME: is there a better way to do this? */
if (_this) {
for (sdlwindow = _this->windows; sdlwindow; sdlwindow = sdlwindow->next) {
NSWindow *nswindow = sdlwindow->driverdata.nswindow;
NSWindow *nswindow = ((__bridge SDL_CocoaWindowData *)sdlwindow->driverdata).nswindow;
if (nswindow == self) {
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;
}
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. */
#if SDL_VIDEO_OPENGL
@ -333,7 +333,7 @@ static NSUInteger GetWindowStyle(SDL_Window *window)
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;
/* 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)
{
SDL_WindowData *data = window->driverdata;
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
if (!data || [data.listener isMovingOrFocusClickPending]) {
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)
{
SDL_WindowData *data = window->driverdata;
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_13_2) {
NSWindow *nswindow = data.nswindow;
@ -463,7 +463,7 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
@implementation Cocoa_WindowListener
- (void)listen:(SDL_WindowData *)data
- (void)listen:(SDL_CocoaWindowData *)data
{
NSNotificationCenter *center;
NSWindow *window = data.nswindow;
@ -564,7 +564,7 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
{
SDL_Window *window = _data.window;
NSWindow *nswindow = _data.nswindow;
SDL_VideoData *videodata = window->driverdata.videodata;
SDL_CocoaVideoData *videodata = ((__bridge SDL_CocoaWindowData *)window->driverdata).videodata;
if (!videodata.allow_spaces) {
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
// event for the background window, this just makes sure the button is reported at the
// 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);
} else {
const int orig_x = mouse->x;
@ -1384,7 +1384,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
- (BOOL)isTouchFromTrackpad:(NSEvent *)theEvent
{
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
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
only gets called for window creation and other extraordinary events. */
self.layer.backgroundColor = CGColorGetConstantColor(kCGColorBlack);
ScheduleContextUpdates(_sdlWindow->driverdata);
ScheduleContextUpdates((__bridge SDL_CocoaWindowData *)_sdlWindow->driverdata);
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)
{
@autoreleasepool {
SDL_VideoData *videodata = _this->driverdata;
SDL_WindowData *data;
SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->driverdata;
SDL_CocoaWindowData *data;
/* Allocate the window data */
data = [[SDL_WindowData alloc] init];
data = [[SDL_CocoaWindowData alloc] init];
if (!data) {
return SDL_OutOfMemory();
}
@ -1679,7 +1679,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, NSWindow *nswindow, NSView
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
* NSWindow, so the extra release provided by releasedWhenClosed isn't
* necessary. */
@ -1691,7 +1691,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, NSWindow *nswindow, NSView
[nswindow setOneShot:NO];
/* All done! */
window->driverdata = data;
window->driverdata = (SDL_WindowData *)CFBridgingRetain(data);
return 0;
}
}
@ -1699,7 +1699,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, NSWindow *nswindow, NSView
int Cocoa_CreateWindow(_THIS, SDL_Window *window)
{
@autoreleasepool {
SDL_VideoData *videodata = _this->driverdata;
SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->driverdata;
NSWindow *nswindow;
SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window);
NSRect rect;
@ -1868,7 +1868,7 @@ void Cocoa_SetWindowTitle(_THIS, SDL_Window *window)
{
@autoreleasepool {
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];
[nswindow setTitle:string];
}
@ -1892,7 +1892,7 @@ int Cocoa_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon)
void Cocoa_SetWindowPosition(_THIS, SDL_Window *window)
{
@autoreleasepool {
SDL_WindowData *windata = window->driverdata;
SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSWindow *nswindow = windata.nswindow;
NSRect rect;
BOOL fullscreen;
@ -1917,7 +1917,7 @@ void Cocoa_SetWindowPosition(_THIS, SDL_Window *window)
void Cocoa_SetWindowSize(_THIS, SDL_Window *window)
{
@autoreleasepool {
SDL_WindowData *windata = window->driverdata;
SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSWindow *nswindow = windata.nswindow;
NSRect rect;
BOOL fullscreen;
@ -1946,7 +1946,7 @@ void Cocoa_SetWindowSize(_THIS, SDL_Window *window)
void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window *window)
{
@autoreleasepool {
SDL_WindowData *windata = window->driverdata;
SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSSize minSize;
minSize.width = window->min_w;
@ -1959,7 +1959,7 @@ void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window *window)
void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window *window)
{
@autoreleasepool {
SDL_WindowData *windata = window->driverdata;
SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSSize maxSize;
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)
{
@autoreleasepool {
SDL_WindowData *windata = window->driverdata;
SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSView *contentView = windata.sdlContentView;
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)
{
@autoreleasepool {
SDL_WindowData *windowData = window->driverdata;
SDL_CocoaWindowData *windowData = ((__bridge SDL_CocoaWindowData *)window->driverdata);
NSWindow *nswindow = windowData.nswindow;
if (![nswindow isMiniaturized]) {
@ -2003,7 +2003,7 @@ void Cocoa_ShowWindow(_THIS, SDL_Window *window)
void Cocoa_HideWindow(_THIS, SDL_Window *window)
{
@autoreleasepool {
NSWindow *nswindow = window->driverdata.nswindow;
NSWindow *nswindow = ((__bridge SDL_CocoaWindowData *)window->driverdata).nswindow;
[nswindow orderOut:nil];
}
@ -2012,7 +2012,7 @@ void Cocoa_HideWindow(_THIS, SDL_Window *window)
void Cocoa_RaiseWindow(_THIS, SDL_Window *window)
{
@autoreleasepool {
SDL_WindowData *windowData = window->driverdata;
SDL_CocoaWindowData *windowData = ((__bridge SDL_CocoaWindowData *)window->driverdata);
NSWindow *nswindow = windowData.nswindow;
/* 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)
{
@autoreleasepool {
SDL_WindowData *windata = window->driverdata;
SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSWindow *nswindow = windata.nswindow;
[nswindow zoom:nil];
@ -2042,7 +2042,7 @@ void Cocoa_MaximizeWindow(_THIS, SDL_Window *window)
void Cocoa_MinimizeWindow(_THIS, SDL_Window *window)
{
@autoreleasepool {
SDL_WindowData *data = window->driverdata;
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSWindow *nswindow = data.nswindow;
if ([data.listener isInFullscreenSpaceTransition]) {
[data.listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
@ -2055,7 +2055,7 @@ void Cocoa_MinimizeWindow(_THIS, SDL_Window *window)
void Cocoa_RestoreWindow(_THIS, SDL_Window *window)
{
@autoreleasepool {
NSWindow *nswindow = window->driverdata.nswindow;
NSWindow *nswindow = ((__bridge SDL_CocoaWindowData *)window->driverdata).nswindow;
if ([nswindow isMiniaturized]) {
[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.
* -flibit
*/
SDL_WindowData *data = window->driverdata;
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
Cocoa_WindowListener *listener = data.listener;
NSWindow *nswindow = data.nswindow;
SDL_VideoData *videodata = data.videodata;
SDL_CocoaVideoData *videodata = data.videodata;
if (![listener isInFullscreenSpace]) {
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)
{
@autoreleasepool {
NSWindow *nswindow = window->driverdata.nswindow;
NSWindow *nswindow = ((__bridge SDL_CocoaWindowData *)window->driverdata).nswindow;
if (on_top) {
[nswindow setLevel:NSFloatingWindowLevel];
} 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)
{
@autoreleasepool {
SDL_WindowData *data = window->driverdata;
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSWindow *nswindow = data.nswindow;
NSRect rect;
@ -2206,7 +2206,7 @@ void *
Cocoa_GetWindowICCProfile(_THIS, SDL_Window *window, size_t *size)
{
@autoreleasepool {
SDL_WindowData *data = window->driverdata;
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
NSWindow *nswindow = data.nswindow;
NSScreen *screen = [nswindow screen];
NSData *iccProfileData = nil;
@ -2244,7 +2244,7 @@ SDL_DisplayID Cocoa_GetDisplayForWindow(_THIS, SDL_Window *window)
{
@autoreleasepool {
NSScreen *screen;
SDL_WindowData *data = window->driverdata;
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
/* Not recognized via CHECK_WINDOW_MAGIC */
if (data == nil) {
@ -2284,7 +2284,7 @@ void Cocoa_SetWindowMouseRect(_THIS, SDL_Window *window)
void Cocoa_SetWindowMouseGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
{
@autoreleasepool {
SDL_WindowData *data = window->driverdata;
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
Cocoa_UpdateClipCursor(window);
@ -2305,7 +2305,7 @@ void Cocoa_SetWindowMouseGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
void Cocoa_DestroyWindow(_THIS, SDL_Window *window)
{
@autoreleasepool {
SDL_WindowData *data = window->driverdata;
SDL_CocoaWindowData *data = (SDL_CocoaWindowData *)CFBridgingRelease(window->driverdata);
if (data) {
#if SDL_VIDEO_OPENGL
@ -2341,14 +2341,14 @@ void Cocoa_DestroyWindow(_THIS, SDL_Window *window)
window->shaper = NULL;
}
}
window->driverdata = nil;
window->driverdata = NULL;
}
}
int Cocoa_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
{
@autoreleasepool {
NSWindow *nswindow = window->driverdata.nswindow;
NSWindow *nswindow = ((__bridge SDL_CocoaWindowData *)window->driverdata).nswindow;
info->subsystem = SDL_SYSWM_COCOA;
info->info.cocoa.window = nswindow;
@ -2360,7 +2360,7 @@ SDL_bool
Cocoa_IsWindowInFullscreenSpace(SDL_Window *window)
{
@autoreleasepool {
SDL_WindowData *data = window->driverdata;
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
if ([data.listener isInFullscreenSpace]) {
return SDL_TRUE;
@ -2375,7 +2375,7 @@ Cocoa_SetWindowFullscreenSpace(SDL_Window *window, SDL_bool state)
{
@autoreleasepool {
SDL_bool succeeded = SDL_FALSE;
SDL_WindowData *data = window->driverdata;
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
if (data.inWindowFullscreenTransition) {
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)
{
@autoreleasepool {
SDL_WindowData *data = window->driverdata;
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
if (accept) {
[data.nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
} else {
@ -2437,7 +2437,7 @@ int Cocoa_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation)
{
@autoreleasepool {
/* 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) {
[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)
{
@autoreleasepool {
SDL_WindowData *data = window->driverdata;
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->driverdata;
[data.nswindow setAlphaValue:opacity];
return 0;
}

View File

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

View File

@ -468,7 +468,7 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
if (_this) {
SDL_Window *window = NULL;
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) {
return data.uiwindow;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -94,7 +94,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
- (void)setSDLWindow:(SDL_Window *)window
{
SDL_WindowData *data = nil;
SDL_UIKitWindowData *data = nil;
if (window == sdlwindow) {
return;
@ -103,7 +103,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
/* Remove ourself from the old window. */
if (sdlwindow) {
SDL_uikitview *view = nil;
data = sdlwindow->driverdata;
data = (__bridge SDL_UIKitWindowData *)sdlwindow->driverdata;
[data.views removeObject:self];
@ -122,7 +122,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
/* Add ourself to the new window. */
if (window) {
data = window->driverdata;
data = (__bridge SDL_UIKitWindowData *)window->driverdata;
/* Make sure the SDL window has a strong reference to this view. */
[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:)];
#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)]) {
displayLink.preferredFramesPerSecond = data.uiwindow.screen.maximumFramesPerSecond / animationInterval;
@ -513,7 +513,7 @@ static SDL_uikitviewcontroller *GetWindowViewController(SDL_Window *window)
return nil;
}
SDL_WindowData *data = window->driverdata;
SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
return data.viewcontroller;
}

View File

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

View File

@ -38,7 +38,7 @@
#include <Foundation/Foundation.h>
@implementation SDL_WindowData
@implementation SDL_UIKitWindowData
@synthesize uiwindow;
@synthesize viewcontroller;
@ -82,19 +82,19 @@
static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created)
{
SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window);
SDL_DisplayData *displaydata = display->driverdata;
SDL_UIKitDisplayData *displaydata = (__bridge SDL_UIKitDisplayData *)display->driverdata;
SDL_uikitview *view;
CGRect frame = UIKit_ComputeViewFrame(window, displaydata.uiscreen);
int width = (int)frame.size.width;
int height = (int)frame.size.height;
SDL_WindowData *data = [[SDL_WindowData alloc] init];
SDL_UIKitWindowData *data = [[SDL_UIKitWindowData alloc] init];
if (!data) {
return SDL_OutOfMemory();
}
window->driverdata = data;
window->driverdata = (SDL_WindowData *)CFBridgingRetain(data);
data.uiwindow = uiwindow;
@ -153,7 +153,7 @@ int UIKit_CreateWindow(_THIS, SDL_Window *window)
{
@autoreleasepool {
SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window);
SDL_DisplayData *data = display->driverdata;
SDL_UIKitDisplayData *data = (__bridge SDL_UIKitDisplayData *)display->driverdata;
SDL_Window *other;
/* 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)) {
const SDL_DisplayMode *bestmode = SDL_GetClosestFullscreenDisplayMode(display->id, window->w, window->h, 0.0f);
if (bestmode) {
SDL_DisplayModeData *modedata = (__bridge SDL_DisplayModeData *)bestmode->driverdata;
SDL_UIKitDisplayModeData *modedata = (__bridge SDL_UIKitDisplayModeData *)bestmode->driverdata;
[data.uiscreen setCurrentMode:modedata.uiscreenmode];
/* 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)
{
@autoreleasepool {
SDL_WindowData *data = window->driverdata;
SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
data.viewcontroller.title = @(window->title);
}
}
@ -218,12 +218,12 @@ void UIKit_SetWindowTitle(_THIS, SDL_Window *window)
void UIKit_ShowWindow(_THIS, SDL_Window *window)
{
@autoreleasepool {
SDL_WindowData *data = window->driverdata;
SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
[data.uiwindow makeKeyAndVisible];
/* Make this window the current mouse focus for touch input */
SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window);
SDL_DisplayData *displaydata = display->driverdata;
SDL_UIKitDisplayData *displaydata = (__bridge SDL_UIKitDisplayData *)display->driverdata;
if (displaydata.uiscreen == [UIScreen mainScreen]) {
SDL_SetMouseFocus(window);
SDL_SetKeyboardFocus(window);
@ -234,7 +234,7 @@ void UIKit_ShowWindow(_THIS, SDL_Window *window)
void UIKit_HideWindow(_THIS, SDL_Window *window)
{
@autoreleasepool {
SDL_WindowData *data = window->driverdata;
SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
data.uiwindow.hidden = YES;
}
}
@ -250,7 +250,7 @@ void UIKit_RaiseWindow(_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;
#if !TARGET_OS_TV
@ -301,7 +301,7 @@ void UIKit_UpdatePointerLock(_THIS, SDL_Window *window)
#if !TARGET_OS_TV
#if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
@autoreleasepool {
SDL_WindowData *data = window->driverdata;
SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
SDL_uikitviewcontroller *viewcontroller = data.viewcontroller;
if (@available(iOS 14.0, *)) {
[viewcontroller setNeedsUpdateOfPrefersPointerLocked];
@ -315,7 +315,7 @@ void UIKit_DestroyWindow(_THIS, SDL_Window *window)
{
@autoreleasepool {
if (window->driverdata != NULL) {
SDL_WindowData *data = window->driverdata;
SDL_UIKitWindowData *data = (SDL_UIKitWindowData *)CFBridgingRelease(window->driverdata);
NSArray *views = nil;
[data.viewcontroller stopAnimation];
@ -335,7 +335,7 @@ void UIKit_DestroyWindow(_THIS, SDL_Window *window)
data.uiwindow.rootViewController = nil;
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)
{
@autoreleasepool {
SDL_WindowData *windata = window->driverdata;
SDL_UIKitWindowData *windata = (__bridge SDL_UIKitWindowData *)window->driverdata;
UIView *view = windata.viewcontroller.view;
CGSize size = view.bounds.size;
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)
{
@autoreleasepool {
SDL_WindowData *data = window->driverdata;
SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
info->subsystem = SDL_SYSWM_UIKIT;
info->info.uikit.window = data.uiwindow;
@ -388,7 +388,7 @@ UIKit_GetSupportedOrientations(SDL_Window *window)
NSUInteger orientationMask = 0;
@autoreleasepool {
SDL_WindowData *data = window->driverdata;
SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
UIApplication *app = [UIApplication sharedApplication];
/* 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 {
SDL_WindowData *data = window->driverdata;
SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
[data.viewcontroller setAnimationCallback:interval
callback:callback
callbackParam:callbackParam];