Move cocoa custom even dispatching into the application object
This allows it to work even with the cocoa run loop
This commit is contained in:
parent
01ed1e1604
commit
a1e9b854e3
@ -294,6 +294,18 @@ static GLFWbool initializeTIS(void)
|
||||
|
||||
@end // GLFWHelper
|
||||
|
||||
@interface GLFWApplication : NSApplication
|
||||
@end
|
||||
|
||||
extern void dispatchCustomEvent(NSEvent *event);
|
||||
|
||||
@implementation GLFWApplication
|
||||
- (void)sendEvent:(NSEvent *)event {
|
||||
if (event.type == NSEventTypeApplicationDefined) {
|
||||
dispatchCustomEvent(event);
|
||||
} else [super sendEvent:event];
|
||||
}
|
||||
@end
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW platform API //////
|
||||
@ -319,7 +331,7 @@ int _glfwPlatformInit(void)
|
||||
toTarget:_glfw.ns.helper
|
||||
withObject:nil];
|
||||
|
||||
[NSApplication sharedApplication];
|
||||
[GLFWApplication sharedApplication];
|
||||
|
||||
NSEvent* (^keydown_block)(NSEvent*) = ^ NSEvent* (NSEvent* event)
|
||||
{
|
||||
|
||||
@ -1752,20 +1752,19 @@ static inline CGDirectDisplayID displayIDForWindow(_GLFWwindow *w) {
|
||||
return (CGDirectDisplayID)-1;
|
||||
}
|
||||
|
||||
static inline void sendEvent(NSEvent *event) {
|
||||
if (event.type == NSEventTypeApplicationDefined) {
|
||||
if (event.subtype == RENDER_FRAME_REQUEST_EVENT_TYPE) {
|
||||
CGDirectDisplayID displayID = (CGDirectDisplayID)event.data1;
|
||||
_GLFWwindow *w = _glfw.windowListHead;
|
||||
while (w) {
|
||||
if (w->ns.renderFrameRequested && displayID == displayIDForWindow(w)) {
|
||||
w->ns.renderFrameRequested = GLFW_FALSE;
|
||||
w->ns.renderFrameCallback((GLFWwindow*)w);
|
||||
}
|
||||
w = w->next;
|
||||
void
|
||||
dispatchCustomEvent(NSEvent *event) {
|
||||
if (event.subtype == RENDER_FRAME_REQUEST_EVENT_TYPE) {
|
||||
CGDirectDisplayID displayID = (CGDirectDisplayID)event.data1;
|
||||
_GLFWwindow *w = _glfw.windowListHead;
|
||||
while (w) {
|
||||
if (w->ns.renderFrameRequested && displayID == displayIDForWindow(w)) {
|
||||
w->ns.renderFrameRequested = GLFW_FALSE;
|
||||
w->ns.renderFrameCallback((GLFWwindow*)w);
|
||||
}
|
||||
w = w->next;
|
||||
}
|
||||
} else [NSApp sendEvent:event];
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
@ -1804,7 +1803,7 @@ void _glfwPlatformPollEvents(void)
|
||||
if (event == nil)
|
||||
break;
|
||||
|
||||
sendEvent(event);
|
||||
[NSApp sendEvent:event];
|
||||
}
|
||||
|
||||
[_glfw.ns.autoreleasePool drain];
|
||||
@ -1820,7 +1819,7 @@ void _glfwPlatformWaitEvents(void)
|
||||
untilDate:[NSDate distantFuture]
|
||||
inMode:NSDefaultRunLoopMode
|
||||
dequeue:YES];
|
||||
sendEvent(event);
|
||||
[NSApp sendEvent:event];
|
||||
|
||||
_glfwPlatformPollEvents();
|
||||
}
|
||||
@ -1832,7 +1831,7 @@ void _glfwPlatformWaitEventsTimeout(double timeout)
|
||||
untilDate:date
|
||||
inMode:NSDefaultRunLoopMode
|
||||
dequeue:YES];
|
||||
if (event) sendEvent(event);
|
||||
if (event) [NSApp sendEvent:event];
|
||||
|
||||
_glfwPlatformPollEvents();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user