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

Popup menu shows on adjacent monitor #177

Closed
stanio opened this issue Sep 21, 2020 · 10 comments
Closed

Popup menu shows on adjacent monitor #177

stanio opened this issue Sep 21, 2020 · 10 comments
Labels
JDK bug there is something wrong in the JDK multi-screen Related to using multiple screens

Comments

@stanio
Copy link

stanio commented Sep 21, 2020

FlatLaf 0.42
Java 11
Windows 10

Steps to reproduce

Have a two-monitor (left and right) setup. Open and maximize the FlatLaf Demo (or another application with a menu-bar) on the ride-side monitor. Start cycling through top-level menus.

Actual results

Some of the (popup) menus get shown on the other (left-side) monitor for no apparent reason.

Details

So far I'm experiencing this with two configurations:

Left monitor: 150%
Right monitor (primary): 200%

Left monitor (primary): 125%
Right monitor: 150%

Maybe the right one should have a greater scaling factor to reproduce as I'm not getting it with:

Left monitor: 150%
Right monitor (primary): 125%

Appears to happen with FlatLaf Demo 0.35 as well. Some of the menus may not show on the other monitor but appear to be aligned on the right-side:

right-aligned-menu

When showing the window on the left-side monitor, the problem is not visible and all menus are left-aligned:

left-aligned-menu

Happens with both "Window decorations" enabled and disabled.

@stanio
Copy link
Author

stanio commented Sep 23, 2020

Some of the menus may not show on the other monitor but appear to be aligned on the right-side

I'm seeing this only with the 125%, 150% (left, right) monitor configuration, so far.

@DevCharly
Copy link
Collaborator

Hmm, strange. Can not reproduce it...

Does this also happen with Metal or Windows LaFs?
You can switch to those LaFs in FlatLaf Demo using the bottom-left combobox.

What Java distro do you use? AdoptOpenJDK? Or other?

Could you please run FlatScreenInfo.java on your computer, with the same Java version, and post the output here?
This program outputs detailed information about the connected screens.
With this information I can configure the same setup an try to reproduce the issue.
All you need to run the program is FlatScreenInfo.java because it does not have any dependencies.

@stanio
Copy link
Author

stanio commented Sep 23, 2020

Should have tried this already before – appears to happen with Metal and the Windows LaFs as well, so it doesn't appear FlatLaf specific.

I'm using Oracle's JDK. Here are the FlatScreenInfo outputs:

Scale factors:  200% / 150%
Java version:   11.0.7

ID:      \Display0 (main)
Size:    2880 x 1620 / 32 Bit / 60 Hz
Bounds:  1440 x 810 / x 0 / y 0   (scale -2.0)
Insets:  left 0 / right 0 / top 0 / bottom 80
Scale:   2.0

ID:      \Display1
Size:    1920 x 1080 / 32 Bit / 60 Hz
Bounds:  1280 x 720 / x -1280 / y -177   (scale -1.5)
Insets:  left 0 / right 0 / top 0 / bottom 0
Scale:   1.5
Scale factors:  125% / 150%
Java version:   11.0.7

ID:      \Display0 (main)
Size:    1920 x 1080 / 32 Bit / 60 Hz
Bounds:  1536 x 864 / x 0 / y 0   (scale -1.25)
Insets:  left 0 / right 0 / top 0 / bottom 50
Scale:   1.25

ID:      \Display1
Size:    1920 x 1080 / 32 Bit / 60 Hz
Bounds:  1280 x 720 / x 1280 / y 0   (scale -1.5)
Insets:  left 0 / right 0 / top 0 / bottom 0
Scale:   1.5

I'll try to update to JDK 11.0.8 to see if it would make any difference... but then it doesn't appear a FlatLaf problem.

@DevCharly
Copy link
Collaborator

Ok, can now reproduce it with your second screen configuration.

Occurs also in Oracle JDK 11.0.8 and in AdoptOpenJDK 11.0.8.
And also in OpenJDK 14.0.2 and 15.

But works in JetBrains Runtime 11.0.8 (bundled in IDEA 2020.2.2)

@stanio
Copy link
Author

stanio commented Sep 23, 2020

Thanks for looking into it. Please, close at your discretion.

@DevCharly
Copy link
Collaborator

Just compared screen info of Oracle JDK with JetBrains Runtime:

image

The interesting thing is the difference in the X location of the second screen.
In Oracle JDK it is 1280, but the width of the first screen is 1536.
So the first screen partly overlaps the second screen in virtual coordinate system!

In JetBrains Runtime the X location of second screen is 1920 and the two screens do not overlap. This is better, but also strange because in virtual coordinate system I would expect 1536...

The wrong menu positioning happens in method JMenu.getPopupMenuOrigin(), which first searches for a screen that contains the popup x/y coordinates and then corrects x/y so that the popup fits into the screen. In case of "overlapping" screens, the first screen is found and x is made smaller...

This has actually nothing to do with maximized windows. Occurs also in not maximized windows:

image

Also occurs for other popups. E.g. comboboxes:

image

@stanio
Copy link
Author

stanio commented Sep 23, 2020

In JetBrains Runtime the X location of second screen is 1920 and the two screens do not overlap. This is better, but also strange because in virtual coordinate system I would expect 1536...

Yeah, I would expect 1536 for the second monitor offset as well. I see the bounds reported are in virtual (screen?) coordinates (according to the width and height reported) but the GraphicsConfiguration.getBounds() is confusing:

Returns the bounds of the GraphicsConfiguration in the device coordinates.

I guess device coordinates should match the physical size reported but then it would be "impossible" to correctly position stuff.

@DevCharly
Copy link
Collaborator

Yea, that's confusing. The documentation is not clear IMHO...

@grimlock81
Copy link

I think it's related to this OpenJDK issue openjdk/jdk#375

@DevCharly
Copy link
Collaborator

@grimlock81 thx for the link. Good news that a fix is (hopefully) coming to Java 16...

Here is the JDK issue: https://bugs.openjdk.java.net/browse/JDK-8211999

@DevCharly DevCharly added JDK bug there is something wrong in the JDK multi-screen Related to using multiple screens labels Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JDK bug there is something wrong in the JDK multi-screen Related to using multiple screens
Projects
None yet
Development

No branches or pull requests

3 participants