I am probably not completely sure what you are specifically looking to do. But to print the entire screen, I just use the “Print Scr” key on my keyboard. That captures the whole screen and automatically saves it to the Pictures folder in your home directory.
I am not a Java expert but I would guess that telling AWT to operate in headless mode is designed to make it work without touching/needing a real display, in which case it may not be surprising that it can’t take a screenshot of the real display.
@wjt thank you for the reply! I still can’t take a screenshot You are right. Enabling headless mode is wrong. But in this case nothing is happens. Just flashing cursor in the terminal…
gnome-screenshot has non-disabling animation. And that’s a slightly different story to call terminal commands in Java.
I searched the app center for other screenshot apps. I found ksnip which seems to work OK and did not flash the screen:
wjt@camille:~$ flatpak run org.ksnip.ksnip --fullscreen --save
Warning: QSocketNotifier: Can only be used with threads started with QThread
Info: Image Saved: Saved to /sysroot/home/wjt/ksnip_20210914-194547.png
Or do you specifically need a Java API to take a screenshot? If you are working on a Java app I would personally not use the eos3.2 runtime but instead org.freedesktop.Sdk.Extension.openjdk
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.ImageIO;
public class test001
{
public static void main(String[] args) throws AWTException,IOException
{
BufferedImage image=(new Robot()).createScreenCapture(
new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ImageIO.write(image,"jpg",new File("screenshot.jpg"));
}
}
(i assume you have put the source code provided into a file called test001.java)
flatpak run --filesystem=home --command=/usr/lib/sdk/openjdk/bin/javac org.freedesktop.Sdk test001.java
Run the Demo
flatpak run --filesystem=home --socket=x11 --command=/usr/lib/sdk/openjdk/bin/java org.freedesktop.Sdk test001
This will capture a Screenshot and write it to the same location as the class file. Please also note, that taking a screenshot currently only works with X11 not with Wayland
Thank you all for help! According to your commands SDK and OpenJDK Extension have been installed successfully:
user@endless1:~$ flatpak run --filesystem=home --command=/usr/lib/sdk/openjdk/bin/java org.freedesktop.Sdk -version
openjdk version “16.0.1” 2021-04-20
OpenJDK Runtime Environment 21.3 (build 16.0.1+9)
OpenJDK 64-Bit Server VM 21.3 (build 16.0.1+9, mixed mode, sharing)
But my Jar and demo code gets the same error with double output:
user@endless1:~$ flatpak run --filesystem=home --socket=x11 --command=/usr/lib/sdk/openjdk/bin/java org.freedesktop.Sdk test001
Gtk-Message: 16:27:15.630: Failed to load module “canberra-gtk-module”
Gtk-Message: 16:27:15.630: Failed to load module “canberra-gtk-module”
I tried to install the module with the command user@endless1:~$ sudo flatpak install -y ibcanberra-gtk-module that was not successful.
Do you know from which repository I can install the missing module?
The current repositories are presented below:
user@endless1:~$ flatpak remotes
Name Parameters
eos-apps system
eos-runtimes system
eos-sdk system
flathub system
Addition:
The link says that
The warning about canberra-gtk-module is because the gtk module is installed on your system, but isn’t available in flatpak. I also noticed it only happens on X11, and not on wayland.
I tried to remove the module on the advice, but it was not installed:
user@endless1:~$ sudo flatpak remove libcanberra-gtk-module
error: libcanberra-gtk-module/unspecified/unspecified not installed
Ignore the canberra error. It’s thrown because the module is not available in the Runtime used by the application in question - in a Flatpak environment, everything need to be available either directly in the flatpak or in the runtime.
You can’t install it seperatly like in Ubuntu per Design.
The canberra library is sometimes used by GTK applications to provide playback of event sounds as a fallback method, so it shouldn’t be a issue if it’s not there.
I’m so sorry! I found all my screenshots They also worked on eos3.2 SDK. And the canberra module error message appears only once on first screenshot (attempt to an audio notification) when the program is still running (no crash exceptions). I found out this by implementing logging on every programm string.
The next problem is that I was unable to set the program at system startup. I put the startup command in the bash script scr.sh
#!/bin/bash
flatpak run --filesystem=home --socket=x11 --command=/usr/lib/sdk/openjdk/bin/java org.freedesktop.Sdk -jar Desktop.Monitor/Screenshoter.jar
EOS (like any other modern Linux) uses systemd instead of classical SysV init, so the init.d scripts shouldn’t be used anymore (even if they are still supported in some quirky way by systemd for compatibility reasons)
You need to make sure that at execution time, X already has been brought up, so instead you should rely on GDM Autostart files (https://help.gnome.org/admin/gdm/stable/configuration.html.en#autostart)
2.1 The directories mentioned in the above documentation are read-only on EOS due to it’s architecture, so you need another way
2.2. This way is probably using some systemd unit which has a dependency on gdm (haven’t tested this out yet)
Can you please tell us more abou the desired solution you want to implement? What’s the goal? Eventually there are other ways of accomplishing it.
Thank you for your desire to help! The goal is to control the staff. I need to take screenshots at a specified frequency after the system boots.
Due to the restrictions on autorun, periodical screenshots in the chrome browser using the extension are also suitable. But google chrome webstore contains extensions that take one screenshot at the user’s command. Or I didn’t search well.
Apparently I should master javascript to write own extension? Perhaps there are other solutions?