internal/glfw: bug fix: posting an empty event from different goroutine fails

This change applies the bug fix at glfw/glfw#1649

After this change, an Ebitengine application always shows the menu
bar, but this should be fine for Ebitengine applications.
This commit is contained in:
Hajime Hoshi 2024-04-14 14:44:38 +09:00
parent 6ff9e2b44c
commit d5f15f9354
4 changed files with 12 additions and 27 deletions

View File

@ -420,7 +420,6 @@ static GLFWbool initializeTIS(void)
- (void)applicationDidFinishLaunching:(NSNotification *)notification - (void)applicationDidFinishLaunching:(NSNotification *)notification
{ {
_glfw.ns.finishedLaunching = GLFW_TRUE;
_glfwPlatformPostEmptyEvent(); _glfwPlatformPostEmptyEvent();
// In case we are unbundled, make us a proper UI application // In case we are unbundled, make us a proper UI application
@ -455,9 +454,6 @@ int _glfwPlatformInit(void)
toTarget:_glfw.ns.helper toTarget:_glfw.ns.helper
withObject:nil]; withObject:nil];
if (NSApp)
_glfw.ns.finishedLaunching = GLFW_TRUE;
[NSApplication sharedApplication]; [NSApplication sharedApplication];
_glfw.ns.delegate = [[GLFWApplicationDelegate alloc] init]; _glfw.ns.delegate = [[GLFWApplicationDelegate alloc] init];
@ -509,6 +505,10 @@ int _glfwPlatformInit(void)
_glfwInitTimerNS(); _glfwInitTimerNS();
_glfwPollMonitorsNS(); _glfwPollMonitorsNS();
if (![[NSRunningApplication currentApplication] isFinishedLaunching])
[NSApp run];
return GLFW_TRUE; return GLFW_TRUE;
} // autoreleasepool } // autoreleasepool

View File

@ -109,7 +109,6 @@ typedef struct _GLFWlibraryNS
{ {
CGEventSourceRef eventSource; CGEventSourceRef eventSource;
id delegate; id delegate;
GLFWbool finishedLaunching;
GLFWbool cursorHidden; GLFWbool cursorHidden;
TISInputSourceRef inputSource; TISInputSourceRef inputSource;
id unicodeData; id unicodeData;

View File

@ -883,9 +883,6 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
{ {
@autoreleasepool { @autoreleasepool {
if (!_glfw.ns.finishedLaunching)
[NSApp run];
if (!createNativeWindow(window, wndconfig, fbconfig)) if (!createNativeWindow(window, wndconfig, fbconfig))
return GLFW_FALSE; return GLFW_FALSE;
@ -1477,9 +1474,6 @@ void _glfwPlatformPollEvents(void)
{ {
@autoreleasepool { @autoreleasepool {
if (!_glfw.ns.finishedLaunching)
[NSApp run];
for (;;) for (;;)
{ {
NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny
@ -1499,9 +1493,6 @@ void _glfwPlatformWaitEvents(void)
{ {
@autoreleasepool { @autoreleasepool {
if (!_glfw.ns.finishedLaunching)
[NSApp run];
// I wanted to pass NO to dequeue:, and rely on PollEvents to // I wanted to pass NO to dequeue:, and rely on PollEvents to
// dequeue and send. For reasons not at all clear to me, passing // dequeue and send. For reasons not at all clear to me, passing
// NO to dequeue: causes this method never to return. // NO to dequeue: causes this method never to return.
@ -1520,9 +1511,6 @@ void _glfwPlatformWaitEventsTimeout(double timeout)
{ {
@autoreleasepool { @autoreleasepool {
if (!_glfw.ns.finishedLaunching)
[NSApp run];
NSDate* date = [NSDate dateWithTimeIntervalSinceNow:timeout]; NSDate* date = [NSDate dateWithTimeIntervalSinceNow:timeout];
NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny
untilDate:date untilDate:date
@ -1540,9 +1528,6 @@ void _glfwPlatformPostEmptyEvent(void)
{ {
@autoreleasepool { @autoreleasepool {
if (!_glfw.ns.finishedLaunching)
[NSApp run];
NSEvent* event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined NSEvent* event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined
location:NSMakePoint(0, 0) location:NSMakePoint(0, 0)
modifierFlags:0 modifierFlags:0

View File

@ -1592,6 +1592,14 @@ typedef struct GLFWimage
* bundle, if present. This can be disabled with the @ref * bundle, if present. This can be disabled with the @ref
* GLFW_COCOA_CHDIR_RESOURCES init hint. * GLFW_COCOA_CHDIR_RESOURCES init hint.
* *
* @remark @macos This function will create the main menu and dock icon for the
* application. If GLFW finds a `MainMenu.nib` it is loaded and assumed to
* contain a menu bar. Otherwise a minimal menu bar is created manually with
* common commands like Hide, Quit and About. The About entry opens a minimal
* about dialog with information from the application's bundle. The menu bar
* and dock icon can be disabled entirely with the @ref GLFW_COCOA_MENUBAR init
* hint.
*
* @remark @x11 This function will set the `LC_CTYPE` category of the * @remark @x11 This function will set the `LC_CTYPE` category of the
* application locale according to the current environment if that category is * application locale according to the current environment if that category is
* still "C". This is because the "C" locale breaks Unicode text input. * still "C". This is because the "C" locale breaks Unicode text input.
@ -2439,13 +2447,6 @@ GLFWAPI void glfwWindowHintString(int hint, const char* value);
* [Bundle Programming Guide](https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/) * [Bundle Programming Guide](https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/)
* in the Mac Developer Library. * in the Mac Developer Library.
* *
* @remark @macos The first time a window is created the menu bar is created.
* If GLFW finds a `MainMenu.nib` it is loaded and assumed to contain a menu
* bar. Otherwise a minimal menu bar is created manually with common commands
* like Hide, Quit and About. The About entry opens a minimal about dialog
* with information from the application's bundle. Menu bar creation can be
* disabled entirely with the @ref GLFW_COCOA_MENUBAR init hint.
*
* @remark @macos On OS X 10.10 and later the window frame will not be rendered * @remark @macos On OS X 10.10 and later the window frame will not be rendered
* at full resolution on Retina displays unless the * at full resolution on Retina displays unless the
* [GLFW_COCOA_RETINA_FRAMEBUFFER](@ref GLFW_COCOA_RETINA_FRAMEBUFFER_hint) * [GLFW_COCOA_RETINA_FRAMEBUFFER](@ref GLFW_COCOA_RETINA_FRAMEBUFFER_hint)