diff --git a/glfw/cocoa_init.m b/glfw/cocoa_init.m index 041793b12..1e719d2e6 100644 --- a/glfw/cocoa_init.m +++ b/glfw/cocoa_init.m @@ -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) { diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index d20addc00..1ce79b565 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -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(); }