Bug 413645

Summary: Can't remember desktop widget positions after reboot
Product: [Plasma] plasmashell Reporter: André Fettouhi <A.Fettouhi>
Component: Desktop ContainmentAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED FIXED    
Severity: major CC: 1i5t5.duncan, andysem, arraybolt3, brendon, chrisacady, claudius+kde, contact, crazylegoguy, daniel-other+kdebug, dcalvino, driesp, eeickmeyer, gilberto.nunes32, jghodd, katyaberezyaka, kdeu, mario, mbmiller1994, nate, notmart, openmindead, pereira.alex, peter.krutel, plasma-bugs, ptconnolly, qydwhotmail, sayantan.santra689, sephiroth_pk, smowtenshi, strm.50, udippel, z_mikowski
Priority: VHI    
Version: 5.24.3   
Target Milestone: 1.0   
Platform: Manjaro   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=458038
https://bugs.kde.org/show_bug.cgi?id=460618
Latest Commit: Version Fixed In: 5.24.7
Attachments: Screenshot of desktop before update
Desktop after update

Description André Fettouhi 2019-10-30 18:09:08 UTC
Created attachment 123602 [details]
Screenshot of desktop before update

SUMMARY

Since updating to KDE Plasma 5.17 my desktop widgets are messed up every time I restart or start my KDE session. I have attached two screenshots of desktop. Screenshot_20191030_161412.png is how my desktop looks like when I boot into it with KDE Plasma 5.17 and 5.17.x. Screenshot_20191030_133444.png shows how it looked before or after I have arranged everything to how I want it and before i close my KDE session or turn off my PC.


KDE Plasma Version: 5.17.2
Comment 1 André Fettouhi 2019-10-30 18:09:37 UTC
Created attachment 123603 [details]
Desktop after update
Comment 2 Dries 2019-11-01 12:37:20 UTC
For me, the issue is resolved in KDE Plasma 5.17.2
Comment 3 André Fettouhi 2019-11-01 13:24:39 UTC
No still present for me with 5.17.2.
Comment 4 Nate Graham 2019-12-02 19:40:52 UTC
Out of curiosity, what's your screen resolution?
Comment 5 André Fettouhi 2019-12-02 19:56:03 UTC
1920x1200
Comment 6 Nate Graham 2019-12-02 21:43:51 UTC
Thanks.
Comment 7 Nate Graham 2020-01-22 16:26:29 UTC
I had this happen yesterday. :/
Comment 8 Nate Graham 2020-01-22 16:26:37 UTC
*** Bug 416552 has been marked as a duplicate of this bug. ***
Comment 9 Nate Graham 2020-01-22 16:28:16 UTC
*** Bug 375229 has been marked as a duplicate of this bug. ***
Comment 10 Nate Graham 2020-01-22 17:01:23 UTC
*** Bug 414761 has been marked as a duplicate of this bug. ***
Comment 11 Nate Graham 2020-01-22 17:16:52 UTC
*** Bug 392845 has been marked as a duplicate of this bug. ***
Comment 12 Uwe Dippel 2020-01-22 17:30:50 UTC
OT: Where can I file a bug against this project being flown blind? This bug was filed (duplicate) in January 2017. And so far we have been told it was difficult to solve. Fine, by all means. 
But it was working (though more constraint) in Plasma 4. 
So nobody was able to see this cliff coming during the design phase of Plasma 5? Nobody thought about the consequences of icon placement at resolution change? Nobody tried resolution change before rolling out Plasma 5 as 'production'?
Comment 13 Nate Graham 2020-01-22 18:34:46 UTC
*** Bug 365286 has been marked as a duplicate of this bug. ***
Comment 14 Nate Graham 2020-01-22 18:35:03 UTC
*** Bug 363855 has been marked as a duplicate of this bug. ***
Comment 15 Nate Graham 2021-03-09 04:56:36 UTC
*** Bug 412640 has been marked as a duplicate of this bug. ***
Comment 16 Nate Graham 2021-03-11 19:01:21 UTC
*** Bug 393881 has been marked as a duplicate of this bug. ***
Comment 17 Nate Graham 2021-03-11 19:01:28 UTC
*** Bug 393270 has been marked as a duplicate of this bug. ***
Comment 18 Nate Graham 2021-03-11 19:01:35 UTC
*** Bug 389141 has been marked as a duplicate of this bug. ***
Comment 19 Marco Martin 2021-03-16 09:08:42 UTC

*** This bug has been marked as a duplicate of bug 433799 ***
Comment 20 Nate Graham 2021-04-06 02:49:34 UTC
*** Bug 435282 has been marked as a duplicate of this bug. ***
Comment 21 Nate Graham 2022-03-25 16:36:01 UTC
Don't think this is a duplicate of Bug 433799, and also we should try not to forward-dupe an old bug with a bunch of dupes to a new one without them, and also that one doesn't seem fixed. :/
Comment 22 Nate Graham 2022-03-25 16:36:11 UTC
*** Bug 451487 has been marked as a duplicate of this bug. ***
Comment 23 Nate Graham 2022-03-25 16:36:16 UTC
*** Bug 433799 has been marked as a duplicate of this bug. ***
Comment 24 Julius R. 2022-03-30 08:11:25 UTC
I also have the same or a similar problem: After the last update (strangely enough from 5.24.2 to 5.24.3), my Desktop widget (a clock) keeps getting reset after every restart to the upper left corner of my screen.
Comment 25 Nate Graham 2022-05-03 15:25:42 UTC
*** Bug 453259 has been marked as a duplicate of this bug. ***
Comment 26 Nate Graham 2022-07-13 19:22:27 UTC
*** Bug 456613 has been marked as a duplicate of this bug. ***
Comment 27 Nate Graham 2022-07-21 19:31:28 UTC
*** Bug 456497 has been marked as a duplicate of this bug. ***
Comment 28 Nate Graham 2022-07-21 19:31:48 UTC
Bug 456497 has a detailed reproducible test case.
Comment 29 Claudius 2022-07-28 13:00:01 UTC
Something I just tried:
I have a pesky single org.kde.plasma.notifications widget that never saved its position (even when re-creating it).
When I manually edited the Containment's ItemGeometries-<myres> line by appending an entry of where I wanted it and did a shell restart. It worked. And now all of a sudden the entry is updated when moving the widget.

Before the Entry was missing and I had the widget in the upper left corner (like the other reports).
Comment 30 Nate Graham 2022-08-01 17:04:14 UTC
*** Bug 457304 has been marked as a duplicate of this bug. ***
Comment 31 Nate Graham 2022-08-01 17:04:21 UTC
*** Bug 457358 has been marked as a duplicate of this bug. ***
Comment 32 Nate Graham 2022-08-23 12:42:14 UTC
*** Bug 458038 has been marked as a duplicate of this bug. ***
Comment 33 Aaron Rainbolt 2022-09-09 01:43:44 UTC
I believe I've located the source of this bug. Using a clean install of Kubuntu 22.04 in a virtual machine with a screen resolution of 2560x1600.

In /home/user/.config/plasma-org.kde.plasma.desktop-appletsrc:

> [Containments][1]
> ItemGeometries-2560x1600=Applet-24:767.806,688.073,224,208,0;
> ItemGeometriesHorizontal=Applet-24:767.806,688.073,224,208,0;
> activityId=24ffa803-0000-40a5-94cb-76f0419052d1
> formfactor=0
> immutability=1
> lastScreen=0
> location=0
> plugin=org.kde.plasma.folder
> wallpaperplugin=org.kde.image
>
> [Containments][1][Applets][24]
> immutability=1
> plugin=org.kde.plasma.notifications
>
> [Containments][1][Applets][24][Configuration]
> PreloadWeight=6

"Applet-24" is a Notifications widget that I've plopped somewhere in the middle of the desktop.
If I log out and log back in at this point, I watch the widget initially render where it belongs. It then appears to "wander" around (moving very noticeably all on its own), then suddenly snaps to the edge of the screen (usually into the lower-right corner). I think I'm capturing this movement because I'm using a VM.

If I remove the "ItemGeometriesHorizontal" line entirely from the file, then save it, close everything (but leave the widget in the middle of the screen), then log out and log back in, the widget stays where it was left last time.

However, the "ItemGeometriesHorizontal" line appears to be automatically recreated, and if I log out and log back in again without modifying the file, the widget again "wanders" then snaps into the wrong location. I have attempted to and succeeded in reproducing this behavior twice. This leads me to believe that the "ItemGeometriesHorizontal" entry is the source of the problem.
Comment 34 Aaron Rainbolt 2022-09-09 01:54:43 UTC
I can also resolve the problem by entirely removing the "ItemGeometries" line and leaving the "ItemGeometriesHorizontal" line. However, again, this line is recreated at login, and if left at logout, the widget will again "wander" and then snap. So something about the two entries coexisting is causing things to go wrong.
Comment 35 Duncan 2022-09-09 04:20:16 UTC
(In reply to Aaron Rainbolt from comment #34)
> I can also resolve the problem by entirely removing the "ItemGeometries"
> line and leaving the "ItemGeometriesHorizontal" line. However, again, this
> line is recreated at login, and if left at logout, the widget will again
> "wander" and then snap. So something about the two entries coexisting is
> causing things to go wrong.

Those floating-point values look suspect.  Does manually setting them to integer values (767 and 688) help?  If not or if it doesn't stick, try the following...

This bug has been around awhile, but there was a workaround I initially described in https://bugs.kde.org/show_bug.cgi?id=389141 that (with a bit of updating) presumably still works (see below):

With the plasmoids in the desired location (either with the ItemGeometries lines deleted or with them set as desired, not sure which), set plasma-org.kde.plasma.desktop-appletsrc (normally found in ~/.config unless you set $XDG_CONFIG_HOME) read-only.   This should prevent it from being overwritten with the bad config but unfortunately you'll still need to manually restart the initially started mixed-up plasmashell (plasmashell --replace, unfortunately at each login, tho it can be scripted as described below) in ordered to get it to take, since that initial start is what goes haywire.

You can try the --replace from krunner.  If that works as I expect it will, automate it with a script set to autostart (see the autostart kcontrol/systemsettings module), with a few seconds sleep to let the system stabilize before the --replace command.

Of course with the desktop-appletsrc file set readonly reconfiguring things will work only for that plasmshell session so you'll have to remember to toggle it back read-writable if you want to reconfigure...

(I believe the bug trigger here was a multi-monitor setup with different resolutions for each monitor, one full-HD one 4K.  When I upgraded to matching-resolution 4Ks it stopped triggering for me so I've not seen the bug in awhile.  Thus the "presumably still works" qualification above.)
Comment 36 Aaron Rainbolt 2022-09-09 14:57:28 UTC
> (I believe the bug trigger here was a multi-monitor setup with different resolutions for each monitor, one full-HD one 4K.  When I upgraded to matching-resolution 4Ks it stopped triggering for me so I've not seen the bug in awhile.  Thus the "presumably still works" qualification above.)

I think this is probably a race condition, because when my VM window was in a lower resolution (close to but not quite 1366x768), the bug didn't occur. When I set it to a high resolution, then it occurred. I'm guessing with 2 4K monitors, things must initialize quickly enough to hide the condition, but with mismatched monitors, the initialization goes slower and the condition appears.

Changing the floating-point values to whole numbers had no effect.
Comment 37 Aaron Rainbolt 2022-09-11 16:08:39 UTC
In https://invent.kde.org/plasma/plasma-workspace/-/blob/Plasma/5.25/components/containmentlayoutmanager/appletslayout.cpp, lines 83-88:

>    } else if (!m_geometryBeforeResolutionChange.isEmpty()) {
>        m_layoutManager->layoutGeometryChanged(newGeom, m_geometryBeforeResolutionChange);
>        m_geometryBeforeResolutionChange = QRectF();
>    
>        // Heuristically relayout items only when the plasma startup is fully completed
>    } else {

Commenting out the "else if" in this section of code causes the bug to disappear.
Comment 38 Aaron Rainbolt 2022-09-11 18:45:09 UTC
Looking at my previous comment, it may appear misleading - the comment within the "else if" block actually applies to the following "else" block if I'm understanding correctly. Here's the snippet of code (including the offending else if block) with more context:

>         } else if (m_layoutChanges & SizeChange) {
>             const QRect newGeom(x(), y(), width(), height());
>             // The size has been restored from the last one it has been saved: restore that exact same layout
>             if (newGeom.size() == m_savedSize) {
>                 m_layoutManager->resetLayoutFromConfig();
>    
>                 // If the resize is consequence of a screen resolution change, queue a relayout maintaining the distance between screen edges
>             } else if (!m_geometryBeforeResolutionChange.isEmpty()) {
>                 m_layoutManager->layoutGeometryChanged(newGeom, m_geometryBeforeResolutionChange);
>                 m_geometryBeforeResolutionChange = QRectF();
>    
>                 // Heuristically relayout items only when the plasma startup is fully completed
>             } else {
>                 polish();
>             }
>         }
>         m_layoutChanges = NoChange;
>     });

From https://invent.kde.org/plasma/plasma-workspace/-/blob/Plasma/5.25/components/containmentlayoutmanager/appletslayout.cpp, lines 76 to 93.
Comment 39 Uwe Dippel 2022-09-11 19:51:02 UTC
Hi,

read up stuff above. That's what I wrote earlier: that it's a race condition. Thanks anyway, though, seriously! 
Could you please file an appropriate 'diff -u' or similar, including plasma version, for me / for us to try out?

Instead of vi or likewise, I'd rather
cp xyz xyz.orig 
and then apply a unified patch file . So roll-back is much easier; and no need to interpret verbal instructions.

Thanks in advance!
Comment 40 Aaron Rainbolt 2022-09-11 20:16:23 UTC
The patch: https://termbin.com/kv20
Plasma version - 5.25.5 (built from source with kdesrc-build with build-group set to stable-kf5-qt5)

WARNING: I do not know C++. All this patch does is comment out a chunk of code - while this has the result of eliminating the bug in my testing, it also has the result of disabling whatever functionality was served by the code being commented out, and it might have unforseen consequences. Treat this like actively reacting uranium. Use in a VM or dedicating testing machine is highly encouraged!
Comment 41 Aaron Rainbolt 2022-09-11 20:22:43 UTC
(In reply to Aaron Rainbolt from comment #40)
> The patch: https://termbin.com/kv20
> Plasma version - 5.25.5 (built from source with kdesrc-build with
> build-group set to stable-kf5-qt5)
> 
> WARNING: I do not know C++. All this patch does is comment out a chunk of
> code - while this has the result of eliminating the bug in my testing, it
> also has the result of disabling whatever functionality was served by the
> code being commented out, and it might have unforseen consequences. Treat
> this like actively reacting uranium. Use in a VM or dedicating testing
> machine is highly encouraged!

:facepalm: Forgot to give the file path. Assuming you have everything set up according to https://community.kde.org/Get_Involved/development, the file you want to patch is ~/kde/src/plasma-workspace/components/containmentlayoutmanager/appletslayout.cpp.
Comment 42 Aaron Rainbolt 2022-09-14 19:27:55 UTC
So, looking at the logic here, I think the problem might actually be the result of a resolution change during early startup - for instance, on an NVIDIA machine of mine, the SDDM display on bootup is rather distorted (renders in 640x480, maybe?), but the resolution changes during early startup to match the screen's correct resolution. I think when this happens with a big enough screen, it causes the relayout to trigger at the wrong time and thus scrambles the widgets. If this is the case, the problematic else if statement may simply need to check for the presence of a component of KDE that only finishes loading after any early-startup resolution changes. Perhaps checking for KWin's presence would be sufficient here?
Comment 43 Nate Graham 2022-09-14 20:19:52 UTC
That seems quite likely.
Comment 44 Duncan 2022-09-14 20:35:01 UTC
(In reply to Aaron Rainbolt from comment #42)
> [T]he problem might actually be the
> result of a resolution change during early startup

Yes.  In my (different resolution dual-monitor) case the problem was definitely the resolution switch, in that case on the high resolution monitor (actually a 4K TV), switching from the resolution of the low-resolution monitor (a Full-HD TV).  What was happening is that all the widgets on the high-res monitor were moved to fit within the confines of the low-res monitor, thus all repositioning in the top-left quadrant of the high-res monitor.  It was pretty obvious -- once I noticed it. =:^\

The problem went away when I switched to both 4K monitors so there wasn't a resolution-switch.  Before that I worked around it by setting the rc-file read-only (so the bad startup wouldn't overwrite the good config) and setting up a start-up script that slept for a few seconds then did a plasmashell restart, basically doing via user script exactly what you suggested, waiting until after the resolutions settled in before (re)starting plasmashell.
Comment 45 Uwe Dippel 2022-09-14 20:54:33 UTC
I'm afraid of repeating myself for the umpteenth time; and here in order to partly support #42. 

In my case the scrambling happens in an irregular manner; sometimes at boot it does, sometimes it doesn't. My initial display (built-in) is 1920x1080; my secondary display 2560x1440 is connected via HDMI, but defined as primary display. Sometimes the icons on the 2560x1440 are squeezed into 1920x1080; sometimes not.
This goes along to the SDDM and subsequent resolution change(s) in #42. So it seems that sometimes the initial display comes up, squeezes the icons, and sometimes it doesn't. So I have to assume the logical: it has never seen any 1920x1080 during boot in those cases. 
Since it is a static setup of the PC and the peripherals, I assumed a race condition. First part of remark.

Still less frequently, this same happens in yet another 'fashion': the desktop returns to the well-known default background, the coloured grayish diagonal one, with all icons and desktop objects arranged in line starting from the upper left corner. Second part of the remark.

So it looks like we have to do with at least TWO such undefined (race?) conditions at startup. Seemingly the initial display is at times activated during bootup, sometimes the bootup ends directly at the primary (peripheral) display. 
Plus, we seem to encounter another potentially undefined condition, in which the previous settings are considered unavailable or damaged or whatnot; so a fall-back to the pre-defined default layout of the screen is initiated. 

Sometimes the final resolution on the
Comment 46 Aaron Rainbolt 2022-09-14 22:41:01 UTC
Looks like the resolution change was indeed (at least part of) the problem. Changing AppletsLayout::AppletsLayout to ignore any screen resolution changes the first time it is ran fixed the bug, while still allowing the widgets to be repositioned when the user intentionally changes the screen resolution. I've only tested this in a single-monitor setup within a VM, but it entirely resolved the problem for me.

Expect a merge request soon. \o/
Comment 47 Aaron Rainbolt 2022-09-15 01:56:26 UTC
Crud. Well the solution that I was about to post a merge request for turned out to only solve the problem partway. While the widgets are no longer scrambled on startup, you can still cause them to be scrambled by starting KDE in a way where the resolution *doesn't* change during early startup, then change the resolution (tested by increasing the resolution). Bam, the widgets go crazy again. So the situation has been much improved, but there's still a bug lurking somewhere (probably in AbstractLayoutManager). :-(
Comment 48 Aaron Rainbolt 2022-09-15 01:59:29 UTC
Er, no, probably in GridLayoutManager. (Note to self, look at code before declaring where you think a bug is.)
Comment 49 Aaron Rainbolt 2022-09-15 02:22:11 UTC
Nevermind, I guess the bug seeming to still be there was a fluke? Now I can't get the wrong behavior to happen anymore. :/ Task failed successfully, I guess.
Comment 50 Aaron Rainbolt 2022-09-15 02:24:08 UTC
Bah, and now there it is again! Fickle thing. Alright, sorry for bug spam. I'll be back once I figure out what it's doing this time.
Comment 51 Aaron Rainbolt 2022-09-15 03:59:40 UTC
Alright, looks like everything's now working right! Merge request: https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/2118
Comment 52 Bug Janitor Service 2022-09-15 07:52:51 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/2120
Comment 53 Bug Janitor Service 2022-09-15 07:53:44 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/1150
Comment 54 Marco Martin 2022-09-23 10:04:40 UTC
Git commit ef57cd3d50f729f22558a20b03172da539e3bb71 by Marco Martin.
Committed on 23/09/2022 at 10:04.
Pushed by mart into branch 'master'.

Introduce a lock that blocks relayouts and config writes

The resize of the layout area can happen either by screen resolution
change or available screen area change (a panel appears or is resized)
This is not an atomic operation, as width and height are usually set in
2 different operations, and even worse the layout area is resized to
match the available one with an animation, so many intermediate resizes
that should never cause a relayout happen.

In normal operation an event compression timer limits the actual
relayouts to hopefully one, but if the system is really slowed down
(for instance, startup) the timer may expire and cause relayouts in
non useful sizes, losing the needed configuration.

In combination with
https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/1150

The lock blocks all relayout and config writes when the size of the
layout area doesn't correspond to corona availablescreenrect, which are
the only "settled" cases.

M  +23   -2    components/containmentlayoutmanager/appletslayout.cpp
M  +7    -0    components/containmentlayoutmanager/appletslayout.h

https://invent.kde.org/plasma/plasma-workspace/commit/ef57cd3d50f729f22558a20b03172da539e3bb71
Comment 55 Marco Martin 2022-09-23 10:05:20 UTC
Git commit bd676333cf57659bc885928afe5d3fe908589e79 by Marco Martin.
Committed on 23/09/2022 at 10:05.
Pushed by mart into branch 'master'.

Use relayout locking

This makes use of the layout locking freature introduced in
https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/2120
The resize of the layout area can happen either by screen resolution
change or available screen area change (a panel appears or is resized).

This is not an atomic operation, as width and height are usually set in
2 different operations, and even worse the layout area is resized to
match the available one with an animation, so many intermediate resizes
that should never cause a relayout happen.

A compression timer limits the actual relayouts to hopefully one,
 but if the system is really slowed down
(for instance, startup) the timer may expire and cause relayouts in
non useful sizes, losing the needed configuration.

The lock blocks all relayout and config writes when the size of the
layout area doesn't correspond to corona availablescreenrect, which are
the only "settled" cases.

M  +1    -0    containments/desktop/package/contents/ui/main.qml

https://invent.kde.org/plasma/plasma-desktop/commit/bd676333cf57659bc885928afe5d3fe908589e79
Comment 56 Uwe Dippel 2022-09-23 10:11:19 UTC
Sounds good, and appropriate! Thanks a bunch.

Please, when can we expect to see this patch being rolled out with the usual update && upgrade?
(I don't feel like compiling myself; and can survive with my workarounds)
Comment 57 Nate Graham 2022-09-23 22:21:10 UTC
Git commit 59bf0f5a2081ed49a32a34083b7f5a9f0792358b by Nate Graham, on behalf of Marco Martin.
Committed on 23/09/2022 at 22:21.
Pushed by ngraham into branch 'Plasma/5.26'.

Introduce a lock that blocks relayouts and config writes

The resize of the layout area can happen either by screen resolution
change or available screen area change (a panel appears or is resized)
This is not an atomic operation, as width and height are usually set in
2 different operations, and even worse the layout area is resized to
match the available one with an animation, so many intermediate resizes
that should never cause a relayout happen.

In normal operation an event compression timer limits the actual
relayouts to hopefully one, but if the system is really slowed down
(for instance, startup) the timer may expire and cause relayouts in
non useful sizes, losing the needed configuration.

In combination with
https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/1150

The lock blocks all relayout and config writes when the size of the
layout area doesn't correspond to corona availablescreenrect, which are
the only "settled" cases.


(cherry picked from commit ef57cd3d50f729f22558a20b03172da539e3bb71)

M  +23   -2    components/containmentlayoutmanager/appletslayout.cpp
M  +7    -0    components/containmentlayoutmanager/appletslayout.h

https://invent.kde.org/plasma/plasma-workspace/commit/59bf0f5a2081ed49a32a34083b7f5a9f0792358b
Comment 58 Nate Graham 2022-09-23 22:21:23 UTC
Git commit 22fa69d96d64422318e83cc57d9ed1d0a08c17b0 by Nate Graham, on behalf of Marco Martin.
Committed on 23/09/2022 at 22:21.
Pushed by ngraham into branch 'Plasma/5.26'.

Use relayout locking

This makes use of the layout locking freature introduced in
https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/2120
The resize of the layout area can happen either by screen resolution
change or available screen area change (a panel appears or is resized).

This is not an atomic operation, as width and height are usually set in
2 different operations, and even worse the layout area is resized to
match the available one with an animation, so many intermediate resizes
that should never cause a relayout happen.

A compression timer limits the actual relayouts to hopefully one,
 but if the system is really slowed down
(for instance, startup) the timer may expire and cause relayouts in
non useful sizes, losing the needed configuration.

The lock blocks all relayout and config writes when the size of the
layout area doesn't correspond to corona availablescreenrect, which are
the only "settled" cases.


(cherry picked from commit bd676333cf57659bc885928afe5d3fe908589e79)

M  +1    -0    containments/desktop/package/contents/ui/main.qml

https://invent.kde.org/plasma/plasma-desktop/commit/22fa69d96d64422318e83cc57d9ed1d0a08c17b0
Comment 59 Aaron Rainbolt 2022-10-06 17:41:35 UTC
Writing this as a comment and not a bug report since there's still some more work to be done, but here's some extra info:

While attempting to test the backports of this bug fix (https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/1178 and https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/2167), I used a special setup with a painfully slow emulated display in order to reproduce the bug and see if the fix worked. Initially, I was led to believe that the fix was failing in my testing, however on closer investigation, I believe there is a different though related bug that my setup is making show up.

How to reproduce the setup:

1: Install GNOME Boxes. This virtualization software has been able to reliably reproduce the issue for me most of the time. VirtualBox has a significantly faster emulated display and may not work.
2: Install Kubuntu 22.04 into GNOME Boxes, providing 8 GB of RAM and 100 GB of disk space. (NOTE: KDE neon Developer Edition won't work - this bug only is appearing on Kubuntu for me, possibly due to the use of KDE Plasma 5.24 in Kubuntu, as opposed to a build from Master in Neon.)
3: When the installation is finished, do `sudo apt update && sudo apt -y full-upgrade` in a terminal, then reboot the VM.
4: Change the display resolution within the VM to the maximum possible resolution.
5: Place some widgets on the desktop.
6: Log out and log back in. The widgets will end up being shifted or scrambled around.
7: Download the KDE Plasma 5.24.6 tarballs and signature files from https://download.kde.org/stable/plasma/5.24.6/ and GPG verify them, then extract them.
8: Build and install all of KDE Plasma 5.24.6 once piece at a time, using `sudo make install` for installation.
9: Reboot the VM.
10: Place widgets on the screen where you want them (repositioning the existing ones if you so desire).
11: Reboot the VM again. The widgets will become scrambled/shifted again, as expected.
12: Apply the code changes in the two linked merge requests, then rebuild plasma-desktop and plasma-workspace.
13: Reposition your widgets, and reboot again. The widgets will become scrambled/shifted again, despite the applied bug fix.

Note that, if you do this whole process on KDE neon Developer Edition, the widgets will never be shifted or scrambled around, *not even in step 11.* This indicates that this particular bug is outside of KDE Plasma, as two different distros running the exact same version of Plasma display different behavior.
Comment 60 Vladimir Yerilov 2022-10-09 15:10:01 UTC
Hope it will make it possible to use widgets on my multi-monitor setup without them losing their position or even disappear as it used to happen in the past. Will see.
Comment 61 Fushan Wen 2022-10-11 08:02:51 UTC
(In reply to Aaron Rainbolt from comment #59)
> Note that, if you do this whole process on KDE neon Developer Edition, the
> widgets will never be shifted or scrambled around, *not even in step 11.*
> This indicates that this particular bug is outside of KDE Plasma, as two
> different distros running the exact same version of Plasma display different
> behavior.


Looks like a Qt bug. If you can test https://invent.kde.org/qt/qt/qtbase/-/commit/75c0053006d05c930749652dfb0120c5a78689de it would be better
Comment 62 Erich Eickmeyer 2022-10-12 19:16:09 UTC
I see the fix has not been worked on for 5.24 for release in 5.24.7 (the current LTS release of Plasma). I highly suggest and urge this be done to keep with the 2-year LTS promise.
Comment 63 Nate Graham 2022-10-12 19:25:29 UTC
That's out of scope for this bug report. Not everything is backportable to 5.24, but in this case it is actually in progress anyway. Regardless, this is fixed in 5.26, so let's only re-open if it it's discovered to not in fact be fixed in 5.26.
Comment 64 Aaron Rainbolt 2022-10-14 02:02:42 UTC
Git commit 0a01c8910309fb9f289fe0aa58492e106d154548 by Aaron Rainbolt, on behalf of Marco Martin.
Committed on 13/10/2022 at 21:45.
Pushed by ngraham into branch 'Plasma/5.24'.

Introduce a lock that blocks relayouts and config writes

The resize of the layout area can happen either by screen resolution
change or available screen area change (a panel appears or is resized)
This is not an atomic operation, as width and height are usually set in
2 different operations, and even worse the layout area is resized to
  match the available one with an animation, so many intermediate resizes
that should never cause a relayout happen.
In normal operation an event compression timer limits the actual
relayouts to hopefully one, but if the system is really slowed down
(for instance, startup) the timer may expire and cause relayouts in
non useful sizes, losing the needed configuration
In combination with

The lock blocks all relayout and config writes when the size of the
layout area doesn't correspond to corona availablescreenrect, which are
the only "settled" cases.

M  +24   -2    components/containmentlayoutmanager/appletslayout.cpp
M  +7    -0    components/containmentlayoutmanager/appletslayout.h

https://invent.kde.org/plasma/plasma-workspace/commit/0a01c8910309fb9f289fe0aa58492e106d154548
Comment 65 Aaron Rainbolt 2022-10-14 02:05:10 UTC
Git commit 234cd860532449f017ecbbca6a8caad5473fcf8b by Aaron Rainbolt, on behalf of Marco Martin.
Committed on 13/10/2022 at 21:46.
Pushed by ngraham into branch 'Plasma/5.24'.

Use relayout locking

This makes use of the layout locking freature introduced in

The resize of the layout area can happen either by screen resolution
change or available screen area change (a panel appears or is resized)
This is not an atomic operation, as width and height are usually set in
2 different operations, and even worse the layout area is resized to
  match the available one with an animation, so many intermediate resizes
that should never cause a relayout happen.
A compression timer limits the actual relayouts to hopefully one,
 but if the system is really slowed down
(for instance, startup) the timer may expire and cause relayouts in
non useful sizes, losing the needed configuration
The lock blocks all relayout and config writes when the size of the
layout area doesn't correspond to corona availablescreenrect, which are
the only "settled" cases.

M  +3    -2    containments/desktop/package/contents/ui/main.qml

https://invent.kde.org/plasma/plasma-desktop/commit/234cd860532449f017ecbbca6a8caad5473fcf8b
Comment 66 Riccardo Robecchi 2022-10-14 18:58:14 UTC
I am reopening this as I see a bug happen in 5.26 on Neon which looks quite similar to this.
I have a desktop PC connected to my 4K TV via HDMI. The system is actually set to a resolution of 1920x1080, so I am not using the TV's default resolution but a lower one. After booting, the widgets I have on the desktop do not keep the position I set on the previous boot and are instead placed as if, at some point during the boot process, the resolution was set to an even lower value and then increased to Full-HD.
Comment 67 Nate Graham 2022-10-14 19:13:46 UTC
It's quite possible there are additional issues that can cause the same result, but for everyone's sanity, it's best if you open a new bug report, so we can investigate that issue on its own without spamming everyone subscribed to this one. Thanks!
Comment 68 Michael Mikowski 2022-10-17 19:17:29 UTC
During testing of 5.24.7 on Kubuntu 22.04 LTS, this has remained in place. Aaron Rainbolt, Riccardo Robecchi, Nate Graham: I have created a new bug 460618 to track and added you to the CC list.
Comment 69 Nate Graham 2022-10-18 19:09:04 UTC
Still getting some reports of this in 5.26. :( Those are being tracked in Bug 458038, and ultimately we may end up re-opening this. I guess there were more edge cases. Time will tell.