Merge lp:~aacid/unity-2d/addSmallDelayOnQuit_812104 into lp:unity-2d

Proposed by Albert Astals Cid
Status: Merged
Approved by: Gerry Boland
Approved revision: 846
Merged at revision: 855
Proposed branch: lp:~aacid/unity-2d/addSmallDelayOnQuit_812104
Merge into: lp:unity-2d
Diff against target: 88 lines (+21/-6)
3 files modified
libunity-2d-private/src/gnomesessionclient.cpp (+15/-6)
libunity-2d-private/src/gnomesessionclient.h (+2/-0)
tests/manual-tests/other.txt (+4/-0)
To merge this branch: bzr merge lp:~aacid/unity-2d/addSmallDelayOnQuit_812104
Reviewer Review Type Date Requested Status
Gerry Boland (community) Approve
Review via email: mp+87623@code.launchpad.net

Description of the change

Wait for the Quit event to be delivered before really quitting

I think this is a problem either in Qt or in gnome-session, but we can "easily" workaround it ourselves, and could not find how to fix it "properly" so this seems like an acceptable workaround to me.

To post a comment you must log in.
845. By Albert Astals Cid

Wait for something less arbitrary than 500 msec

Revision history for this message
Gerry Boland (gerboland) wrote :

I think it would be a good idea to add a comment in the code to explain why you're doing this.

Also testing: can you write a test for this?

I need to test, but code looks good. This will make lots of people happy :)

Revision history for this message
Gerry Boland (gerboland) wrote :

In my tests, this reduces the logout time to about 10 seconds.

These 10 seconds are explained by this Qt4 bug, for which a patch is pending:
https://bugs.launchpad.net/ubuntu/+source/qt4-x11/+bug/912365

Please add a manual test for this bug, IMO this will be very tricky to automatically test.

review: Needs Fixing
846. By Albert Astals Cid

Add the logout manual test

Revision history for this message
Gerry Boland (gerboland) wrote :

Magic, thank you!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libunity-2d-private/src/gnomesessionclient.cpp'
2--- libunity-2d-private/src/gnomesessionclient.cpp 2011-03-23 14:43:45 +0000
3+++ libunity-2d-private/src/gnomesessionclient.cpp 2012-01-18 16:01:36 +0000
4@@ -50,6 +50,7 @@
5 QString m_applicationId;
6 QString m_clientPath;
7 bool m_waitingForEndSession;
8+ bool m_waitingForQuitEvent;
9
10 bool sendEndSessionResponse()
11 {
12@@ -73,8 +74,10 @@
13 , d(new GnomeSessionClientPrivate(applicationId))
14 {
15 d->m_waitingForEndSession = false;
16+ d->m_waitingForQuitEvent = true;
17 connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()),
18 SLOT(waitForEndSession()));
19+ QCoreApplication::instance()->installEventFilter(this);
20 }
21
22 GnomeSessionClient::~GnomeSessionClient()
23@@ -99,6 +102,14 @@
24 SLOT(slotRegisterClientFinished(QDBusPendingCallWatcher*)));
25 }
26
27+bool GnomeSessionClient::eventFilter(QObject* watched, QEvent* event)
28+{
29+ if (event->type() == QEvent::Quit) {
30+ d->m_waitingForQuitEvent = false;
31+ }
32+ return false;
33+}
34+
35 void GnomeSessionClient::slotRegisterClientFinished(QDBusPendingCallWatcher* watcher)
36 {
37 QDBusPendingReply<QDBusObjectPath> reply = *watcher;
38@@ -139,24 +150,22 @@
39 UQ_DEBUG;
40 d->sendEndSessionResponse();
41 d->m_waitingForEndSession = false;
42- QCoreApplication::quit();
43 }
44
45 void GnomeSessionClient::waitForEndSession()
46 {
47- if (!d->m_waitingForEndSession) {
48- return;
49- }
50-
51 UQ_DEBUG << "Application is about to quit, waiting for gnome-session to call us back";
52 QTime watchDog;
53 watchDog.start();
54- while (d->m_waitingForEndSession && watchDog.elapsed() < MAX_END_SESSION_WAIT * 1000) {
55+ while ((d->m_waitingForEndSession || d->m_waitingForQuitEvent) && watchDog.elapsed() < MAX_END_SESSION_WAIT * 1000) {
56 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
57 }
58 if (d->m_waitingForEndSession) {
59 UQ_WARNING << "gnome-session did not call back after" << MAX_END_SESSION_WAIT << "seconds, leaving";
60 }
61+ if (d->m_waitingForQuitEvent) {
62+ UQ_WARNING << "did not get the Quit event after" << MAX_END_SESSION_WAIT << "seconds, leaving";
63+ }
64 }
65
66 #include "gnomesessionclient.moc"
67
68=== modified file 'libunity-2d-private/src/gnomesessionclient.h'
69--- libunity-2d-private/src/gnomesessionclient.h 2011-03-22 09:58:45 +0000
70+++ libunity-2d-private/src/gnomesessionclient.h 2012-01-18 16:01:36 +0000
71@@ -47,6 +47,8 @@
72
73 void connectToSessionManager();
74
75+ bool eventFilter(QObject* watched, QEvent* event);
76+
77 private Q_SLOTS:
78 void slotRegisterClientFinished(QDBusPendingCallWatcher* watcher);
79 void stop();
80
81=== added file 'tests/manual-tests/other.txt'
82--- tests/manual-tests/other.txt 1970-01-01 00:00:00 +0000
83+++ tests/manual-tests/other.txt 2012-01-18 16:01:36 +0000
84@@ -0,0 +1,4 @@
85+----
86+ * Logout of a Unity-2d session
87+
88+-> Logout is "fast", with "fast" meaning it is not 30 seconds (gnome-session timeout) nor 10 (Qt clipboard manager timeout on app shutdown)

Subscribers

People subscribed via source and target branches