JDK-8280982 : [Wayland] [XWayland] java.awt.Robot taking screenshots
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 21
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-01-31
  • Updated: 2025-02-12
  • Resolved: 2023-06-07
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 11 JDK 17 JDK 21 JDK 8
11.0.26-oracleFixed 17.0.13-oracleFixed 21 b26Fixed 8u441Fixed
Related Reports
Blocks :  
Blocks :  
CSR :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Modern Linux systems often come with [Wayland](https://wayland.freedesktop.org/) by default.
This comes with some difficulties, and one of them is the inability to get screenshots from the system.
This is because we now use the [X Window System API](https://en.wikipedia.org/wiki/X_Window_System) to capture screenshots and it cannot access data outside the [XWayland server](https://wayland.freedesktop.org/xserver.html) 

But this functionality is a very important part of automated testing.


At the moment there are two obvious solutions to this problem, and both use [xdg-desktop-portal](https://github.com/flatpak/xdg-desktop-portal):

1. [org.freedesktop.portal.Screenshot DBUS API](https://flatpak.github.io/xdg-desktop-portal/#gdbus-org.freedesktop.portal.Screenshot)
It has several drawbacks though:
+ It saves a screenshot to disk, which must be read and deleted(may add some delays depending on the type of a disk drive).
+ There is no way to disable the visual "screen flash" after screenshot
+ It asks a user confirmation to save a screenshot. This confirmation can be saved on Gnome 43+. 
Since we would like Ubuntu 22.04 LTS which comes with Gnome 42 this option is not acceptable for us because it would require user confirmation for each screenshot.
But we still can consider this option as a fallback.



2. [org.freedesktop.portal.ScreenCast](https://flatpak.github.io/xdg-desktop-portal/#gdbus-org.freedesktop.portal.ScreenCast)
It typically used by applications that need to capture the contents of the user's screen or a specific window for the purpose of sharing, recording, or streaming.
This might be a bit of overkill, but it avoids several of the problems mentioned in the Screenshot API.

+ implementation is more complicated comparing to Screenshot API
+ no intermediate file, screenshot data can be obtained from memory
+ Permission to make screenshots can be stored with [`restore_token`](https://flatpak.github.io/xdg-desktop-portal/#gdbus-method-org-freedesktop-portal-ScreenCast.SelectSources)
Comments
jdk17u-dev backport request I would like to have the patch in jdk17u-dev as well, for parity with OracleJDK. The backport is clean and medium risk.
10-07-2024

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk17u-dev/pull/2700 Date: 2024-07-09 10:49:06 +0000
09-07-2024

Looks like this breaks the AIX build. I created JDK-8309703 .
09-06-2023

Changeset: 9d7bf532 Author: Alexander Zvegintsev <azvegint@openjdk.org> Date: 2023-06-07 13:08:11 +0000 URL: https://git.openjdk.org/jdk/commit/9d7bf5329e5a0393553bca2e3a51ad1125b41b96
07-06-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/13804 Date: 2023-05-04 14:20:30 +0000
04-05-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/13803 Date: 2023-05-04 14:18:44 +0000
04-05-2023