Bug 384733

Summary: Wayland configs are not saved
Product: [Plasma] KScreen Reporter: David Edmundson <kde>
Component: kdedAssignee: Sebastian Kügler <sebas>
Status: RESOLVED FIXED    
Severity: normal CC: aleixpol, firebringer11, rainer, simonandric5
Priority: NOR    
Version: git   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description David Edmundson 2017-09-15 07:08:43 UTC
If I set a scale in kwayland the config is not saved.

kscreen-console json   shows the right thing
kscreen-console config shows nothing

nothing is written into ~/.local/share/kscreen
Comment 1 Sebastian Kügler 2017-09-16 10:36:19 UTC
The problem seems to be that the kcm doesn't save the config (by design), but the kded5 module does. 

On X11, it does so after getting a changed signal from XRandR. There's no such event for scale changes, as the scale is changed by an env var.

On Wayland, this *should* actually work, but the scaling UI doesn't actually go through Wayland from having a glance at the code, the scale is never set to the outputs in the compositor, so we don't get a changed signal back (in kded) and hence, nothing's saved.

kscreen-console just shows scale: 1 on my system, by the way, even if I set the scale to 1.2 or 2 (that's in line with the above observations).
Comment 2 Sebastian Kügler 2017-09-16 10:56:58 UTC
can you check if the sebas/scalesave branch of kscreen makes a difference?
Comment 3 David Edmundson 2017-09-16 18:10:25 UTC
Scaling does go via Wayland and the compositor.

It's quite plausible I'm not sending this back properly.

How are you setting it to 1.2?
Comment 4 David Edmundson 2017-09-16 18:14:12 UTC
*** Bug 384763 has been marked as a duplicate of this bug. ***
Comment 5 Sebastian Kügler 2017-09-16 21:13:57 UTC
I'm opening kcmshell5 kscreen, then "Scale display", set the factor to 1.2 and hit OK on the popup.

From reading scalingconfig.cpp, you're only writing the scalefactor to kdeglobals via KConfig and to xrdb.

For the kwayland backend to pick up the changes, which it then writes to the kscreen hash config file, it needs to trigger a screen config change, which it does after changing the config through output->setScale() and SetConfigOperation.

Essentially, I haven't found the output->setScale(1.2) call anywhere in there, the scaling doesn't go through kscreen API (and backend) at all.
Comment 6 David Edmundson 2017-09-17 10:31:35 UTC
You can't be selecting 1.2...

Either you're not running master or you're not runing wayland.
Comment 7 David Edmundson 2017-09-17 10:32:27 UTC
Note that there are two code paths for X and wayland, all your comments are about the X one.
Comment 8 Sebastian Kügler 2017-09-17 19:38:59 UTC
Yes, but the problem also applies to Wayland, I just haven't been able to test it, just to hack up a proof of concept patch. Does it work? :)
Comment 9 David Edmundson 2017-09-17 21:42:51 UTC
The issue only applies to wayland, not also.

Your patch is to a class that is never used on Wayland. I can tell you it won't work.

mOutput->setScale is called from outputConfig where it does go through wayland.
Comment 10 Sebastian Kügler 2017-09-18 08:04:42 UTC
Okay, I looked into scalingconfig.cpp, and wondered where the per output scaling went. I did so on a train without much time, which would explain my oversight.

I'll have another look. :)
Comment 11 Sebastian Kügler 2017-09-19 18:31:05 UTC
Git commit 78e8133e934e837ff927673ca6d07218e054c60d by Sebastian Kügler.
Committed on 19/09/2017 at 18:27.
Pushed by sebas into branch 'sebas/scalechange'.

refresh the config after it changed

When we get a config change signaled, the internal config may not have updated (when the wayland connection is in process). This means that we may miss changed data. Reloading the config when it changed and only then saving it makes it more robust.

I'm not 100% happy about this patch, but tried a lot of things to get the output updated when the backend changes, but it just doesn't happen. With this patch, at least the correct scale value gets written to the config file.

M  +20   -12   kded/daemon.cpp
M  +1    -0    kded/serializer.cpp

https://commits.kde.org/kscreen/78e8133e934e837ff927673ca6d07218e054c60d
Comment 12 David Edmundson 2017-09-21 11:42:37 UTC
We have a few problems:

1) Whoever sends a config to kwin never gets an accepted/failed reply, so they block updates forever. (see relevant phab)

2) The kwayland code to do that is broken (see relevant phab)

3) Even after that I have another problem.

On initial load the kded loads a config from the backend
 - we then create a new config in idealConfig() which calls clone()
 - we set this but we're still monitoring the original config
 - when we change something it's the new config that gets an update
 - kded obviously ignores it
Comment 13 Sebastian Kügler 2017-09-21 13:10:14 UTC
Git commit 8719c33eea8f115986990ddfa90de614b8e945ee by Sebastian Kügler.
Committed on 21/09/2017 at 13:10.
Pushed by sebas into branch 'master'.

track the config to monitor, save scale

Summary:
When doApplyConfig is called, we forgot to change the monitored config,
which means we weren't tracking changes anymore. This patch makes sure
that the new config becomes the monitored one in that case.

Also, save the scale property to the json config, we forgot to do that.

Test Plan: Scale changes through kwin are now saved, they weren't before

Reviewers: davidedmundson

Reviewed By: davidedmundson

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D7912

M  +3    -0    kded/daemon.cpp
M  +1    -0    kded/serializer.cpp

https://commits.kde.org/kscreen/8719c33eea8f115986990ddfa90de614b8e945ee
Comment 14 Sebastian Kügler 2017-09-21 13:11:05 UTC
Git commit 19e96249d78601d77e022a5ae081be8606ed402e by Sebastian Kügler.
Committed on 21/09/2017 at 13:10.
Pushed by sebas into branch 'Plasma/5.11'.

track the config to monitor, save scale

Summary:
When doApplyConfig is called, we forgot to change the monitored config,
which means we weren't tracking changes anymore. This patch makes sure
that the new config becomes the monitored one in that case.

Also, save the scale property to the json config, we forgot to do that.

Test Plan: Scale changes through kwin are now saved, they weren't before

Reviewers: davidedmundson

Reviewed By: davidedmundson

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D7912

M  +3    -0    kded/daemon.cpp
M  +1    -0    kded/serializer.cpp

https://commits.kde.org/kscreen/19e96249d78601d77e022a5ae081be8606ed402e
Comment 15 Sebastian Kügler 2017-09-21 14:16:06 UTC
Git commit d16f63b6e64b49f8dbd4742045b0766a8c550b4b by Sebastian Kügler.
Committed on 21/09/2017 at 14:15.
Pushed by sebas into branch 'master'.

inform outputconfiguration clients that a change has been applied

Summary:
After changing the output configuration, the client expects that it is informed
whether or not a new configuration has been applied (or failed). This was ommitted
so far, meaning that clients wouldn't know what happened in kwin.

Since we don't track if a setting failed yet, send the applied() signal regardless.

Test Plan: Verified that the signal arrived in libkscreen after changing scale of an output

Reviewers: graesslin, davidedmundson

Reviewed By: davidedmundson

Subscribers: kwin, #kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D7910

M  +7    -0    platform.cpp
M  +5    -0    plugins/platforms/drm/drm_backend.cpp

https://commits.kde.org/kwin/d16f63b6e64b49f8dbd4742045b0766a8c550b4b
Comment 16 Sebastian Kügler 2017-09-21 14:18:13 UTC
Note: This needs David's kwayland's 2b3f9509ac1 to not crash.
Comment 17 Rainer Finke 2017-10-18 21:29:50 UTC
Is this supposed to work in Plasma 5.11.1 and KDE Frameworks 5.39? Because I can't disable the scaling factor of 2x for my 4k screen on Plasma-Wayland, as soon as I reboot it will always reset to 2x. This looks really blurry and unsharp. Is there maybe a workaround to disable scaling?
Comment 18 David Edmundson 2017-10-18 21:57:54 UTC
>Is this supposed to work in Plasma 5.11.1 and KDE Frameworks 5.39?

Yes.

What version of frameworks are you running?
Comment 19 Rainer Finke 2017-10-19 06:38:25 UTC
KDE Frameworks 5.39.0
Plasma 5.11.1
Qt 5.10 beta

After I login to Plasma-Wayland automatically the scaling is adjusted from 1x to 2x, I can see it as the Plasma logo is increasing the size. I tried to change this via systemsettings, but this is valid for the session only.
Comment 20 David Edmundson 2017-10-19 10:12:03 UTC
That should all work then.

Can you look in your ~/.local/share/kscreen and see if that's saved?
Comment 21 Rainer Finke 2017-10-19 21:39:11 UTC
The config file in ~/.local/share/kscreen seems to be ok (see below). But Plasma-Wayland seems to ignore it, the scaling factor of 2x is still applied automatically after login.
[
    {
        "enabled": true,
        "id": "88063ad449c2982c6a3107f0a644fce2",
        "metadata": {
            "fullname": "xrandr-U28D590",
            "name": "DisplayPort-2"
        },
        "mode": {
            "refresh": 59.99662399291992,
            "size": {
                "height": 2160,
                "width": 3840
            }
        },
        "pos": {
            "x": 0,
            "y": 0
        },
        "primary": true,
        "rotation": 1,
        "scale": 1
    }
]
Comment 22 David Edmundson 2017-10-26 16:53:30 UTC
*** Bug 386214 has been marked as a duplicate of this bug. ***
Comment 23 Sebastian Kügler 2017-11-01 12:18:38 UTC
Looking into this, my findings so far:

We don't get a change event in kded after the scale has changed, this means that the config isn't saved, so it can't be restored.

I'm looking into why we don't get said change event right now.

Problem is also that I'm reproducing the same symptom but with different assumptions (my config isn't there, Rainer's is).
Comment 24 Rainer Finke 2017-11-15 09:44:58 UTC
Sorry for my late reply. The config ~/.local/share/kscreen is not saved after adjusting the scaling factor for me either. I did modify manually the config file to show the value "scale": 1. Unfortunatly this setting is ignored when I login to Plasma-Wayland. 
After every start of Plasma-Wayland I have to manually adjust the scaling factor in systemsettings to 1x, run "kill plasmashell" and then run "plasmashell". I use Plasma-Wayland on my desktop and laptop each with a 4K screen as my main system and do avoid X11, so this bug is quite annoying for my setup and I'm happy to provide further info if necessary.

Plasma 5.11.3
KDE Frameworks 5.40
Qt 5.10 beta4
Arch Linux
Comment 25 Rainer Finke 2017-12-10 19:35:22 UTC
I upgraded to KDE Frameworks 5.41 in the hope there would be an improvement for this 4k screen issue on Wayland, but there is not. It would be great if this could be fixed for Plasma 5.12. Please allow the user to disable the automatic scaling! The previous Plasma version (5.10) didn't enforce the scaling factor of 2x. I'm happy to compile from git and to provide feedback.
Comment 26 Sebastian Kügler 2018-01-17 12:18:10 UTC
Most likely fixed with https://phabricator.kde.org/D9902

Please reopen if this still persists with Plasma 5.12.

Also: Thanks for the feedback!