Details
-
Type:
Bug
-
Status: Open
-
Priority:
P3
-
Resolution: Unresolved
-
Affects Version/s: internal
-
Fix Version/s: internal
-
Component/s: client-libs
-
Labels:
-
Subcomponent:
Description
The java.awt.Robot class provides createScreenCapture() method which currently uses X11-specific APIs.
Use xdg-desktop-portal, a cross-platform stable D-Bus API which works on GNOME, KDE and wlroots-based compositors.
Specifically, it provides [org.freedesktop.portal.Screenshot]( https://flatpak.github.io/xdg-desktop-portal/portal-docs.html#gdbus-org.freedesktop.portal.Screenshot ) which can be used to create a screenshot.
However, it has significant drawbacks(at least on Gnome):
It asks a confirmation on each screenshot request, so it is unusable for automated testing.
It does not allow to take a specified screen area, only whole screen.
A user can deny the request. In this case as a possible solution we can throw a SecurityException for Robot#createScreenCapture (javadoc update required). Currently it is thrown only if readDisplayPixels permission is not granted(which is not suitable here).
There is also [org.freedesktop.portal.Screenshot#PickColor]( https://flatpak.github.io/xdg-desktop-portal/#gdbus-method-org-freedesktop-portal-Screenshot.PickColor ) API which can't be used for Robot#getPixelColor needs. It does not allow to take a pixel color at specified location, but interactively asks a user to pick a color with mouse cursor.
Use xdg-desktop-portal, a cross-platform stable D-Bus API which works on GNOME, KDE and wlroots-based compositors.
Specifically, it provides [org.freedesktop.portal.Screenshot]( https://flatpak.github.io/xdg-desktop-portal/portal-docs.html#gdbus-org.freedesktop.portal.Screenshot ) which can be used to create a screenshot.
However, it has significant drawbacks(at least on Gnome):
It asks a confirmation on each screenshot request, so it is unusable for automated testing.
It does not allow to take a specified screen area, only whole screen.
A user can deny the request. In this case as a possible solution we can throw a SecurityException for Robot#createScreenCapture (javadoc update required). Currently it is thrown only if readDisplayPixels permission is not granted(which is not suitable here).
There is also [org.freedesktop.portal.Screenshot#PickColor]( https://flatpak.github.io/xdg-desktop-portal/#gdbus-method-org-freedesktop-portal-Screenshot.PickColor ) API which can't be used for Robot#getPixelColor needs. It does not allow to take a pixel color at specified location, but interactively asks a user to pick a color with mouse cursor.