mirror of
https://github.com/encounter/SDL.git
synced 2025-12-21 10:49:12 +00:00
Fix C89 declaration for macOS modules.
Since Clang 14, `-Wdeclaration-after-statement` is enforced on every standard.
This commit is contained in:
committed by
Sam Lantinga
parent
e4a8087551
commit
6c536afdb7
@@ -229,6 +229,7 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
|
||||
|
||||
- (void)focusSomeWindow:(NSNotification *)aNotification
|
||||
{
|
||||
SDL_VideoDevice *device;
|
||||
/* HACK: Ignore the first call. The application gets a
|
||||
* applicationDidBecomeActive: a little bit after the first window is
|
||||
* created, and if we don't ignore it, a window that has been created with
|
||||
@@ -246,7 +247,7 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_VideoDevice *device = SDL_GetVideoDevice();
|
||||
device = SDL_GetVideoDevice();
|
||||
if (device && device->windows) {
|
||||
SDL_Window *window = device->windows;
|
||||
int i;
|
||||
|
||||
@@ -390,6 +390,7 @@ UpdateKeymap(SDL_VideoData *data, SDL_bool send_event)
|
||||
int i;
|
||||
SDL_Scancode scancode;
|
||||
SDL_Keycode keymap[SDL_NUM_SCANCODES];
|
||||
CFDataRef uchrDataRef;
|
||||
|
||||
/* See if the keymap needs to be updated */
|
||||
key_layout = TISCopyCurrentKeyboardLayoutInputSource();
|
||||
@@ -401,7 +402,7 @@ UpdateKeymap(SDL_VideoData *data, SDL_bool send_event)
|
||||
SDL_GetDefaultKeymap(keymap);
|
||||
|
||||
/* Try Unicode data first */
|
||||
CFDataRef uchrDataRef = TISGetInputSourceProperty(key_layout, kTISPropertyUnicodeKeyLayoutData);
|
||||
uchrDataRef = TISGetInputSourceProperty(key_layout, kTISPropertyUnicodeKeyLayoutData);
|
||||
if (uchrDataRef) {
|
||||
chr_data = CFDataGetBytePtr(uchrDataRef);
|
||||
} else {
|
||||
@@ -472,6 +473,7 @@ void
|
||||
Cocoa_StartTextInput(_THIS)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSView *parentView;
|
||||
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
|
||||
SDL_Window *window = SDL_GetKeyboardFocus();
|
||||
NSWindow *nswindow = nil;
|
||||
@@ -479,7 +481,7 @@ Cocoa_StartTextInput(_THIS)
|
||||
nswindow = ((__bridge SDL_WindowData*)window->driverdata).nswindow;
|
||||
}
|
||||
|
||||
NSView *parentView = [nswindow contentView];
|
||||
parentView = [nswindow contentView];
|
||||
|
||||
/* We only keep one field editor per process, since only the front most
|
||||
* window can receive text input events, so it make no sense to keep more
|
||||
@@ -527,13 +529,14 @@ Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect)
|
||||
void
|
||||
Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
|
||||
{
|
||||
unsigned short scancode;
|
||||
SDL_Scancode code;
|
||||
SDL_VideoData *data = _this ? ((__bridge SDL_VideoData *) _this->driverdata) : nil;
|
||||
if (!data) {
|
||||
return; /* can happen when returning from fullscreen Space on shutdown */
|
||||
}
|
||||
|
||||
unsigned short scancode = [event keyCode];
|
||||
SDL_Scancode code;
|
||||
scancode = [event keyCode];
|
||||
#if 0
|
||||
const char *text;
|
||||
#endif
|
||||
|
||||
@@ -92,9 +92,14 @@
|
||||
static void
|
||||
Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid, int *returnValue)
|
||||
{
|
||||
NSAlert* alert;
|
||||
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
|
||||
SDLMessageBoxPresenter* presenter;
|
||||
NSInteger clicked;
|
||||
int i;
|
||||
Cocoa_RegisterApp();
|
||||
|
||||
NSAlert* alert = [[NSAlert alloc] init];
|
||||
alert = [[NSAlert alloc] init];
|
||||
|
||||
if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
|
||||
[alert setAlertStyle:NSAlertStyleCritical];
|
||||
@@ -107,8 +112,6 @@ Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid
|
||||
[alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
|
||||
[alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
|
||||
|
||||
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
|
||||
int i;
|
||||
for (i = 0; i < messageboxdata->numbuttons; ++i) {
|
||||
const SDL_MessageBoxButtonData *sdlButton;
|
||||
NSButton *button;
|
||||
@@ -129,11 +132,11 @@ Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid
|
||||
}
|
||||
}
|
||||
|
||||
SDLMessageBoxPresenter* presenter = [[SDLMessageBoxPresenter alloc] initWithParentWindow:messageboxdata->window];
|
||||
presenter = [[SDLMessageBoxPresenter alloc] initWithParentWindow:messageboxdata->window];
|
||||
|
||||
[presenter showAlert:alert];
|
||||
|
||||
NSInteger clicked = presenter->clicked;
|
||||
clicked = presenter->clicked;
|
||||
if (clicked >= NSAlertFirstButtonReturn) {
|
||||
clicked -= NSAlertFirstButtonReturn;
|
||||
if (messageboxdata->flags & SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT) {
|
||||
|
||||
@@ -185,6 +185,9 @@ GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmodeCurrent, CFArray
|
||||
int i;
|
||||
|
||||
for (i = 0; i < modescount; i++) {
|
||||
int otherW, otherH, otherpixelW, otherpixelH, otherrefresh;
|
||||
Uint32 otherformat;
|
||||
bool otherGUI;
|
||||
CGDisplayModeRef othermode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modelist, i);
|
||||
uint32_t otherioflags = CGDisplayModeGetIOFlags(othermode);
|
||||
|
||||
@@ -196,13 +199,13 @@ GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmodeCurrent, CFArray
|
||||
continue;
|
||||
}
|
||||
|
||||
int otherW = (int) CGDisplayModeGetWidth(othermode);
|
||||
int otherH = (int) CGDisplayModeGetHeight(othermode);
|
||||
int otherpixelW = (int) CGDisplayModeGetPixelWidth(othermode);
|
||||
int otherpixelH = (int) CGDisplayModeGetPixelHeight(othermode);
|
||||
int otherrefresh = GetDisplayModeRefreshRate(othermode, link);
|
||||
Uint32 otherformat = GetDisplayModePixelFormat(othermode);
|
||||
bool otherGUI = CGDisplayModeIsUsableForDesktopGUI(othermode);
|
||||
otherW = (int) CGDisplayModeGetWidth(othermode);
|
||||
otherH = (int) CGDisplayModeGetHeight(othermode);
|
||||
otherpixelW = (int) CGDisplayModeGetPixelWidth(othermode);
|
||||
otherpixelH = (int) CGDisplayModeGetPixelHeight(othermode);
|
||||
otherrefresh = GetDisplayModeRefreshRate(othermode, link);
|
||||
otherformat = GetDisplayModePixelFormat(othermode);
|
||||
otherGUI = CGDisplayModeIsUsableForDesktopGUI(othermode);
|
||||
|
||||
/* Ignore this mode if it's low-dpi (@1x) and we have a high-dpi
|
||||
* mode in the list with the same size in points.
|
||||
@@ -417,11 +420,13 @@ Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
|
||||
return -1;
|
||||
}
|
||||
|
||||
const NSRect frame = [screen visibleFrame];
|
||||
rect->x = (int)frame.origin.x;
|
||||
rect->y = (int)(CGDisplayPixelsHigh(kCGDirectMainDisplay) - frame.origin.y - frame.size.height);
|
||||
rect->w = (int)frame.size.width;
|
||||
rect->h = (int)frame.size.height;
|
||||
{
|
||||
const NSRect frame = [screen visibleFrame];
|
||||
rect->x = (int)frame.origin.x;
|
||||
rect->y = (int)(CGDisplayPixelsHigh(kCGDirectMainDisplay) - frame.origin.y - frame.size.height);
|
||||
rect->w = (int)frame.size.width;
|
||||
rect->h = (int)frame.size.height;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -487,20 +492,21 @@ Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdp
|
||||
}
|
||||
}
|
||||
|
||||
const CGSize displaySize = CGDisplayScreenSize(data->display);
|
||||
const int pixelWidth = displayNativeSize.width;
|
||||
const int pixelHeight = displayNativeSize.height;
|
||||
{
|
||||
const CGSize displaySize = CGDisplayScreenSize(data->display);
|
||||
const int pixelWidth = displayNativeSize.width;
|
||||
const int pixelHeight = displayNativeSize.height;
|
||||
|
||||
if (ddpi) {
|
||||
*ddpi = (SDL_ComputeDiagonalDPI(pixelWidth, pixelHeight, displaySize.width / MM_IN_INCH, displaySize.height / MM_IN_INCH));
|
||||
if (ddpi) {
|
||||
*ddpi = (SDL_ComputeDiagonalDPI(pixelWidth, pixelHeight, displaySize.width / MM_IN_INCH, displaySize.height / MM_IN_INCH));
|
||||
}
|
||||
if (hdpi) {
|
||||
*hdpi = (pixelWidth * MM_IN_INCH / displaySize.width);
|
||||
}
|
||||
if (vdpi) {
|
||||
*vdpi = (pixelHeight * MM_IN_INCH / displaySize.height);
|
||||
}
|
||||
}
|
||||
if (hdpi) {
|
||||
*hdpi = (pixelWidth * MM_IN_INCH / displaySize.width);
|
||||
}
|
||||
if (vdpi) {
|
||||
*vdpi = (pixelHeight * MM_IN_INCH / displaySize.height);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}}
|
||||
|
||||
|
||||
@@ -112,35 +112,37 @@ static NSCursor *
|
||||
LoadHiddenSystemCursor(NSString *cursorName, SEL fallback)
|
||||
{
|
||||
NSString *cursorPath = [@"/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/Resources/cursors" stringByAppendingPathComponent:cursorName];
|
||||
NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[cursorPath stringByAppendingPathComponent:@"info.plist"]];
|
||||
/* we can't do animation atm. :/ */
|
||||
const int frames = [[info valueForKey:@"frames"] integerValue];
|
||||
NSCursor *cursor;
|
||||
NSImage *image = [[NSImage alloc] initWithContentsOfFile:[cursorPath stringByAppendingPathComponent:@"cursor.pdf"]];
|
||||
if ((image == nil) || (image.valid == NO)) {
|
||||
return [NSCursor performSelector:fallback];
|
||||
}
|
||||
|
||||
NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[cursorPath stringByAppendingPathComponent:@"info.plist"]];
|
||||
|
||||
/* we can't do animation atm. :/ */
|
||||
const int frames = [[info valueForKey:@"frames"] integerValue];
|
||||
if (frames > 1) {
|
||||
#ifdef MAC_OS_VERSION_12_0 /* same value as deprecated symbol. */
|
||||
const NSCompositingOperation operation = NSCompositingOperationCopy;
|
||||
#else
|
||||
const NSCompositingOperation operation = NSCompositeCopy;
|
||||
#endif
|
||||
const NSSize cropped_size = NSMakeSize(image.size.width, (int) (image.size.height / frames));
|
||||
NSImage *cropped = [[NSImage alloc] initWithSize:cropped_size];
|
||||
if (cropped == nil) {
|
||||
return [NSCursor performSelector:fallback];
|
||||
}
|
||||
|
||||
#ifdef MAC_OS_VERSION_12_0 /* same value as deprecated symbol. */
|
||||
const NSCompositingOperation operation = NSCompositingOperationCopy;
|
||||
#else
|
||||
const NSCompositingOperation operation = NSCompositeCopy;
|
||||
#endif
|
||||
[cropped lockFocus];
|
||||
const NSRect cropped_rect = NSMakeRect(0, 0, cropped_size.width, cropped_size.height);
|
||||
[image drawInRect:cropped_rect fromRect:cropped_rect operation:operation fraction:1];
|
||||
{
|
||||
const NSRect cropped_rect = NSMakeRect(0, 0, cropped_size.width, cropped_size.height);
|
||||
[image drawInRect:cropped_rect fromRect:cropped_rect operation:operation fraction:1];
|
||||
}
|
||||
[cropped unlockFocus];
|
||||
image = cropped;
|
||||
}
|
||||
|
||||
NSCursor *cursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint([[info valueForKey:@"hotx"] doubleValue], [[info valueForKey:@"hoty"] doubleValue])];
|
||||
cursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint([[info valueForKey:@"hotx"] doubleValue], [[info valueForKey:@"hoty"] doubleValue])];
|
||||
return cursor;
|
||||
}
|
||||
|
||||
@@ -247,6 +249,7 @@ SDL_FindWindowAtPoint(const int x, const int y)
|
||||
static int
|
||||
Cocoa_WarpMouseGlobal(int x, int y)
|
||||
{
|
||||
CGPoint point;
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
if (mouse->focus) {
|
||||
SDL_WindowData *data = (__bridge SDL_WindowData *) mouse->focus->driverdata;
|
||||
@@ -256,7 +259,7 @@ Cocoa_WarpMouseGlobal(int x, int y)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
const CGPoint point = CGPointMake((float)x, (float)y);
|
||||
point = CGPointMake((float)x, (float)y);
|
||||
|
||||
Cocoa_HandleMouseWarp(point.x, point.y);
|
||||
|
||||
@@ -295,6 +298,8 @@ static int
|
||||
Cocoa_SetRelativeMouseMode(SDL_bool enabled)
|
||||
{
|
||||
CGError result;
|
||||
SDL_Window *window;
|
||||
SDL_WindowData *data;
|
||||
if (enabled) {
|
||||
DLog("Turning on.");
|
||||
result = CGAssociateMouseAndMouseCursorPosition(NO);
|
||||
@@ -309,7 +314,7 @@ Cocoa_SetRelativeMouseMode(SDL_bool enabled)
|
||||
/* We will re-apply the non-relative mode when the window gets focus, if it
|
||||
* doesn't have focus right now.
|
||||
*/
|
||||
SDL_Window *window = SDL_GetKeyboardFocus();
|
||||
window = SDL_GetKeyboardFocus();
|
||||
if (!window) {
|
||||
return 0;
|
||||
}
|
||||
@@ -317,7 +322,7 @@ 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.
|
||||
*/
|
||||
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
|
||||
data = (__bridge SDL_WindowData *) window->driverdata;
|
||||
if ([data.listener isMovingOrFocusClickPending]) {
|
||||
return 0;
|
||||
}
|
||||
@@ -363,6 +368,7 @@ Cocoa_GetGlobalMouseState(int *x, int *y)
|
||||
int
|
||||
Cocoa_InitMouse(_THIS)
|
||||
{
|
||||
NSPoint location;
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
SDL_MouseData *driverdata = (SDL_MouseData*) SDL_calloc(1, sizeof(SDL_MouseData));
|
||||
if (driverdata == NULL) {
|
||||
@@ -382,7 +388,7 @@ Cocoa_InitMouse(_THIS)
|
||||
|
||||
SDL_SetDefaultCursor(Cocoa_CreateDefaultCursor());
|
||||
|
||||
const NSPoint location = [NSEvent mouseLocation];
|
||||
location = [NSEvent mouseLocation];
|
||||
driverdata->lastMoveX = location.x;
|
||||
driverdata->lastMoveY = location.y;
|
||||
return 0;
|
||||
@@ -419,6 +425,13 @@ Cocoa_HandleTitleButtonEvent(_THIS, NSEvent *event)
|
||||
void
|
||||
Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
||||
{
|
||||
SDL_Mouse *mouse;
|
||||
SDL_MouseData *driverdata;
|
||||
SDL_MouseID mouseID;
|
||||
NSPoint location;
|
||||
CGFloat lastMoveX, lastMoveY;
|
||||
float deltaX, deltaY;
|
||||
SDL_bool seenWarp;
|
||||
switch ([event type]) {
|
||||
case NSEventTypeMouseMoved:
|
||||
case NSEventTypeLeftMouseDragged:
|
||||
@@ -446,19 +459,19 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata;
|
||||
mouse = SDL_GetMouse();
|
||||
driverdata = (SDL_MouseData*)mouse->driverdata;
|
||||
if (!driverdata) {
|
||||
return; /* can happen when returning from fullscreen Space on shutdown */
|
||||
}
|
||||
|
||||
SDL_MouseID mouseID = mouse ? mouse->mouseID : 0;
|
||||
const SDL_bool seenWarp = driverdata->seenWarp;
|
||||
mouseID = mouse ? mouse->mouseID : 0;
|
||||
seenWarp = driverdata->seenWarp;
|
||||
driverdata->seenWarp = NO;
|
||||
|
||||
const NSPoint location = [NSEvent mouseLocation];
|
||||
const CGFloat lastMoveX = driverdata->lastMoveX;
|
||||
const CGFloat lastMoveY = driverdata->lastMoveY;
|
||||
location = [NSEvent mouseLocation];
|
||||
lastMoveX = driverdata->lastMoveX;
|
||||
lastMoveY = driverdata->lastMoveY;
|
||||
driverdata->lastMoveX = location.x;
|
||||
driverdata->lastMoveY = location.y;
|
||||
DLog("Last seen mouse: (%g, %g)", location.x, location.y);
|
||||
@@ -476,8 +489,8 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
float deltaX = [event deltaX];
|
||||
float deltaY = [event deltaY];
|
||||
deltaX = [event deltaX];
|
||||
deltaY = [event deltaY];
|
||||
|
||||
if (seenWarp) {
|
||||
deltaX += (lastMoveX - driverdata->lastWarpX);
|
||||
@@ -492,15 +505,18 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
||||
void
|
||||
Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
|
||||
{
|
||||
SDL_MouseID mouseID;
|
||||
SDL_MouseWheelDirection direction;
|
||||
CGFloat x, y;
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
if (!mouse) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_MouseID mouseID = mouse->mouseID;
|
||||
CGFloat x = -[event deltaX];
|
||||
CGFloat y = [event deltaY];
|
||||
SDL_MouseWheelDirection direction = SDL_MOUSEWHEEL_NORMAL;
|
||||
mouseID = mouse->mouseID;
|
||||
x = -[event deltaX];
|
||||
y = [event deltaY];
|
||||
direction = SDL_MOUSEWHEEL_NORMAL;
|
||||
|
||||
if ([event isDirectionInvertedFromDevice] == YES) {
|
||||
direction = SDL_MOUSEWHEEL_FLIPPED;
|
||||
|
||||
@@ -189,6 +189,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
||||
const char *glversion;
|
||||
int glversion_major;
|
||||
int glversion_minor;
|
||||
NSOpenGLPixelFormatAttribute profile;
|
||||
|
||||
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
@@ -216,7 +217,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
||||
|
||||
attr[i++] = NSOpenGLPFAAllowOfflineRenderers;
|
||||
|
||||
NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
|
||||
profile = NSOpenGLProfileVersionLegacy;
|
||||
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
|
||||
profile = NSOpenGLProfileVersion3_2Core;
|
||||
}
|
||||
|
||||
@@ -115,6 +115,7 @@ Cocoa_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
|
||||
int
|
||||
Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
NSView* v;
|
||||
/* The current context is lost in here; save it and reset it. */
|
||||
SDL_WindowData *windowdata = (__bridge SDL_WindowData *) window->driverdata;
|
||||
SDL_Window *current_win = SDL_GL_GetCurrentWindow();
|
||||
@@ -134,7 +135,7 @@ Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
|
||||
}
|
||||
|
||||
/* Create the GLES window surface */
|
||||
NSView* v = windowdata.nswindow.contentView;
|
||||
v = windowdata.nswindow.contentView;
|
||||
windowdata.egl_surface = SDL_EGL_CreateSurface(_this, (__bridge NativeWindowType)[v layer]);
|
||||
|
||||
if (windowdata.egl_surface == EGL_NO_SURFACE) {
|
||||
|
||||
@@ -31,25 +31,28 @@ SDL_WindowShaper*
|
||||
Cocoa_CreateShaper(SDL_Window* window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
SDL_WindowShaper* result;
|
||||
SDL_ShapeData* data;
|
||||
int resized_properly;
|
||||
SDL_WindowData* windata = (__bridge SDL_WindowData*)window->driverdata;
|
||||
[windata.nswindow setOpaque:NO];
|
||||
|
||||
[windata.nswindow setStyleMask:NSWindowStyleMaskBorderless];
|
||||
|
||||
SDL_WindowShaper* result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper));
|
||||
result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper));
|
||||
result->window = window;
|
||||
result->mode.mode = ShapeModeDefault;
|
||||
result->mode.parameters.binarizationCutoff = 1;
|
||||
result->userx = result->usery = 0;
|
||||
window->shaper = result;
|
||||
|
||||
SDL_ShapeData* data = (SDL_ShapeData *)SDL_malloc(sizeof(SDL_ShapeData));
|
||||
data = (SDL_ShapeData *)SDL_malloc(sizeof(SDL_ShapeData));
|
||||
result->driverdata = data;
|
||||
data->context = [windata.nswindow graphicsContext];
|
||||
data->saved = SDL_FALSE;
|
||||
data->shape = NULL;
|
||||
|
||||
int resized_properly = Cocoa_ResizeWindowShape(window);
|
||||
resized_properly = Cocoa_ResizeWindowShape(window);
|
||||
SDL_assert(resized_properly == 0);
|
||||
return result;
|
||||
}}
|
||||
|
||||
@@ -123,13 +123,14 @@
|
||||
|
||||
- (void)sendEvent:(NSEvent *)event
|
||||
{
|
||||
id delegate;
|
||||
[super sendEvent:event];
|
||||
|
||||
if ([event type] != NSEventTypeLeftMouseUp) {
|
||||
return;
|
||||
}
|
||||
|
||||
id delegate = [self delegate];
|
||||
delegate = [self delegate];
|
||||
if (![delegate isKindOfClass:[Cocoa_WindowListener class]]) {
|
||||
return;
|
||||
}
|
||||
@@ -163,24 +164,29 @@
|
||||
NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType];
|
||||
NSString *desiredType = [pasteboard availableTypeFromArray:types];
|
||||
SDL_Window *sdlwindow = [self findSDLWindow];
|
||||
NSData *data;
|
||||
NSArray *array;
|
||||
NSPoint point;
|
||||
SDL_Mouse *mouse;
|
||||
int x, y;
|
||||
|
||||
if (desiredType == nil) {
|
||||
return NO; /* can't accept anything that's being dropped here. */
|
||||
}
|
||||
|
||||
NSData *data = [pasteboard dataForType:desiredType];
|
||||
data = [pasteboard dataForType:desiredType];
|
||||
if (data == nil) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
|
||||
NSArray *array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
|
||||
array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
|
||||
|
||||
/* Code addon to update the mouse location */
|
||||
NSPoint point = [sender draggingLocation];
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
int x = (int)point.x;
|
||||
int y = (int)(sdlwindow->h - point.y);
|
||||
point = [sender draggingLocation];
|
||||
mouse = SDL_GetMouse();
|
||||
x = (int)point.x;
|
||||
y = (int)(sdlwindow->h - point.y);
|
||||
if (x >= 0 && x < sdlwindow->w && y >= 0 && y < sdlwindow->h) {
|
||||
SDL_SendMouseMotion(sdlwindow, mouse->mouseID, 0, x, y);
|
||||
}
|
||||
@@ -254,6 +260,8 @@ static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
|
||||
static void
|
||||
ScheduleContextUpdates(SDL_WindowData *data)
|
||||
{
|
||||
NSOpenGLContext *currentContext;
|
||||
NSMutableArray *contexts;
|
||||
if (!data || !data.nscontexts) {
|
||||
return;
|
||||
}
|
||||
@@ -264,8 +272,8 @@ ScheduleContextUpdates(SDL_WindowData *data)
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
|
||||
NSMutableArray *contexts = data.nscontexts;
|
||||
currentContext = [NSOpenGLContext currentContext];
|
||||
contexts = data.nscontexts;
|
||||
@synchronized (contexts) {
|
||||
for (SDLOpenGLContext *context in contexts) {
|
||||
if (context == currentContext) {
|
||||
@@ -763,15 +771,19 @@ Cocoa_UpdateClipCursor(SDL_Window * window)
|
||||
|
||||
- (void)windowDidResize:(NSNotification *)aNotification
|
||||
{
|
||||
SDL_Window *window;
|
||||
NSWindow *nswindow;
|
||||
NSRect rect;
|
||||
int x, y, w, h;
|
||||
BOOL zoomed;
|
||||
if (inFullscreenTransition) {
|
||||
/* We'll take care of this at the end of the transition */
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_Window *window = _data.window;
|
||||
NSWindow *nswindow = _data.nswindow;
|
||||
int x, y, w, h;
|
||||
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
||||
window = _data.window;
|
||||
nswindow = _data.nswindow;
|
||||
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
||||
ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
|
||||
x = (int)rect.origin.x;
|
||||
y = (int)rect.origin.y;
|
||||
@@ -789,7 +801,7 @@ Cocoa_UpdateClipCursor(SDL_Window * window)
|
||||
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
|
||||
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
|
||||
|
||||
const BOOL zoomed = [nswindow isZoomed];
|
||||
zoomed = [nswindow isZoomed];
|
||||
if (!zoomed) {
|
||||
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
|
||||
} else if (zoomed) {
|
||||
@@ -844,10 +856,11 @@ Cocoa_UpdateClipCursor(SDL_Window * window)
|
||||
if ((isFullscreenSpace) && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)) {
|
||||
[NSMenu setMenuBarVisible:NO];
|
||||
}
|
||||
|
||||
const unsigned int newflags = [NSEvent modifierFlags] & NSEventModifierFlagCapsLock;
|
||||
_data.videodata.modifierFlags = (_data.videodata.modifierFlags & ~NSEventModifierFlagCapsLock) | newflags;
|
||||
SDL_ToggleModState(KMOD_CAPS, newflags != 0);
|
||||
{
|
||||
const unsigned int newflags = [NSEvent modifierFlags] & NSEventModifierFlagCapsLock;
|
||||
_data.videodata.modifierFlags = (_data.videodata.modifierFlags & ~NSEventModifierFlagCapsLock) | newflags;
|
||||
SDL_ToggleModState(KMOD_CAPS, newflags != 0);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)windowDidResignKey:(NSNotification *)aNotification
|
||||
@@ -1187,12 +1200,12 @@ Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * w
|
||||
- (void)mouseDown:(NSEvent *)theEvent
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
int button;
|
||||
|
||||
if (!mouse) {
|
||||
return;
|
||||
}
|
||||
|
||||
int button;
|
||||
|
||||
/* Ignore events that aren't inside the client area (i.e. title bar.) */
|
||||
if ([theEvent window]) {
|
||||
NSRect windowRect = [[[theEvent window] contentView] frame];
|
||||
@@ -1244,12 +1257,12 @@ Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * w
|
||||
- (void)mouseUp:(NSEvent *)theEvent
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
int button;
|
||||
|
||||
if (!mouse) {
|
||||
return;
|
||||
}
|
||||
|
||||
int button;
|
||||
|
||||
if ([self processHitTest:theEvent]) {
|
||||
SDL_SendWindowEvent(_data.window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
|
||||
return; /* stopped dragging, drop event. */
|
||||
@@ -1291,14 +1304,17 @@ Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * w
|
||||
- (void)mouseMoved:(NSEvent *)theEvent
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
SDL_MouseID mouseID;
|
||||
NSPoint point;
|
||||
int x, y;
|
||||
SDL_Window *window;
|
||||
|
||||
if (!mouse) {
|
||||
return;
|
||||
}
|
||||
|
||||
const SDL_MouseID mouseID = mouse->mouseID;
|
||||
SDL_Window *window = _data.window;
|
||||
NSPoint point;
|
||||
int x, y;
|
||||
mouseID = mouse->mouseID;
|
||||
window = _data.window;
|
||||
|
||||
if ([self processHitTest:theEvent]) {
|
||||
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
|
||||
@@ -1350,6 +1366,10 @@ Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * w
|
||||
|
||||
- (void)touchesBeganWithEvent:(NSEvent *) theEvent
|
||||
{
|
||||
NSSet *touches;
|
||||
SDL_TouchID touchID;
|
||||
int existingTouchCount;
|
||||
|
||||
/* probably a MacBook trackpad; make this look like a synthesized event.
|
||||
This is backwards from reality, but better matches user expectations. */
|
||||
BOOL istrackpad = NO;
|
||||
@@ -1365,9 +1385,9 @@ Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * w
|
||||
*/
|
||||
}
|
||||
|
||||
NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
|
||||
const SDL_TouchID touchID = istrackpad ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t)[[touches anyObject] device];
|
||||
int existingTouchCount = 0;
|
||||
touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
|
||||
touchID = istrackpad ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t)[[touches anyObject] device];
|
||||
existingTouchCount = 0;
|
||||
|
||||
for (NSTouch* touch in touches) {
|
||||
if ([touch phase] != NSTouchPhaseBegan) {
|
||||
@@ -1411,6 +1431,8 @@ Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * w
|
||||
- (void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
|
||||
{
|
||||
NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
|
||||
SDL_FingerID fingerId;
|
||||
float x, y;
|
||||
|
||||
/* probably a MacBook trackpad; make this look like a synthesized event.
|
||||
This is backwards from reality, but better matches user expectations. */
|
||||
@@ -1457,9 +1479,9 @@ Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * w
|
||||
return;
|
||||
}
|
||||
|
||||
const SDL_FingerID fingerId = (SDL_FingerID)(intptr_t)[touch identity];
|
||||
float x = [touch normalizedPosition].x;
|
||||
float y = [touch normalizedPosition].y;
|
||||
fingerId = (SDL_FingerID)(intptr_t)[touch identity];
|
||||
x = [touch normalizedPosition].x;
|
||||
y = [touch normalizedPosition].y;
|
||||
/* Make the origin the upper left instead of the lower left */
|
||||
y = 1.0f - y;
|
||||
|
||||
@@ -1554,8 +1576,9 @@ Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * w
|
||||
|
||||
- (void)resetCursorRects
|
||||
{
|
||||
SDL_Mouse *mouse;
|
||||
[super resetCursorRects];
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
mouse = SDL_GetMouse();
|
||||
|
||||
if (mouse->cursor_shown && mouse->cur_cursor && !mouse->relative_mode) {
|
||||
[self addCursorRect:[self bounds]
|
||||
@@ -1680,6 +1703,9 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
||||
SDL_Rect bounds;
|
||||
NSUInteger style;
|
||||
NSArray *screens = [NSScreen screens];
|
||||
NSScreen *screen = nil;
|
||||
SDLView *contentView;
|
||||
BOOL highdpi;
|
||||
|
||||
Cocoa_GetDisplayBounds(_this, display, &bounds);
|
||||
rect.origin.x = window->x;
|
||||
@@ -1691,7 +1717,6 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
||||
style = GetWindowStyle(window);
|
||||
|
||||
/* Figure out which screen to place this window */
|
||||
NSScreen *screen = nil;
|
||||
for (NSScreen *candidate in screens) {
|
||||
NSRect screenRect = [candidate frame];
|
||||
if (rect.origin.x >= screenRect.origin.x &&
|
||||
@@ -1732,7 +1757,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
||||
|
||||
/* Create a default view for this window */
|
||||
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
||||
SDLView *contentView = [[SDLView alloc] initWithFrame:rect];
|
||||
contentView = [[SDLView alloc] initWithFrame:rect];
|
||||
[contentView setSDLWindow:window];
|
||||
|
||||
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
|
||||
@@ -1742,7 +1767,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
||||
#endif
|
||||
/* Note: as of the macOS 10.15 SDK, this defaults to YES instead of NO when
|
||||
* the NSHighResolutionCapable boolean is set in Info.plist. */
|
||||
BOOL highdpi = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
|
||||
highdpi = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
|
||||
[contentView setWantsBestResolutionOpenGLSurface:highdpi];
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
@@ -1789,6 +1814,8 @@ Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
|
||||
{
|
||||
NSView* nsview = nil;
|
||||
NSWindow *nswindow = nil;
|
||||
NSString *title;
|
||||
BOOL highdpi;
|
||||
|
||||
if ([(__bridge id)data isKindOfClass:[NSWindow class]]) {
|
||||
nswindow = (__bridge NSWindow*)data;
|
||||
@@ -1800,8 +1827,6 @@ Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
|
||||
SDL_assert(false);
|
||||
}
|
||||
|
||||
NSString *title;
|
||||
|
||||
/* Query the title from the existing window */
|
||||
title = [nswindow title];
|
||||
if (title) {
|
||||
@@ -1815,7 +1840,7 @@ Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
|
||||
#endif
|
||||
/* Note: as of the macOS 10.15 SDK, this defaults to YES instead of NO when
|
||||
* the NSHighResolutionCapable boolean is set in Info.plist. */
|
||||
BOOL highdpi = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
|
||||
highdpi = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
|
||||
[nsview setWantsBestResolutionOpenGLSurface:highdpi];
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
@@ -2083,6 +2108,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
|
||||
|
||||
[nswindow setStyleMask:NSWindowStyleMaskBorderless];
|
||||
} else {
|
||||
NSRect frameRect;
|
||||
rect.origin.x = window->windowed.x;
|
||||
rect.origin.y = window->windowed.y;
|
||||
rect.size.width = window->windowed.w;
|
||||
@@ -2098,7 +2124,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
|
||||
[nswindow setStyleMask:GetWindowWindowedStyle(window)];
|
||||
|
||||
/* Hack to restore window decorations on Mac OS X 10.10 */
|
||||
NSRect frameRect = [nswindow frame];
|
||||
frameRect = [nswindow frame];
|
||||
[nswindow setFrame:NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width + 1, frameRect.size.height) display:NO];
|
||||
[nswindow setFrame:frameRect display:NO];
|
||||
}
|
||||
@@ -2204,6 +2230,9 @@ int
|
||||
Cocoa_GetWindowDisplayIndex(_THIS, SDL_Window * window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSRect displayframe;
|
||||
SDL_Point display_center;
|
||||
SDL_Rect sdl_display_rect;
|
||||
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
|
||||
|
||||
/* Not recognized via CHECK_WINDOW_MAGIC */
|
||||
@@ -2216,9 +2245,7 @@ Cocoa_GetWindowDisplayIndex(_THIS, SDL_Window * window)
|
||||
instead of checking in which display the window is placed, we should check which SDL display matches the display described
|
||||
via displayframe.
|
||||
*/
|
||||
NSRect displayframe = data.nswindow.screen.frame;
|
||||
SDL_Point display_center;
|
||||
SDL_Rect sdl_display_rect;
|
||||
displayframe = data.nswindow.screen.frame;
|
||||
|
||||
display_center.x = displayframe.origin.x + displayframe.size.width / 2;
|
||||
display_center.y = displayframe.origin.y + displayframe.size.height / 2;
|
||||
@@ -2292,6 +2319,7 @@ Cocoa_DestroyWindow(_THIS, SDL_Window * window)
|
||||
SDL_WindowData *data = (SDL_WindowData *) CFBridgingRelease(window->driverdata);
|
||||
|
||||
if (data) {
|
||||
NSArray *contexts;
|
||||
if ([data.listener isInFullscreenSpace]) {
|
||||
[NSMenu setMenuBarVisible:YES];
|
||||
}
|
||||
@@ -2303,7 +2331,7 @@ Cocoa_DestroyWindow(_THIS, SDL_Window * window)
|
||||
[data.nswindow close];
|
||||
}
|
||||
|
||||
NSArray *contexts = [data.nscontexts copy];
|
||||
contexts = [data.nscontexts copy];
|
||||
for (SDLOpenGLContext *context in contexts) {
|
||||
/* Calling setWindow:NULL causes the context to remove itself from the context list. */
|
||||
[context setWindow:NULL];
|
||||
|
||||
Reference in New Issue
Block a user