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

8346281: [Windows] RenderScale doesn't update to HiDPI changes #1668

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jperedadnr
Copy link
Collaborator

@jperedadnr jperedadnr commented Dec 23, 2024

This PR adds the missing native implementation for Windows GlassWindow::HandleDPIEvent, to notify the (Java) window when there is a DPI change event, which can happen when the user changes the resolution of the screen (via Settings -> System -> Display -> scale), while the JavaFX application is running.

When such WM_DPICHANGED event happens, GlassWindow::HandleDPIEvent notifies the (Java) window, which changes its platform scale via Window::notifyScaleChanged, and GlassScreen::HandleDisplayChange(); is needed too, to update the platform scale of the screen where the window is at as well.

There are no tests added to this PR, since these would require manual intervention to change the display. In any case, the test case added to the issue runs fine now when the app runs on a given screen and the user changes its resolution.

There is a follow-up issue after this PR, that might require a more complex fix, for the case where the user changes the resolution of a different screen that is placed before the one that has the application (as location coordinates of the latter depend on the former), because there is no WM_DPICHANGED event in this case.


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-8346281: [Windows] RenderScale doesn't update to HiDPI changes (Bug - P4)(⚠️ The fixVersion in this issue is [jfx25] but the fixVersion in .jcheck/conf is jfx24, a new backport will be created when this pr is integrated.)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1668

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 23, 2024

👋 Welcome back jpereda! 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 Dec 23, 2024

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the rfr Ready for review label Dec 23, 2024
@mlbridge
Copy link

mlbridge bot commented Dec 23, 2024

Webrevs

@andy-goryachev-oracle
Copy link
Contributor

/reviewers 2

@openjdk
Copy link

openjdk bot commented Dec 23, 2024

@andy-goryachev-oracle
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).

@@ -209,6 +209,10 @@ LRESULT CALLBACK GlassWindow::CBTFilter(int nCode, WPARAM wParam, LPARAM lParam)
return ::CallNextHookEx(GlassWindow::sm_hCBTFilter, nCode, wParam, lParam);
}

#ifndef USER_DEFAULT_SCREEN_DPI
#define USER_DEFAULT_SCREEN_DPI 96
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this value come from some windows header?

@andy-goryachev-oracle
Copy link
Contributor

please add the test case to https://bugs.openjdk.org/browse/JDK-8346281

@andy-goryachev-oracle
Copy link
Contributor

Does not seem to work. Here is my scenario:

  1. win11 with two monitors, the built-in laptop screen at scale 100%, the external monitor at 225% (located "above" the build-in one).
  2. the monkey tester opens up on the external monitor (since it remembers its position between launches)
  3. when the user clicks on the menu, the menu pops up in the wrong location (way outside of the main window in fact)
  4. change resolution to 200%
  5. click on the menu, the menu also appears in the wrong location
  6. it's only after I drag the window to the main monitor the menus start appearing at the right location. drag it back to the external monitor, the menu appears at the correct location again.
  7. change external scale back to 225%, the menu opens up at the right location.

@jperedadnr
Copy link
Collaborator Author

I've added the test case to the JBS issue (sorry about that, I thought I did when I created it).

About the test case scenario:

  • you have a JavaFX application already running in a given monitor
  • without changing resolution, the label shows the current output scale, and the menu popup shows up in the correct position (if it doesn't, this is a different issue than this one).
  • Then, after showing the menu at least once, you change the screen resolution (the screen that has the app, that is)

With this PR you should see:

  • the label showing the correct output scale once you change the resolution (this doesn't happen without the PR),
  • and the menu popup showing up at the correct position (this doesn't happen without the PR).

@andy-goryachev-oracle
Copy link
Contributor

andy-goryachev-oracle commented Dec 23, 2024

hmm, not sure where the disconnect is.

  • before I launch the monkey tester, there is no fx app running anywhere
  • the monkey tester appears on the external monitor, it's status bar shows scale 2.25
  • the menu appears in the wrong location

let me try attaching the screenshot:

Screenshot 2024-12-23 132020

@jperedadnr
Copy link
Collaborator Author

Do you have the same issue (unexpected offset for the popup) as well without this PR?

@andy-goryachev-oracle
Copy link
Contributor

I think the difference between your scenario and mine is that the monkey tester appears on the external monitor instead of the main one.

If I close the monkey tester while it is on the primary laptop screen and restart it, the menu shows up at the right location from the start.

Maybe you can change your test app to open one window on each screen?

@andy-goryachev-oracle
Copy link
Contributor

Do you have the same issue (unexpected offset for the popup) as well without this PR?

The behavior is different. With the MT showing up on the external monitor, the initial location of the menus is correct. Once I change the scale, the menus pop up in two wrong location above and to the left (the change in scale was 2.25 -> 1.5)

@andy-goryachev-oracle
Copy link
Contributor

attached an updated SCCE to the ticket. the initial scale value seems to be incorrect in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rfr Ready for review
Development

Successfully merging this pull request may close these issues.

2 participants