<AWT Dev> RFR: 8257414: Drag n Drop target area is wrong on high DPI systems [v2]

Sergey Bylokhov serb at openjdk.java.net
Sat Feb 6 02:35:43 UTC 2021

On Tue, 2 Feb 2021 22:53:57 GMT, Olga Mikhaltsova <omikhaltcova at openjdk.org> wrote:

>> Please, review this small fix for drag-n-drop on Linux with HiDPI turned on!
>> This bug is due to the following reason: while scaling Java recalculates resolution (W x H) according to sun.java2d.uiScale (W/SCALE x H/SCALE) and works inside these new coordinates but at the same time the events, that come from the system, continue reporting positions in the old coordinates (W x H).
>> The idea of the suggested fix is in division of coordinates on the scale when they come from the system to Java and multiplying them on the scale when they go back from Java to the system. It is similar to processing events from mouse and buttons. 
>> Testing is quite complicated because for reproducing this bug the following conditions should be met:
>> 1.	HiDPI is turned on
>> 2.	sun.java2d.uiScale.enabled = true and sun.java2d.uiScale != 100%
>> 3.	the source of drag-n-drop is non-java application
>> The step-by-step guide how to reproduce this bug is added to https://bugs.openjdk.java.net/browse/JDK-8257414.
> Olga Mikhaltsova has updated the pull request incrementally with one additional commit since the last revision:
>   8257414: Drag n Drop target area is wrong on high DPI systems

src/java.desktop/unix/classes/sun/awt/X11/XDnDDropTargetProtocol.java line 618:

> 616:             try {
> 617:                 for (int i = 0; i < gdslen; i++) {
> 618:                     long screenRoot = XlibWrapper.RootWindow(display, i);

I am not sure this will work in the multi-monitors configuration when the screen is split across a few monitors(when Xinerama is enabled for example). In such a configuration, only one root window and only one X11 screen exist. And the index of the GraphicsDevice is the index of the "virtual" monitor, so you cannot pass this index to the "XlibWrapper.RootWindow".

A few questions:
* Are you sure that to scale the x/y in the device space you need to find where the pointer is located? And not where the x/y coordinates are located themselves?
* Did you try to iterate over the devices->downscale the bounds of each GD to the device scale and upscale the x/y using the selected device. Such utility method can be added to the SunGraphicsEnvironment


PR: https://git.openjdk.java.net/jdk/pull/1907

More information about the awt-dev mailing list