JDK-8280861 : Robot color picker broken on Linux with scaling above 100%
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: dev,11,17
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • Submitted: 2022-01-28
  • Updated: 2024-08-08
  • Resolved: 2022-02-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 19
19 b11Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
Several tests that use Robot.getPixelColor() or createScreenCapture() fail on Linux with scaling set above 100%:
javax/swing/JPasswordField/TestSelectedTextBackgroundColor.java
javax/swing/JProgressBar/TestJProgressBarHighlightColor.java
javax/swing/JSlider/TestJSliderRendering.java
javax/swing/JSpinner/TestSelectedTextBackgroundColor.java
javax/swing/JTextPane/TestJTextPaneBackgroundColor.java
javax/swing/JToolTip/TestTooltipBackgroundColor.java

The reason for failures is that the coordinates for the tested pixel are incorrect and the returned value, which is usually expected to be different because of a change in state, appears to be the same.

There are also two tests that *should* fail for the same reason, but don't:
java/awt/Robot/HiDPIScreenCapture/HiDPIRobotScreenCaptureTest.java
java/awt/Robot/HiDPIScreenCapture/ScreenCaptureTest.java
That's because the tests only check the color in the middle of a large square and, even if the coordinates are off by a few dozen pixels, the result is as expected. 
However, those two tests fail with scaling set to 300% because of an attempt to capture an image of zero size.
Comments
Test failures caused by this fix are addressed by JDK-8282270.
18-09-2023

Changeset: cc7cf812 Author: Maxim Kartashev <maxim.kartashev@jetbrains.com> Committer: Anton Tarasov <ant@openjdk.org> Date: 2022-02-21 11:39:29 +0000 URL: https://git.openjdk.java.net/jdk/commit/cc7cf81256ed4d74493472017b1c4df20fa2208a
21-02-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/7425 Date: 2022-02-10 14:08:48 +0000
10-02-2022

[~serb] feel free to take it if you want
28-01-2022

There are two bugs here: 1. gtk3_interface.c`gtk3_get_drawable_data() gets the coordinates from Robot that pre-scales them. However, gdk_pixbuf_get_from_window() expects unscaled coordinates _and_ size. The latter had been taken care of in JDK-8225118, but coordinates are still passed scaled. 2. The fix for JDK-8225118 scales down the size of the captured area by the root window scale factor, which can be 3 or more. So when the incoming size is just 1x1 (for instance, from Robot.getPixelColor() ), scaling this down by 3 results in the size of 0x0, which gdk refuses to work with.
28-01-2022