Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements a new "ScreenShotUtil" class that implements a CreateScreenShot method that will take a screenshot in the typical way using a
java.awt.Robot
on every desktop platform short of Wayland, this returns aBufferedImage
, as expected.Due to some bugs with how Wayland screenshots are handled in Java proper: https://bugs.openjdk.org/browse/JDK-8269245
We have to call the desktop bus (dbus) to request for the compositor to take a screenshot.
The screenshot is taken as a PNG image and dbus will tell us where that image is. That image is ingested as a
BufferedImage
and the PNG we took is deleted from the system. TheBufferedImage
is returned, which is what a Robot would normally do.I also ran into a fun edge case where writing a
BufferedImage
with an alpha channel (like one we might get when reading a PNG) to a JPG silently fails, which causes themy-images/
folder to not be populated as expected.I wrote a small helper method to strip out the alpha channel to avoid this:
sc-trade-companion/src/main/java/tools/sctrade/companion/utils/ImageUtil.java
Lines 257 to 262 in f714efb
This PR pulls in the
dbus-java
library, which allows us to interface with dbus directly instead of talking to a potentially missing executable, which is the most portable way to do this.This change adds approx 1MiB to the final jarfile.