Bug 429236

Summary: Screen layout is scrambled after switching between X11 and Wayland Plasma session
Product: [Plasma] KScreen Reporter: Vlad Zahorodnii <vlad.zahorodnii>
Component: commonAssignee: kscreen-bugs-null <kscreen-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: 9luty1992, admin, alex765, ashark, butirsky, guido-kdebugs, katyaberezyaka, kman, lrdarknesss, michele.kipiel, nate, sitter, vityas_official
Priority: NOR    
Version: git   
Target Milestone: ---   
Platform: Other   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=433460
Latest Commit: Version Fixed In: 5.27
Sentry Crash Report:
Attachments: Screenshots of the messed-up screen layout

Description Vlad Zahorodnii 2020-11-17 11:12:52 UTC
SUMMARY
If you have a dual-monitor setup with HiDPI, the screen layout will be scrambled after switching between X11 and Wayland session.

STEPS TO REPRODUCE
1. Log in to Wayland session
2. Set a scale factor of 2 on both monitors
3. Change orientation of one monitor to "portrait"
4. Switch to X11 session

OBSERVED RESULT
Screen layout is corrupted in X11 session. Furthermore, after switching back to Wayland session, the scale factors need to be reset in the kcm in order to re-enable HiDPI.

EXPECTED RESULT
Screen layout should not be corrupted after switching between X11 and Wayland sessions.
Comment 1 Nate Graham 2021-03-10 13:24:48 UTC
Related to Bug 433460. Once that's fixed, it would be interesting to see what's still broken.
Comment 2 Nate Graham 2021-06-10 17:25:42 UTC
*** Bug 438423 has been marked as a duplicate of this bug. ***
Comment 3 Nate Graham 2021-06-14 16:18:23 UTC
*** Bug 438132 has been marked as a duplicate of this bug. ***
Comment 4 Harald Sitter 2021-06-19 16:53:27 UTC
I have: output scale=1.5 in wayland. I switch to x11 globalscale=1. What I then see is that

systemsettings(36246)/(default) KScreen::Output::geometry: logicalsize QSize(2560, 1440) dptr size QSize(3840, 2160)

where logical size /1.5 of the real resolution

systemsettings(36246)/(default) KScreen::Output::logicalSize: scale 1.5

What I believe happens here is that since wayland supports per-screen scaling the scale is recorded in the backing configs

grep -ri 1.5
control/outputs/af15716759a8cd23110c74dd7f1fb852:    "scale": 1.5
control/configs/db639558b75873b5ba72f206a3712a16:            "scale": 1.5

but then on x11 per-screen isn't a thing so that's meaningless. BUT the Output class still reads the value and the KCM still uses the value to get relative sizing and whatnot. So this may indeed be the other side to the coin that is bug #433460 but I don't really have sufficient overview of the stack. It occurs to me that if libkscreen's Output class correctly dealt with scaling behind the scenes (that is to say: use the global config when in x11 or per-display in wayland) then everything built on top should work.
Comment 5 d3coder 2021-06-19 21:12:19 UTC
I don't have scaling. My widgets and desktop are just swapped.

For example on X11 i have Left and Right monitors. When i start wayland session, arrangement is correct, but X11 Right monitor contents are on Left monitor and vice-versa.
Comment 6 MK 2021-06-20 10:10:15 UTC
Created attachment 139537 [details]
Screenshots of the messed-up screen layout

Same here: after setting per-screen scaling in Wayland and then switching back to X11 (because of https://bugs.kde.org/show_bug.cgi?id=438313 ) my screen setup is effed up (see attachment)
Comment 7 Harald Sitter 2021-06-20 11:14:59 UTC
Yes. That is entirely consistent with what we see in the two bug reports.

What goes on in your screenshot is that the KCM thinks you are at a scale >1 so it takes the the actual resolution of your left hand screen and divides it by the scale. This then is the "logical" resolution that is smaller than your actual resolution. Say your left screen is 15x15 and has 1.5 scale. The logical size is 10x10. And that is the basis for the layout in the KCM preview. That is why it looks smart there (it behaves as though you were still in wayland). Kscreen then has the config

first screen at point 0,0 with width=10 and height=10. second screen at point 11,11 width=5 and height=5 (random example values).

Plasmashell (or KWin, unsure about responsibilities) on the other hand knows that you are on x11 and so wayland scale has no impact. The first desktop consequently gets rendered at 0,0 with width=15 and height=15 (these are the unscaled values!). Then it renders the second screen. KScreen says the second screen is at position 11,11. Plasma draws the desktop at that location with a width=5 and height=5.

The second screen is now drawn on your first screen because the KScreen position was wrong.

Hope that makes some sense. Essentially the KCM pretends you have wayland scaling, but you really don't so the positioning between KCM (scaled) and real world (not scaled) are out of sync and that results in things getting placed and incorrect locations.
Comment 8 d3coder 2021-06-20 11:38:18 UTC
This bug was not fixed https://bugs.kde.org/show_bug.cgi?id=426496
Just check screenshots (they are not attached, only links), exact same issue.
On X11 Intel, it swaps monitor content right after start.
On nvidia X11 it doesn't swap.
Haven't tested with AMD.

On wayland it doesn't swap desktop contents like on X11 Intel.
Comment 9 Nate Graham 2022-11-08 22:23:02 UTC

*** This bug has been marked as a duplicate of bug 365865 ***
Comment 10 Nate Graham 2022-11-08 22:24:08 UTC
Oops wrong thing, sorry.
Comment 11 Nate Graham 2022-11-08 22:24:18 UTC
*** Bug 438423 has been marked as a duplicate of this bug. ***
Comment 12 Nate Graham 2022-11-08 22:24:23 UTC
*** Bug 438132 has been marked as a duplicate of this bug. ***
Comment 13 Nate Graham 2022-11-08 22:24:48 UTC
*** Bug 389661 has been marked as a duplicate of this bug. ***
Comment 14 Nate Graham 2022-11-08 22:24:53 UTC
*** Bug 445092 has been marked as a duplicate of this bug. ***
Comment 15 Nate Graham 2022-11-08 22:25:00 UTC
*** Bug 447359 has been marked as a duplicate of this bug. ***
Comment 16 Nate Graham 2022-11-08 22:47:10 UTC
*** Bug 447085 has been marked as a duplicate of this bug. ***
Comment 17 Nate Graham 2022-12-16 19:48:10 UTC
I can confirm that this is fixed with the big multiscreen changes for Plasma 5.27!