Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,8 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
// but it doesn't get activated, so this is needed:
LOG("-> need to active application");
dispatch_async(dispatch_get_main_queue(), ^{
[NSApp performSelector: @selector(activate)];
[NSApp activateIgnoringOtherApps:YES];
Copy link
Contributor

Choose a reason for hiding this comment

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

should we add a comment about possible removal of this API in newer platforms?
(I would suggest also include the JBS reference so the context can be obtained by the person who will be fixing this code in the future).

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't want to do either of these in this PR. My comment in the PR Description about possible API removal is independent of this bug and something I just happened to notice -- plus it's speculative on my part. I will file a follow-on place-holder bug for this, but there isn't anything actionable at this point. Also, I don't like the practice of putting bug IDs in for fixed bugs except in unusual cases (this isn't one of them).

Copy link
Member Author

Choose a reason for hiding this comment

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

I filed JDK-8348878 to track our use of the deprecated [NSApp activateIgnoringOtherApps] method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, one can typically rely on git history to make connection to the original PR/JBS. The problem is that a merge might make this information not (easily) accessible.
And yes, the comments are subject to the usual decay, when they lose the relevance (or stop being applicable), but at least one can easily find the original issue and related discussion.

Just my two yen.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see that the CanvasTest mentioned in the JBS issue passes now with this fix, and fails with [NSApp activate];

I'm not sure why [NSApp activateIgnoringOtherApps:YES]; works but [NSApp activate]; doesn't, given that the former is deprecated, as you already mentioned, and the latter is what Apple precisely recommends to use instead.
In any case, probably something for https://bugs.openjdk.org/browse/JDK-8348878.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jperedadnr can you add this comment to https://bugs.openjdk.org/browse/JDK-8348878 please?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure why [NSApp activateIgnoringOtherApps:YES]; works but [NSApp activate]; doesn't, given that the former is deprecated, as you already mentioned, and the latter is what Apple precisely recommends to use instead.

The default activation mode is to only activate only when no other app is active, after first deactivating the launching application. This is true for the new activate method as well as the existing activateWithOptions method. [NSApp activate] is equivalent to [NSApp activateIgnoringOtherApps:NO].

The activateIgnoringOtherApps method says this:

By default, activation deactivates the calling app (assuming it was active), and then the new app is activated only if there’s no currently active application. This prevents the new app from stealing focus from the user, if the app is slow to activate and the user has switched to a different app in the interim. However, if you specify NSApplicationActivateIgnoringOtherApps, the application is activated regardless of the currently active app, potentially stealing focus from the user.

Let's continue looking into this in the context of JDK-8348878.

});
// TODO: performSelector is used only to avoid a compiler
// warning with the 13.3 SDK. After updating to SDK 14
// this can be converted to a standard call.
}
}

Expand Down