Bug 438971 - GDK_SCALE scale envs not unset on wayland login
Summary: GDK_SCALE scale envs not unset on wayland login
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: general (show other bugs)
Version: master
Platform: Other Linux
: NOR normal
Target Milestone: 1.0
Assignee: David Edmundson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-21 02:56 UTC by Emilio Cobos Álvarez (:emilio)
Modified: 2021-07-08 01:09 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.22.4


Attachments
Sample application that prints window scaling (359 bytes, text/plain)
2021-06-21 02:56 UTC, Emilio Cobos Álvarez (:emilio)
Details
WAYLAND_DEBUG=1 output (12.09 KB, text/plain)
2021-06-21 09:55 UTC, Emilio Cobos Álvarez (:emilio)
Details
WAYLAND_DEBUG=1 output on GNOME (16.44 KB, text/plain)
2021-06-21 09:58 UTC, Emilio Cobos Álvarez (:emilio)
Details
WAYLAND_DEBUG=1 output after a restart (13.55 KB, text/x-log)
2021-06-21 12:06 UTC, Emilio Cobos Álvarez (:emilio)
Details
env difference (7.78 KB, patch)
2021-06-21 12:33 UTC, Emilio Cobos Álvarez (:emilio)
Details
env difference between x11 and wayland-bad env (3.64 KB, text/plain)
2021-06-21 12:34 UTC, Emilio Cobos Álvarez (:emilio)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Emilio Cobos Álvarez (:emilio) 2021-06-21 02:56:23 UTC
Created attachment 139558 [details]
Sample application that prints window scaling

SUMMARY

When using kwin + wayland, gtk applications report a bogus display scaling.

STEPS TO REPRODUCE
1. Go to system settings > display configuration
2. Set monitor scale to 200%
3. Run the attached application

OBSERVED RESULT

"1" instead of the expected "2" is printed.

EXPECTED RESULT

"2" is printed, as it happens if you do the same on X11

SOFTWARE/OS VERSIONS

Operating System: Fedora 34
KDE Frameworks Version: 5.82.0
Qt Version: 5.15.2
Kernel Version: 5.12.10-300.fc34.x86_64
OS Type: 64-bit
Graphics Platform: Wayland

ADDITIONAL INFORMATION

This causes Firefox to detect the wrong monitor scaling and appear too tiny, when ran with native wayland support rather than via XWayland.
Comment 1 Vlad Zahorodnii 2021-06-21 08:10:22 UTC
the test app doesn't print anything.
Comment 2 Vlad Zahorodnii 2021-06-21 08:10:46 UTC
Can you please run the test app with WAYLAND_DEBUG=1 and post the output here?
Comment 3 Emilio Cobos Álvarez (:emilio) 2021-06-21 09:21:15 UTC
(In reply to Vlad Zahorodnii from comment #1)
> the test app doesn't print anything.

Saving the attachment as a python file and running it on a terminal definitely should print the window scale factor to stdout, but sure, will run it with WAYLAND_DEBUG asap, thanks for taking a look.
Comment 4 Emilio Cobos Álvarez (:emilio) 2021-06-21 09:55:55 UTC
Created attachment 139565 [details]
WAYLAND_DEBUG=1 output

(As requested)
Comment 5 Emilio Cobos Álvarez (:emilio) 2021-06-21 09:58:56 UTC
Created attachment 139566 [details]
WAYLAND_DEBUG=1 output on GNOME

set_buffer_scale calls are different
Comment 6 Emilio Cobos Álvarez (:emilio) 2021-06-21 10:23:55 UTC
FWIW I see some similar stuff in regular KDE apps, in the sense that I need to set the font size in the font settings to twice the size I want for text to be the right size (so the font settings seem to not account for monitor scale either).
Comment 7 Emilio Cobos Álvarez (:emilio) 2021-06-21 10:30:21 UTC
Ok, so this is weird. If I restart my computer and just start a Plasma+Wayland session, then stuff works as expected. If at some point I have started a plasma X11 session before (even though I log out and restart with wayland) then I can repro all this weirdness.
Comment 8 David Edmundson 2021-06-21 11:44:49 UTC
>set_buffer_scale calls are different

They are on different surfaces
surface 25 is the cursor.

surface 30 is the window.

Everything from our side look correct.

We potentially call  wl_surface@30.enter(wl_output@6) at different points to Gnome.

That code is querying the scale before the client has been told which output the window is on.

Please reopen if you can name something specific that's wrong our side based on that output
Comment 9 Emilio Cobos Álvarez (:emilio) 2021-06-21 12:06:30 UTC
Created attachment 139570 [details]
WAYLAND_DEBUG=1 output after a restart

This is the WAYLAND_DEBUG=1 output after a restart on Plasma, which behaves correctly.

So there's some inconsistency on Plasma depending on whether an X11 session has been started before or not. That looks clearly like a bug to me (not sure how prioritary, but definitely threw me off).
Comment 10 Emilio Cobos Álvarez (:emilio) 2021-06-21 12:07:50 UTC
(Reopening per the above: Maybe it's known, maybe it's not important enough to fix, but it does look pretty broken to me fwiw)
Comment 11 David Edmundson 2021-06-21 12:12:52 UTC
>So there's some inconsistency on Plasma depending on whether an X11 session has been started before or not

Aha! That might be a clue.

Is the "env" different between the two cases? (can you just upload the diff please)

On X we'll have exported something to set the scale
On Wayland we don't export anything as we have wayland communicating it
Comment 12 Emilio Cobos Álvarez (:emilio) 2021-06-21 12:33:09 UTC
Created attachment 139572 [details]
env difference

Spot on, indeed there are two variables that explain this:

```
+GDK_DPI_SCALE=0.5                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
+GDK_SCALE=2
```
Comment 13 Emilio Cobos Álvarez (:emilio) 2021-06-21 12:34:52 UTC
Created attachment 139573 [details]
env difference between x11 and wayland-bad env

Yeah, it seems there are a bunch of env changes that starting an x11 Plasma session causes that starting a wayland session doesn't undo.
Comment 14 Emilio Cobos Álvarez (:emilio) 2021-06-21 12:45:33 UTC
After going to a wayland session from an x11 session, even a restart, the monitor scale needs to get reset as well from the system settings (even though it is still reported as 200%). Going back to any other scale then back to 200% does cause things to get scaled properly again.

So perhaps that's the root of the problem.
Comment 15 David Edmundson 2021-06-21 12:55:17 UTC
\o/ 

I will patch our startup to explicitly unset these on wayland login. Thanks
Comment 16 Bug Janitor Service 2021-06-21 23:15:59 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/943
Comment 17 David Edmundson 2021-07-05 23:05:51 UTC
Git commit 4ef92d8c9bba5429bf85c521bc962f105692c4ce by David Edmundson.
Committed on 05/07/2021 at 23:05.
Pushed by davidedmundson into branch 'master'.

Set GDK scale explictily on wayland

On wayland we don't want to use the env vars as we send the scale via
wl_output scale.

If a user logs into X first we set these in our activation env to a
scaled value. If they then log into wayland afterwards they are still
set. Calling qunsetenv won't work as then we won't remove them from the
activation env.

Arguably it's working round a bug, but we don't have other options.

M  +2    -0    startkde/startplasma-wayland.cpp

https://invent.kde.org/plasma/plasma-workspace/commit/4ef92d8c9bba5429bf85c521bc962f105692c4ce
Comment 18 Nate Graham 2021-07-08 01:09:10 UTC
Git commit 14cd19138cd514ea753a842d01bd2265ee8ad0b8 by Nate Graham, on behalf of David Edmundson.
Committed on 08/07/2021 at 01:09.
Pushed by ngraham into branch 'Plasma/5.22'.

Set GDK scale explictily on wayland

On wayland we don't want to use the env vars as we send the scale via
wl_output scale.

If a user logs into X first we set these in our activation env to a
scaled value. If they then log into wayland afterwards they are still
set. Calling qunsetenv won't work as then we won't remove them from the
activation env.

Arguably it's working round a bug, but we don't have other options.


(cherry picked from commit 4ef92d8c9bba5429bf85c521bc962f105692c4ce)

M  +2    -0    startkde/startplasma-wayland.cpp

https://invent.kde.org/plasma/plasma-workspace/commit/14cd19138cd514ea753a842d01bd2265ee8ad0b8