Skip to content

Conversation

@kevinrushforth
Copy link
Member

@kevinrushforth kevinrushforth commented Jan 28, 2025

The fix for JDK-8319066 added a needed call to activate a JavaFX window on macOS 14 or later via [NSApp activate]. In macOS 15, this doesn't always activate the window; even on macOS 14 there are certain cases where it might not. In all other places where we need to activate a window we call [NSApp activateIgnoringOtherApps:YES]. This is also what AWT uses in all places.

The fix is to replace the call to activate with a call to activateIgnoringOtherApps. I ran a full set of headful tests on macOS 15, 14, and 13 (although the code is not executed on macOS 13), and everything looks good on my end.

Worth noting is that NSApp::activateIgnoringOtherApps is deprecated as of MacOS SDK 14, which means that we might have problems in the future when we update the Xcode toolchain (or if they eventually degrade it so that the ignoringOtherApps part of this call stops doing anything), but that will be a problem we need to address anyway, affecting other places in JavaFX and AWT.

I intend to backported this fix to jfx24 after it is integrated into mainline (for 25).

/reviewers 2


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8348744: Application window not always activated on macOS 15 (Bug - P3)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1685/head:pull/1685
$ git checkout pull/1685

Update a local copy of the PR:
$ git checkout pull/1685
$ git pull https://git.openjdk.org/jfx.git pull/1685/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1685

View PR using the GUI difftool:
$ git pr show -t 1685

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1685.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 28, 2025

👋 Welcome back kcr! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jan 28, 2025

@kevinrushforth This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8348744: Application window not always activated on macOS 15

Reviewed-by: angorya, jpereda

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@kevinrushforth
Copy link
Member Author

Reviewers: @andy-goryachev-oracle @jperedadnr

@openjdk openjdk bot added the rfr Ready for review label Jan 28, 2025
@openjdk
Copy link

openjdk bot commented Jan 28, 2025

@kevinrushforth
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

@mlbridge
Copy link

mlbridge bot commented Jan 28, 2025

Webrevs

Copy link
Contributor

@andy-goryachev-oracle andy-goryachev-oracle left a comment

Choose a reason for hiding this comment

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

works as expected (test app stage gets focused even when the terminal window running the test script loses focus) on macOS 15.1.1 M1, running the following script:

#! /bin/bash

set -x

sleep 5
gradle --continue --info -PBUILD_TOOLS_DOWNLOAD_SCRIPT=../build-tools.gradle -PTEST_ONLY=true -PFULL_TEST=true -PUSE_ROBOT=true :systemTests:test --tests CSSRoundingTest

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.

LOG("-> need to active application");
dispatch_async(dispatch_get_main_queue(), ^{
[NSApp performSelector: @selector(activate)];
[NSApp activateIgnoringOtherApps:YES];
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.

@kevinrushforth
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Jan 29, 2025

Going to push as commit f55f5c6.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jan 29, 2025
@openjdk openjdk bot closed this Jan 29, 2025
@openjdk openjdk bot removed ready Ready to be integrated rfr Ready for review labels Jan 29, 2025
@openjdk
Copy link

openjdk bot commented Jan 29, 2025

@kevinrushforth Pushed as commit f55f5c6.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@kevinrushforth kevinrushforth deleted the 8348744-macos15-activation branch January 29, 2025 13:16
@kevinrushforth
Copy link
Member Author

/backport :jfx24

@openjdk
Copy link

openjdk bot commented Jan 29, 2025

@kevinrushforth the backport was successfully created on the branch backport-kevinrushforth-f55f5c60-jfx24 in my personal fork of openjdk/jfx. To create a pull request with this backport targeting openjdk/jfx:jfx24, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit f55f5c60 from the openjdk/jfx repository.

The commit being backported was authored by Kevin Rushforth on 29 Jan 2025 and was reviewed by Andy Goryachev and Jose Pereda.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jfx:

$ git fetch https://github.com/openjdk-bots/jfx.git backport-kevinrushforth-f55f5c60-jfx24:backport-kevinrushforth-f55f5c60-jfx24
$ git checkout backport-kevinrushforth-f55f5c60-jfx24
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jfx.git backport-kevinrushforth-f55f5c60-jfx24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants