Skip to content

Commit

Permalink
internal/glfw: bug fix: posting an empty event from different gorouti…
Browse files Browse the repository at this point in the history
…ne 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.
  • Loading branch information
hajimehoshi committed Apr 14, 2024
1 parent 6ff9e2b commit d5f15f9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 27 deletions.
8 changes: 4 additions & 4 deletions internal/glfw/cocoa_init_darwin.m
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ - (void)applicationWillFinishLaunching:(NSNotification *)notification

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
_glfw.ns.finishedLaunching = GLFW_TRUE;
_glfwPlatformPostEmptyEvent();

// In case we are unbundled, make us a proper UI application
Expand Down Expand Up @@ -455,9 +454,6 @@ int _glfwPlatformInit(void)
toTarget:_glfw.ns.helper
withObject:nil];

if (NSApp)
_glfw.ns.finishedLaunching = GLFW_TRUE;

[NSApplication sharedApplication];

_glfw.ns.delegate = [[GLFWApplicationDelegate alloc] init];
Expand Down Expand Up @@ -509,6 +505,10 @@ int _glfwPlatformInit(void)
_glfwInitTimerNS();

_glfwPollMonitorsNS();

if (![[NSRunningApplication currentApplication] isFinishedLaunching])
[NSApp run];

return GLFW_TRUE;

} // autoreleasepool
Expand Down
1 change: 0 additions & 1 deletion internal/glfw/cocoa_platform_darwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ typedef struct _GLFWlibraryNS
{
CGEventSourceRef eventSource;
id delegate;
GLFWbool finishedLaunching;
GLFWbool cursorHidden;
TISInputSourceRef inputSource;
id unicodeData;
Expand Down
15 changes: 0 additions & 15 deletions internal/glfw/cocoa_window_darwin.m
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,6 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
{
@autoreleasepool {

if (!_glfw.ns.finishedLaunching)
[NSApp run];

if (!createNativeWindow(window, wndconfig, fbconfig))
return GLFW_FALSE;

Expand Down Expand Up @@ -1477,9 +1474,6 @@ void _glfwPlatformPollEvents(void)
{
@autoreleasepool {

if (!_glfw.ns.finishedLaunching)
[NSApp run];

for (;;)
{
NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny
Expand All @@ -1499,9 +1493,6 @@ void _glfwPlatformWaitEvents(void)
{
@autoreleasepool {

if (!_glfw.ns.finishedLaunching)
[NSApp run];

// I wanted to pass NO to dequeue:, and rely on PollEvents to
// dequeue and send. For reasons not at all clear to me, passing
// NO to dequeue: causes this method never to return.
Expand All @@ -1520,9 +1511,6 @@ void _glfwPlatformWaitEventsTimeout(double timeout)
{
@autoreleasepool {

if (!_glfw.ns.finishedLaunching)
[NSApp run];

NSDate* date = [NSDate dateWithTimeIntervalSinceNow:timeout];
NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny
untilDate:date
Expand All @@ -1540,9 +1528,6 @@ void _glfwPlatformPostEmptyEvent(void)
{
@autoreleasepool {

if (!_glfw.ns.finishedLaunching)
[NSApp run];

NSEvent* event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined
location:NSMakePoint(0, 0)
modifierFlags:0
Expand Down
15 changes: 8 additions & 7 deletions internal/glfw/glfw3_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,14 @@ typedef struct GLFWimage
* bundle, if present. This can be disabled with the @ref
* 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
* application locale according to the current environment if that category is
* still "C". This is because the "C" locale breaks Unicode text input.
Expand Down Expand Up @@ -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/)
* 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
* at full resolution on Retina displays unless the
* [GLFW_COCOA_RETINA_FRAMEBUFFER](@ref GLFW_COCOA_RETINA_FRAMEBUFFER_hint)
Expand Down

0 comments on commit d5f15f9

Please sign in to comment.