Robot's screenshot fails if you are using fractional scaling in Wayland

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Arch Linux, KDE Plasma 6.5.5

      A DESCRIPTION OF THE PROBLEM :
      If you are using KDE Plasma with fractional scaling (I use 150%, this probably affects other compositors too) the capture will always fail with

          callbackScreenCastStart:745 available screen count 1
          rebuildScreenData:116
          ==== screenId#98
          rebuildScreenData:161 -----------------------
          rebuildScreenData:162 screenId#98
          || bounds x 0 y 0 w 1707 h 960
          || capture area x 0 y 0 w 0 h 0 shouldCapture 0
          
          rebuildScreenData:163 #---------------------#
          
          callbackScreenCastStart:751 rebuildScreenData result |0|
          callbackScreenCastStart:764 restore_token |5b0f7d56-d05f-483e-a85a-99727b3a36f6|
          storeRestoreToken:805 saving token, old: |16521d36-3b86-4b25-b990-319ce54e3283| > new: |5b0f7d56-d05f-483e-a85a-99727b3a36f6|
          portalScreenCastStart:843 ScreenCastResult |0|
          initAndStartSession:1116 portalScreenCastStart result |0|
          checkCanCaptureAllRequiredScreens:991 Could not find required screen 0 0 2560 1440 in allowed bounds
          getPipewireFd:1132 The location of the screens has changed, the capture area is outside the allowed area.
          Java_sun_awt_screencast_ScreencastHelper_getRGBPixelsImpl:1036 Screencast attempt failed with -12, re-trying...

      The reason is because it keeps trying to find the bounds with the "logical" resolution size (the size without any scaling) and it keeps failing because the Screencast API gives the scaled resolution size.

      Using the default non-scaled resolution fixes the issue.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Set your monitor scaling in Plasma to anything larger than 100%
      2. Create a Robot instance
      3. Try capturing a screenshot with "createScreenCapture"

      ---------- BEGIN SOURCE ----------
      import javax.imageio.ImageIO;
      import java.awt.*;
      import java.awt.image.BufferedImage;
      import java.io.File;
      import java.io.IOException;

      public class CaptureBug {
          public static void main(String[] args) throws AWTException, IOException {
              Robot robot = new Robot();
              BufferedImage image = robot.createScreenCapture(new Rectangle(128, 128));

              ImageIO.write(image, "png", new File("capture.png"));
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Setting the scaling resolution to 100%

      FREQUENCY :
      ALWAYS

            Assignee:
            Alexander Zvegintsev
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: