Cocoa: user performSelectorOnMainThread instead of postEvent for the tick callback
performSelectorOnMainThread runs in more loop run modes which means that the tick callback will behave more like it does on other platforms, during window resizes and other modal event loops.
This commit is contained in:
parent
48303bac75
commit
0dc6ac26c3
4 changed files with 10 additions and 8 deletions
|
|
@ -295,6 +295,7 @@ - (void)doNothing:(id)object
|
|||
@end // GLFWHelper
|
||||
|
||||
@interface GLFWApplication : NSApplication
|
||||
- (void)tick_callback;
|
||||
@end
|
||||
|
||||
extern void dispatchCustomEvent(NSEvent *event);
|
||||
|
|
@ -305,6 +306,11 @@ - (void)sendEvent:(NSEvent *)event {
|
|||
dispatchCustomEvent(event);
|
||||
} else [super sendEvent:event];
|
||||
}
|
||||
|
||||
- (void)tick_callback
|
||||
{
|
||||
_glfwDispatchTickCallback();
|
||||
}
|
||||
@end
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -462,6 +468,7 @@ void _glfwPlatformTerminate(void)
|
|||
static void* tick_callback_data = NULL;
|
||||
static bool tick_callback_requested = false;
|
||||
|
||||
|
||||
void _glfwDispatchTickCallback() {
|
||||
if (tick_callback) {
|
||||
tick_callback_requested = false;
|
||||
|
|
@ -472,7 +479,7 @@ void _glfwDispatchTickCallback() {
|
|||
void _glfwPlatformRequestTickCallback() {
|
||||
if (!tick_callback_requested) {
|
||||
tick_callback_requested = true;
|
||||
_glfwCocoaPostEmptyEvent(TICK_CALLBACK_EVENT_TYPE, 0, false);
|
||||
[NSApp performSelectorOnMainThread:@selector(tick_callback) withObject:nil waitUntilDone:NO];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
1
glfw/cocoa_platform.h
vendored
1
glfw/cocoa_platform.h
vendored
|
|
@ -39,7 +39,6 @@ typedef void* CVDisplayLinkRef;
|
|||
typedef enum {
|
||||
EMPTY_EVENT_TYPE,
|
||||
RENDER_FRAME_REQUEST_EVENT_TYPE,
|
||||
TICK_CALLBACK_EVENT_TYPE
|
||||
} EventTypes;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1769,10 +1769,6 @@ static inline CGDirectDisplayID displayIDForWindow(_GLFWwindow *w) {
|
|||
case EMPTY_EVENT_TYPE:
|
||||
break;
|
||||
|
||||
case TICK_CALLBACK_EVENT_TYPE:
|
||||
_glfwDispatchTickCallback();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -939,8 +939,8 @@ void
|
|||
wakeup_main_loop() {
|
||||
request_tick_callback();
|
||||
#ifndef __APPLE__
|
||||
// On Cocoa request_tick_callback() uses an event which wakes up the
|
||||
// main loop anyway
|
||||
// On Cocoa request_tick_callback() uses performSelectorOnMainLoop which
|
||||
// wakes up the main loop anyway
|
||||
glfwPostEmptyEvent();
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue