Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8280982

[Wayland] [XWayland] java.awt.Robot taking screenshots



    • b26


      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)


        Issue Links



              azvegint Alexander Zvegintsev
              azvegint Alexander Zvegintsev
              0 Vote for this issue
              8 Start watching this issue