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:
Kovid Goyal 2019-03-21 15:51:10 +05:30
parent 48303bac75
commit 0dc6ac26c3
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 10 additions and 8 deletions

View File

@ -295,6 +295,7 @@ static GLFWbool initializeTIS(void)
@end // GLFWHelper @end // GLFWHelper
@interface GLFWApplication : NSApplication @interface GLFWApplication : NSApplication
- (void)tick_callback;
@end @end
extern void dispatchCustomEvent(NSEvent *event); extern void dispatchCustomEvent(NSEvent *event);
@ -305,6 +306,11 @@ extern void dispatchCustomEvent(NSEvent *event);
dispatchCustomEvent(event); dispatchCustomEvent(event);
} else [super sendEvent:event]; } else [super sendEvent:event];
} }
- (void)tick_callback
{
_glfwDispatchTickCallback();
}
@end @end
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -462,6 +468,7 @@ static GLFWtickcallback tick_callback = NULL;
static void* tick_callback_data = NULL; static void* tick_callback_data = NULL;
static bool tick_callback_requested = false; static bool tick_callback_requested = false;
void _glfwDispatchTickCallback() { void _glfwDispatchTickCallback() {
if (tick_callback) { if (tick_callback) {
tick_callback_requested = false; tick_callback_requested = false;
@ -472,7 +479,7 @@ void _glfwDispatchTickCallback() {
void _glfwPlatformRequestTickCallback() { void _glfwPlatformRequestTickCallback() {
if (!tick_callback_requested) { if (!tick_callback_requested) {
tick_callback_requested = true; tick_callback_requested = true;
_glfwCocoaPostEmptyEvent(TICK_CALLBACK_EVENT_TYPE, 0, false); [NSApp performSelectorOnMainThread:@selector(tick_callback) withObject:nil waitUntilDone:NO];
} }
} }

View File

@ -39,7 +39,6 @@ typedef void* CVDisplayLinkRef;
typedef enum { typedef enum {
EMPTY_EVENT_TYPE, EMPTY_EVENT_TYPE,
RENDER_FRAME_REQUEST_EVENT_TYPE, RENDER_FRAME_REQUEST_EVENT_TYPE,
TICK_CALLBACK_EVENT_TYPE
} EventTypes; } EventTypes;

View File

@ -1769,10 +1769,6 @@ dispatchCustomEvent(NSEvent *event) {
case EMPTY_EVENT_TYPE: case EMPTY_EVENT_TYPE:
break; break;
case TICK_CALLBACK_EVENT_TYPE:
_glfwDispatchTickCallback();
break;
default: default:
break; break;
} }

View File

@ -939,8 +939,8 @@ void
wakeup_main_loop() { wakeup_main_loop() {
request_tick_callback(); request_tick_callback();
#ifndef __APPLE__ #ifndef __APPLE__
// On Cocoa request_tick_callback() uses an event which wakes up the // On Cocoa request_tick_callback() uses performSelectorOnMainLoop which
// main loop anyway // wakes up the main loop anyway
glfwPostEmptyEvent(); glfwPostEmptyEvent();
#endif #endif
} }