Bug 474778 - X11Output does not have its scale set
Summary: X11Output does not have its scale set
Status: RESOLVED INTENTIONAL
Alias: None
Product: kwin
Classification: Plasma
Component: general (show other bugs)
Version: git master
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-09-22 01:04 UTC by Noah Davis
Modified: 2023-10-12 07:13 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Noah Davis 2023-09-22 01:04:04 UTC
SUMMARY
In X11StandaloneBackend::doUpdateOutputs(), X11Output::State::scale is never set, leaving it at the default 1.0 value.
This causes CaptureArea and CaptureWorkspace from the ScreenShot2 DBus API to return an incorrect image in a Plasma 6 X11 session when the global scale is not 100%.

STEPS TO REPRODUCE
1. In the Display Configuration KCM, set the global scale to 125%.
2. Reboot and log into a Plasma 6 X11 session.
3. Run `spectacle -if` to take a screenshot of the whole workspace.

OBSERVED RESULT
The image is smaller than it should be and doesn't actually contain the whole workspace.

EXPECTED RESULT
The image should have a size equal to the virtual desktop size multiplied by the highest screen scale in the virtual desktop. The image should also contain the whole workspace.

SOFTWARE/OS VERSIONS
Operating System: openSUSE Tumbleweed 20230917
KDE Plasma Version: 5.27.80
KDE Frameworks Version: 5.240.0
Qt Version: 6.5.2
Kernel Version: 6.5.3-1-default (64-bit)
Graphics Platform: X11
Processors: 16 × AMD Ryzen 7 4800H with Radeon Graphics
Memory: 30.8 GiB of RAM
Graphics Processor: AMD Radeon Graphics

ADDITIONAL INFORMATION
If you put `qDebug() << output->scale()` in X11StandaloneBackend::doUpdateOutputs() to get the scales of the outputs, you will see that it is always 1.0
Comment 1 Noah Davis 2023-09-22 01:44:21 UTC
In `QFuture<QImage> ScreenShotEffect::scheduleScreenShot(const QRect &area, ScreenShotFlags flags)`, if I use QScreen::devicePixelRatio() to get the screen scales, then the returned image is correct. It currently uses KWin::EffectScreen::devicePixelRatio(), which gets its value from the scale for the platform dependent KWin::Output subclass.
Comment 2 David Edmundson 2023-10-02 13:11:22 UTC
1.0 is expected. 
Logical and device pixels are the same.

Can you expand on 

>to return an incorrect image
Comment 3 Noah Davis 2023-10-02 20:02:41 UTC
(In reply to David Edmundson from comment #2)
> 1.0 is expected. 
> Logical and device pixels are the same.
> 
> Can you expand on 
> 
> >to return an incorrect image

The image is smaller than it should be and doesn't actually contain the whole workspace.

For example, let's say you have two 1920x1080 screens horizontally next to each other with 1.25x scale. The unscaled virtual desktop size is 3840x1080. If you get an image of the whole workspace, you get a 3072x864 image with the right and bottom parts of the workspace cut off. This is different from the behavior on Wayland where the image dimensions match the unscaled virtual desktop size and the image contains the entire workspace. I looked at the code and the reason why is because WaylandOutput gives a correct device pixel ratio, but the X11Output does not, even though QScreen gives a correct device pixel ratio on X11. I think QScreen has different results from X11Output because plasma-workspace/startkde/startplasma-x11.cpp sets QT_SCREEN_SCALE_FACTORS using the settings defined using the Display Configuration KCM.
Comment 4 Vlad Zahorodnii 2023-10-05 11:53:34 UTC
X11Output::scale() returning 1 on X11 is fully intentional and I'm afraid that we cannot change it as it's going to have some repercussions. Maybe spectacle needs to handle this case somehow.

---

Removing qt6 because it's not really a new Plasma 6 issue. kwin has been behaving like this forever.
Comment 5 Noah Davis 2023-10-05 12:21:37 UTC
(In reply to Vlad Zahorodnii from comment #4)
> X11Output::scale() returning 1 on X11 is fully intentional and I'm afraid
> that we cannot change it as it's going to have some repercussions. Maybe
> spectacle needs to handle this case somehow.
> 
> ---
> 
> Removing qt6 because it's not really a new Plasma 6 issue. kwin has been
> behaving like this forever.

Spectacle can't handle it because the image it gets is faulty, as described above. The issue only occurs on X11 with scaling. I suppose we could make the ScreenShot2 effect use QScreen instead of EffectScreen to get screen geometry.