Bug 326893 - Some clients close windows on session exit before kwin stored the session data, this are not restored correctly
Summary: Some clients close windows on session exit before kwin stored the session dat...
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: core (show other bugs)
Version: 4.11.5
Platform: Kubuntu Linux
: NOR normal
Target Milestone: 4.11
Assignee: KWin default assignee
URL: https://git.reviewboard.kde.org/r/114...
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-30 16:45 UTC by Leon Maurer
Modified: 2016-03-16 09:11 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:
thomas.luebking: ReviewRequest+


Attachments
kwin session file where restore of thunderbird on correct desktop fails (4.12 KB, application/octet-stream)
2013-12-17 09:22 UTC, Nils Kneuper
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Leon Maurer 2013-10-30 16:45:34 UTC
I have KDE set to "Restore previous session" on login (using System Settings), and while the applications do open at startup, they do not appear in the correct places. I have four virtual desktops, and on login, all the applications appear on the same virtual desktop -- the virtual desktop I see first when logging in.

I understand from Bug 62157 that non-KDE programs may have this problem, but this is affecting all programs -- including KDE applications like System Monitor, Kate, and Dolphin.

I think that KDE programs used to restore to the correct location, but I can't say when this stopped happening.

Reproducible: Always

Steps to Reproduce:
1. Set KDE to "Restore previous session"
2. Log out with KDE applications open
3. Log back in
Comment 1 Martin Droessler 2013-11-01 11:41:53 UTC
I can confirm the described behaviour. I encounter the same using KDE 4.11.2 on Kubuntu 13.10
Comment 2 Massimiliano 2013-11-01 18:36:18 UTC
Me too confirm the behaviour. It did not happen with Kubuntu and KDE 4.10.
I have changed KDE set to start an empty session and added scripts with wmctrl command to start the applications on different virtual desktops on the starting of the system.
Comment 3 Thomas Lübking 2013-11-18 01:21:34 UTC
http://kde.6490.n7.nabble.com/Session-management-effectively-broken-td1538259.html

QApplication::isSessionRestored() is (still) always false for me (in KWin)
And I doubt that this is some recent development, since kwin relies on that function at least since 

commit 05507ee2939e4d5420f3c9599d00986906d61959
Author: Luboš Luňák
Date:   Sun Apr 29 17:35:43 2007 +0000

    branches/work/kwin_composite becomes new trunk kwin.

which is the root of our commit history...

Afaics, startkde/ksmserver however needed to start kwin with the "-session" switch (where the <session> parameter apparently can just be "0" - QApplicationPrivate assigns is_session_restored as long as there's the switch and some parameter (while session id and key will be naturally junk)

No idea whether or why that has ever been changed in startkde.
Comment 4 Norman Hull 2013-11-20 16:21:50 UTC
First noticed this a couple of subreleases ago in Arch.  Dolphin and Kmail always restored to the correct desktop, as did konsole.  Non-kde apps all restore to the desktop from which I initiate the shutdown.

Just installed openSuSE 13.1 with Thunderbird.  Konsole still opens on correct desktop, Chrome, Thunderbird and Firefox all open on the desktop I was using at shutdowm
Comment 5 Thomas Lübking 2013-11-20 16:27:41 UTC
The application can of course keep this info as well; it's just not maintained by kwin, as kwin is - as much as i can say - really never invoked ::isSessionRestored() == true
Comment 6 Norman Hull 2013-11-20 17:09:50 UTC
On 20/11/13 16:27, Thomas Lübking wrote:
> https://bugs.kde.org/show_bug.cgi?id=326893
>
> --- Comment #5 from Thomas Lübking <thomas.luebking@gmail.com> ---
> The application can of course keep this info as well; it's just not
maintained
> by kwin, as kwin is - as much as i can say - really never invoked
> ::isSessionRestored() == true
>
That does not make sense.  All prior versions of KDE always restored all
- including non-KDE - applications to the correct desktop.

This bug exhibits the effect of only restoring KDE applications, and
piles all others on top of each other on the last desktop in use at
shutdown.  How can a non-KDE app 'keep this info as well'?  This
misbehaviour is damaging to the reputation of the best desktop
environment there is.  Would I rather use a Mac? No- and I shudder at
the prospect of the horrible Gnome desktop, while Windows is beneath
contempt.

There has been nothing as good as KDE since I encountered KDE2.  Please
restore it to its full glory.
Comment 7 Thomas Lübking 2013-11-20 17:39:23 UTC
The kwin code didn't change since 2007...
No idea what else would have changed (fast grepping the startkde/ksmserver log didn't help)

Every application can of course store and restore it's virtual desktop - it's public information.
Comment 8 Norman Hull 2013-11-20 22:30:52 UTC
On 20/11/13 17:39, Thomas Lübking wrote:
> Every application can of course store and restore it's virtual desktop - it's
> public information.
You seem to be saying that the KDE devs have deliberately removed one of
its great features and expect every app out there to adapt to make up
for it.  I thought that the motivation for Matthias Ettrich was to
produce a uniform desktop environment - he was frustrated by every app
doing its own thing and doing it differently.  If all (non KDE) apps
must handle everything for themselves, what is the benefit of a desktop
environment over a window manager?

Whichever way you want to look at it, removing a great feature that has
been there for so many years is - if not a bug - a very retrograde step.
will KDE be going clunky and dumbed down like Gnome next?

I generally use KDE apps, but there are some things for which I must use
others - such as Chrome/Firefox/Opera/Gimp.  I used to love
demonstrating the benefits of Linux/KDE by showing how I not only had
multiple virtual desktops but ones that reinitialised when booting.  Now
I have a horrible mess where I cannot get at my KDE apps because of a
pile of non-KDE apps sitting on top of them
Comment 9 Norman Hull 2013-11-20 22:38:00 UTC
No idea what else would have changed (fast grepping the startkde/ksmserver log didn't help)
Try diffing between versions.  This is definitely a problem that should not have occurred.  If the code you are looking at hasn't changed since 2007 the problem must be elsewhere - in code that appeared in late 4.10 or in 4.11, I believe.  Unfortunately its beginnings in my Arch system were initially masked by a different problem that I had at the time.
Comment 10 Thomas Lübking 2013-11-20 23:22:11 UTC
> You seem to be saying that the KDE devs have deliberately removed
Please don't put stupid bullshit in my mouth. Thank you.
Nobody has even remotely suggested deliberate action.
Comment 11 Thomas Lübking 2013-11-21 00:24:51 UTC
Proof that it's not a kwin issue: run
kwin -session $(ls -1 "$(kde4-config --path config | cut -d':' -f1)session" | sed -e '/kwin/!d; s/kwin_//g')

(ensure that
ls -1 "$(kde4-config --path config | cut -d':' -f1)session"
actually lists your session data)

-> Session is properly restored.
Even adding that as KDEWM export to startkde doesn't help - kwin started through ksmserver does not receive those parameters and is started with isSessionRestored false

So much from my side - i've really no interest in further dealing with some ppl. around here.
Comment 12 Leon Maurer 2013-11-21 01:15:03 UTC
I'm sorry that this thread degraded; Norman's comments were out of line.

FWIW, KDE applications are being restored to the correct positions; I could have swore that they weren't restored correctly when I filed this bug, but maybe I'm just crazy. (Perhaps I was just fooled by a combination of bug 317278 and non-KDE applications being restored incorrectly.)

Still, many non-KDE apps aren't being restored correctly; I tested a bunch of random ones and Firefox, Gerbv, Thunderbird, wxMaxima, DOSemu, Chrome, gitg, and inkscape have this problem. Some non-KDE applications did restore correctly, like LibreOffice Writer, xterm, GNU Emacs.

If the issue isn't with KDE, does anyone have thoughts on where the problem lies and whose attention we should bring this to? I guess I could file bugs with all the problem applications, but that doesn't sound like the right approach. I recall that these applications used to restore correctly, so I'd guess that they didn't all break at once; these issues probably have a common cause.
Comment 13 Norman Hull 2013-11-21 09:36:26 UTC
Did not mean to offend, but I was misled by Thomas's insistence on apps maintaining the information  for themselves.  I gained a false impression and apologise.

Thomas goes on to say:

Proof that it's not a kwin issue: run
kwin -session $(ls -1 "$(kde4-config --path config | cut -d':' -f1)session" |
sed -e '/kwin/!d; s/kwin_//g')

(ensure that
ls -1 "$(kde4-config --path config | cut -d':' -f1)session"
actually lists your session data)

-> Session is properly restored.
Even adding that as KDEWM export to startkde doesn't help - kwin started
through ksmserver does not receive those parameters and is started with
isSessionRestored false

So he has actually narrowed down the area at fault.  What now needs to be investigated is how ksmserver handles accessing and passing on session information.  The session information *is* getting through for KDE apps but not for non-KDE apps.
Comment 14 Nils Kneuper 2013-12-17 09:22:34 UTC
Created attachment 84138 [details]
kwin session file where restore of thunderbird on correct desktop fails

For me the issue of non KDE apps being restored to the virtual desktop loaded at startup started to appear with the release of 4.11.0. Before this everything was fine, with this new series firefox and thunderbird were always restored to the desktop active at start (which is identical to the one open at shutdown).

Interestingly the session file for KDE shows the applications firefox and thunderbird associated to the correct desktop each (firefox to 3 and thunderbird to 4). I attached my session file.

What should happen (got 4 virtual desktops):
1) Nothing on desktop 1.
2) Konsole on desktop 2.
3) Firefox, konversation, kopete and kaffeine on desktop 3.
4) Thunderbird on desktop 4.
5) Superkaramba on all desktops.
6) Plasma loaded and on all desktops.
7) At start restore to desktop 3.

What was interesting is that firefox and thunderbird had no /usr/bin/ prefix in their wmcommand?= entry. But changing that one had no effect on thunderbird being shown on the wrong desktop instead of on desktop 4.
Comment 15 Thomas Lübking 2014-01-11 02:01:16 UTC
Randomly returning:
a) I did and do not insist that applications would store this data, but said they *can* re/store this data as well (comment #5)
b) nobody has said the issue would not be with KDE. It *is* with KDE - apparently with the way KWin is invoked by the session manager.
c) please be aware that FF/TB are about the worst clients to test this, for Mozilla is /very/ eager to get them in sight and for this purpose either tries to move them to the current desktop or change the current desktop whenever it feels like. For clean testing, i suggest a client like xterm.
Comment 16 Leon Maurer 2014-01-11 02:36:58 UTC
xterm was restored correctly. (I tested a number of applications and noted in comment 12 which did and did not restore correctly.)

Let me know if there are more applications I should test.
Comment 17 Thomas Lübking 2014-01-11 08:35:22 UTC
This is a two level issue (was for me)

1. ps ax | krep kwin
  556 ?        Sl     0:11 /usr/bin/kwin --replace -session 10d3d76761000138940825800000024960000_1389410931_93899

If there's no "-session <key>" parameter, you're facing a condition where kwin is started w/o being asked to restore the window attributes from the last session.

Happened to me because ksmserver is very picky about reloading stuff.
If the stored restart/command does not fit the expected WM command, it will just call the configured WM w/o any further parameters (including session control)
(Here, "kwin" is a script to call /usr/bin/kwin, thus leading to mismatching "kwin" ./. "/usr/bin/kwin" comparism)

2. Beyond that (well, now that session restorage works in principle), apparently clients like at least TheGimp do not set/restore SM_CLIENT_ID - neither directly, nor on their leader window.
SM_CLIENT_ID is the relevant property for session restorage, but KWin has some heuristics to match the session data to the new window anyway.

I assume this broke by making the wmClientMachine detection asynchronous, see bug #308391 - "and the case of session management is" not ultimately so "very academic" since WM_CLIENT_MACHINE is $(cat /etc/hostname) - not the stored "localhost"

tl; dr:
Those windows do actually simply not support session management, but nevertheless there's a regression in KWin's workaround for that.
         -> (2) is a KWin bug, (1) is ebkac


@Martin
The intended patch is to drop client machine comparism on session restorage heuristics (to cause the academic problem ;-)
Comment 18 Thomas Lübking 2014-01-11 10:58:32 UTC
FTR, this is *far* more complex.

1. hostname resolution matches arbitrarily ie. depends on threading, what mostly depends on whether the resolution is cached by the system etc.

2. eg. "chromium" has some junk (not valid utf-8) character trailing the WM name (here) - so it fails on that test as well

3. eg. qupzilla does not even make it into session storage, ie. the window closed before kwin was told to save the session

Only hostname mismatch would be a new problem - everything else *must* have been present before 4.11

For the "WM_COMMAND contains junk" issue we'd have to check  whether that's part of getStringProperty() or the property is really "broken" - and in the latter case loose the heuristics
I've atm. no idea on how to deal with the "i'll just piss off early" case - we cannot record windows that have already gone.
Comment 19 Thomas Lübking 2014-01-29 19:22:37 UTC
Git commit 2d156caaf93291514723e3f811d25e534f88ac23 by Thomas Lübking.
Committed on 11/01/2014 at 11:50.
Pushed by luebking into branch 'KDE/4.11'.

cut spurious \0 byte from string properties

added with 26c263cc1de9cf0af66c12d0d746cd8ae7b1744a
FIXED-IN: 4.11.6
REVIEW: 114963

M  +4    -1    kwin/utils.cpp

http://commits.kde.org/kde-workspace/2d156caaf93291514723e3f811d25e534f88ac23
Comment 20 Thomas Lübking 2014-01-29 19:22:39 UTC
Git commit cad8faa9ed14b7ee4f3a9928d2ff955aecfa0b3c by Thomas Lübking.
Committed on 11/01/2014 at 11:52.
Pushed by luebking into branch 'KDE/4.11'.

remove clientMachine from session handling

since the hostname is resolved asynchronous, testing it can easily fail
FIXED-IN: 4.11.6
REVIEW: 114963

M  +0    -4    kwin/sm.cpp

http://commits.kde.org/kde-workspace/cad8faa9ed14b7ee4f3a9928d2ff955aecfa0b3c
Comment 21 Max Schettler 2016-03-16 02:09:05 UTC
Shouldn't this issue be closed?
Comment 22 Thomas Lübking 2016-03-16 09:11:49 UTC
Let's say "fixed what was fixable"
Early leaving clients are violating the session protocol and as we recently figured Qt4 & Qt5 are completely broken itr and were only covered by KApplication/KMainWindow in Qt4; Qt5 situation is "evolving" (ie. there's now a flag that allows clients to override the broken-by-default behavior)