Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue when window (on Mac) opens without focus #7949

Merged
merged 1 commit into from Sep 4, 2023
Merged

Conversation

AGulev
Copy link
Contributor

@AGulev AGulev commented Sep 4, 2023

Fixed an issue when a window on Mac opens without focus. In such cases, the window doesn't react to most input events, and only double-click works.

Fix #6709

PR checklist

  • Code
    • Add engine and/or editor unit tests.
    • New and changed code follows the overall code style of existing code
    • Add comments where needed
  • Documentation
    • Make sure that API documentation is updated in code comments
    • Make sure that manuals are updated (in github.com/defold/doc)
  • Prepare pull request and affected issue for automatic release notes generator
    • Pull request - Write a message that explains what this pull request does. What was the problem? How was it solved? What are the changes to APIs or the new APIs introduced? This message will be used in the generated release notes. Make sure it is well written and understandable for a user of Defold.
    • Pull request - Write a pull request title that in a sentence summarises what the pull request does. Do not include "Issue-1234 ..." in the title. This text will be used in the generated release notes.
    • Pull request - Link the pull request to the issue(s) it is closing. Use on of the approved closing keywords.
    • Affected issue - Assign the issue to a project. Do not assign the pull request to a project if there is an issue which the pull request closes.
    • Affected issue - Assign the "breaking change" label to the issue if introducing a breaking change.
    • Affected issue - Assign the "skip release notes" is the issue should not be included in the generated release notes.

@AGulev AGulev requested a review from britzl September 4, 2023 07:58

// Having the app in front of the terminal window is also generally
// handy. There is an NSApplication API to do this, but...
SetFrontProcess( &psn );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetFrontProcess - deprecated

// Eclipse does something similar:
// https://bugs.eclipse.org/bugs/attachment.cgi?id=248969
[NSApp nextEventMatchingMask: NSAnyEventMask untilDate: nil
inMode: NSDefaultRunLoopMode dequeue: NO ];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like this hack doesn't work anymore. I moved part of it to didupdate event

@@ -127,9 +127,17 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende
return NSTerminateCancel;
}

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
[[NSRunningApplication currentApplication] activateWithOptions:(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this event never called

if( !_glfwLibrary.Unbundled ) {
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType( &psn, kProcessTransformToForegroundApplication );
[[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommended function instead of SetFrontProcess() even though it's deprecated as well 🤷‍♂️

// Wait for the first update to make window active
// It helps to avoid issue when the window opens inactive
// https://github.com/defold/defold/issues/6709
if( !_glfwLibrary.Unbundled ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to make sure we call it once

@@ -810,7 +817,6 @@ int _glfwPlatformOpenWindow( int width, int height,
}
_glfwWin.aux_context = [[NSOpenGLContext alloc] initWithFormat:_glfwWin.pixelFormat shareContext:_glfwWin.context];

[_glfwWin.window makeKeyAndOrderFront:nil];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no reason to call it twice

@AGulev AGulev merged commit e0cc73b into dev Sep 4, 2023
23 checks passed
@AGulev AGulev deleted the issue-6709-focus branch September 4, 2023 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non-clickable window when debugging on mac os
2 participants