early-access version 1780
This commit is contained in:
@@ -32,10 +32,14 @@ Cocoa_SetClipboardText(_THIS, const char *text)
|
||||
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
||||
NSPasteboard *pasteboard;
|
||||
NSString *format = NSPasteboardTypeString;
|
||||
NSString *nsstr = [NSString stringWithUTF8String:text];
|
||||
if (nsstr == nil) {
|
||||
return SDL_SetError("Couldn't create NSString; is your string data in UTF-8 format?");
|
||||
}
|
||||
|
||||
pasteboard = [NSPasteboard generalPasteboard];
|
||||
data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
|
||||
[pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
|
||||
[pasteboard setString:nsstr forType:format];
|
||||
|
||||
return 0;
|
||||
}}
|
||||
@@ -61,7 +65,7 @@ Cocoa_GetClipboardText(_THIS)
|
||||
} else {
|
||||
utf8 = [string UTF8String];
|
||||
}
|
||||
text = SDL_strdup(utf8);
|
||||
text = SDL_strdup(utf8 ? utf8 : "");
|
||||
} else {
|
||||
text = SDL_strdup("");
|
||||
}
|
||||
|
@@ -25,6 +25,8 @@
|
||||
|
||||
extern void Cocoa_RegisterApp(void);
|
||||
extern void Cocoa_PumpEvents(_THIS);
|
||||
extern int Cocoa_WaitEventTimeout(_THIS, int timeout);
|
||||
extern void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window);
|
||||
extern void Cocoa_SuspendScreenSaver(_THIS);
|
||||
|
||||
#endif /* SDL_cocoaevents_h_ */
|
||||
|
57
externals/SDL/src/video/cocoa/SDL_cocoaevents.m
vendored
57
externals/SDL/src/video/cocoa/SDL_cocoaevents.m
vendored
@@ -35,6 +35,9 @@
|
||||
#ifndef NSAppKitVersionNumber10_8
|
||||
#define NSAppKitVersionNumber10_8 1187
|
||||
#endif
|
||||
#ifndef MAC_OS_X_VERSION_10_12
|
||||
#define NSEventTypeApplicationDefined NSApplicationDefined
|
||||
#endif
|
||||
|
||||
static SDL_Window *FindSDLWindowForNSWindow(NSWindow *win)
|
||||
{
|
||||
@@ -512,9 +515,8 @@ Cocoa_RegisterApp(void)
|
||||
}
|
||||
}}
|
||||
|
||||
void
|
||||
Cocoa_PumpEvents(_THIS)
|
||||
{ @autoreleasepool
|
||||
int
|
||||
Cocoa_PumpEventsUntilDate(_THIS, NSDate *expiration, bool accumulate)
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
|
||||
/* Update activity every 30 seconds to prevent screensaver */
|
||||
@@ -530,9 +532,9 @@ Cocoa_PumpEvents(_THIS)
|
||||
#endif
|
||||
|
||||
for ( ; ; ) {
|
||||
NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
|
||||
NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:expiration inMode:NSDefaultRunLoopMode dequeue:YES ];
|
||||
if ( event == nil ) {
|
||||
break;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!s_bShouldHandleEventsInSDLApplication) {
|
||||
@@ -541,7 +543,52 @@ Cocoa_PumpEvents(_THIS)
|
||||
|
||||
// Pass events down to SDLApplication to be handled in sendEvent:
|
||||
[NSApp sendEvent:event];
|
||||
if ( !accumulate) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
Cocoa_WaitEventTimeout(_THIS, int timeout)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
if (timeout > 0) {
|
||||
NSDate *limitDate = [NSDate dateWithTimeIntervalSinceNow: (double) timeout / 1000.0];
|
||||
return Cocoa_PumpEventsUntilDate(_this, limitDate, false);
|
||||
} else if (timeout == 0) {
|
||||
return Cocoa_PumpEventsUntilDate(_this, [NSDate distantPast], false);
|
||||
} else {
|
||||
while (Cocoa_PumpEventsUntilDate(_this, [NSDate distantFuture], false) == 0) {
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}}
|
||||
|
||||
void
|
||||
Cocoa_PumpEvents(_THIS)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
Cocoa_PumpEventsUntilDate(_this, [NSDate distantPast], true);
|
||||
}}
|
||||
|
||||
void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
|
||||
NSEvent* event = [NSEvent otherEventWithType: NSEventTypeApplicationDefined
|
||||
location: NSMakePoint(0,0)
|
||||
modifierFlags: 0
|
||||
timestamp: 0.0
|
||||
windowNumber: nswindow.windowNumber
|
||||
context: nil
|
||||
subtype: 0
|
||||
data1: 0
|
||||
data2: 0];
|
||||
|
||||
[NSApp postEvent: event atStart: YES];
|
||||
}}
|
||||
|
||||
void
|
||||
|
@@ -38,6 +38,9 @@ static void Cocoa_VideoQuit(_THIS);
|
||||
static void
|
||||
Cocoa_DeleteDevice(SDL_VideoDevice * device)
|
||||
{
|
||||
if (device->wakeup_lock) {
|
||||
SDL_DestroyMutex(device->wakeup_lock);
|
||||
}
|
||||
SDL_free(device->driverdata);
|
||||
SDL_free(device);
|
||||
}
|
||||
@@ -63,6 +66,7 @@ Cocoa_CreateDevice(int devindex)
|
||||
return NULL;
|
||||
}
|
||||
device->driverdata = data;
|
||||
device->wakeup_lock = SDL_CreateMutex();
|
||||
|
||||
/* Set the function pointers */
|
||||
device->VideoInit = Cocoa_VideoInit;
|
||||
@@ -73,6 +77,8 @@ Cocoa_CreateDevice(int devindex)
|
||||
device->GetDisplayModes = Cocoa_GetDisplayModes;
|
||||
device->SetDisplayMode = Cocoa_SetDisplayMode;
|
||||
device->PumpEvents = Cocoa_PumpEvents;
|
||||
device->WaitEventTimeout = Cocoa_WaitEventTimeout;
|
||||
device->SendWakeupEvent = Cocoa_SendWakeupEvent;
|
||||
device->SuspendScreenSaver = Cocoa_SuspendScreenSaver;
|
||||
|
||||
device->CreateSDLWindow = Cocoa_CreateWindow;
|
||||
|
Reference in New Issue
Block a user