On Thu, 15 Jul 2021 15:48:18 GMT, Ambarish Rapte <ara...@openjdk.org> wrote:

>> On Windows, with two monitors with different DPI settings, if a JavaFX 
>> application changes screens (either by dragging or programmatically) there 
>> is a resize event to adjust the view to its new platform scale.
>> 
>> Note that there is already a 
>> [call](https://github.com/openjdk/jfx/blob/master/modules/javafx.graphics/src/main/java/com/sun/glass/ui/win/WinWindow.java#L206)
>>  to `View::updateLocation` in WinWindow, right after 
>> `notifyMoveToAnotherScreen` and `notifyScaleChanged `. But this is done too 
>> soon, before the resize event. There are other MOVE events processed too (in 
>> a long complex chain of recursive calls to `WinWindow::setBounds`).
>> 
>> As a consequence, as commented in the issue 
>> [JDK-8269374](https://bugs.openjdk.java.net/browse/JDK-8269374), the view 
>> x/y coordinates are wrongly set using the _old_ X,Y values (from the 
>> previous screen) with the _new_ platform scale (from the new screen).
>> 
>> This PR adds an extra call to View::updateLocation` in WinWindow, forcing 
>> the view relocation on Windows after every resize event to fix the issue. 
>> With the correct location of the scene, the Menus are now perfectly aligned, 
>> and the mouse events are correctly processed. It doesn't have any side 
>> effect on other platforms.
>> 
>> There's a very small penalty, as this new relocation will be called whenever 
>> there is a resize event on Windows, but it simplifies the overhead of 
>> detecting when the change of screens is effectively done (including the 
>> chain of move/resize) events.
>> 
>> No tests are provided, since these would require a setup of two monitors 
>> with different DPI settings. However, the test case in the JBS issue can be 
>> used to validate the fix.
>
> I tested the fix with different scaling combinations, the issue reported in 
> JBS does not occur with fix. But noticed a similar issue that occurs only if 
> the primary screen is in landscape mode and external monitor is in portrait 
> mode. This behavior is observed both with and without this change. The 
> behavior may be unrelated to fix, in that it can be addressed separately. 
> @kevinrushforth  request you to take look and call on this.
> 
> Steps:
> 1. Primary screen, 125%, Landscape mode
> 2. Secondary screen, 100%, Portrait mode
> 3. Run the program attached to JBS
> 4. Move the Stage to secondary screen
> 5. Maximize Stage
> 6. Keep focus on the Stage and press Windows + Shift + Left key
> 7. Stage will be moved to primary screen
> 8. Click on menu, observe that location is not correct. Below is screenshot.
> 
> ![image](https://user-images.githubusercontent.com/11330676/125815141-5eeb3f3a-177f-4b09-b746-3a25f63bde44.png)
> 
> ----
> A slight different behavior can be observed with a change in step 6
> Follow same steps as above except at step 6: Click 'Change screen' button. 
> Below is the screenshot
> 
> ![image](https://user-images.githubusercontent.com/11330676/125816635-27176ce3-923e-40f1-a632-8d7b4b30f1b5.png)

I've filed [JDK-8270868](https://bugs.openjdk.java.net/browse/JDK-8270868), and 
also investigated the possible root cause of the issue. It turns out there is a 
reason for the issues @arapte notified, as those happened with a full screen.

-------------

PR: https://git.openjdk.java.net/jfx/pull/572

Reply via email to