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
=== modified file 'libunity-2d-private/src/gnomesessionclient.cpp'
--- libunity-2d-private/src/gnomesessionclient.cpp 2011-03-23 14:43:45 +0000
+++ libunity-2d-private/src/gnomesessionclient.cpp 2012-01-18 16:01:36 +0000
@@ -50,6 +50,7 @@
50 QString m_applicationId;50 QString m_applicationId;
51 QString m_clientPath;51 QString m_clientPath;
52 bool m_waitingForEndSession;52 bool m_waitingForEndSession;
53 bool m_waitingForQuitEvent;
5354
54 bool sendEndSessionResponse()55 bool sendEndSessionResponse()
55 {56 {
@@ -73,8 +74,10 @@
73, d(new GnomeSessionClientPrivate(applicationId))74, d(new GnomeSessionClientPrivate(applicationId))
74{75{
75 d->m_waitingForEndSession = false;76 d->m_waitingForEndSession = false;
77 d->m_waitingForQuitEvent = true;
76 connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()),78 connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()),
77 SLOT(waitForEndSession()));79 SLOT(waitForEndSession()));
80 QCoreApplication::instance()->installEventFilter(this);
78}81}
7982
80GnomeSessionClient::~GnomeSessionClient()83GnomeSessionClient::~GnomeSessionClient()
@@ -99,6 +102,14 @@
99 SLOT(slotRegisterClientFinished(QDBusPendingCallWatcher*)));102 SLOT(slotRegisterClientFinished(QDBusPendingCallWatcher*)));
100}103}
101104
105bool GnomeSessionClient::eventFilter(QObject* watched, QEvent* event)
106{
107 if (event->type() == QEvent::Quit) {
108 d->m_waitingForQuitEvent = false;
109 }
110 return false;
111}
112
102void GnomeSessionClient::slotRegisterClientFinished(QDBusPendingCallWatcher* watcher)113void GnomeSessionClient::slotRegisterClientFinished(QDBusPendingCallWatcher* watcher)
103{114{
104 QDBusPendingReply<QDBusObjectPath> reply = *watcher;115 QDBusPendingReply<QDBusObjectPath> reply = *watcher;
@@ -139,24 +150,22 @@
139 UQ_DEBUG;150 UQ_DEBUG;
140 d->sendEndSessionResponse();151 d->sendEndSessionResponse();
141 d->m_waitingForEndSession = false;152 d->m_waitingForEndSession = false;
142 QCoreApplication::quit();
143}153}
144154
145void GnomeSessionClient::waitForEndSession()155void GnomeSessionClient::waitForEndSession()
146{156{
147 if (!d->m_waitingForEndSession) {
148 return;
149 }
150
151 UQ_DEBUG << "Application is about to quit, waiting for gnome-session to call us back";157 UQ_DEBUG << "Application is about to quit, waiting for gnome-session to call us back";
152 QTime watchDog;158 QTime watchDog;
153 watchDog.start();159 watchDog.start();
154 while (d->m_waitingForEndSession && watchDog.elapsed() < MAX_END_SESSION_WAIT * 1000) {160 while ((d->m_waitingForEndSession || d->m_waitingForQuitEvent) && watchDog.elapsed() < MAX_END_SESSION_WAIT * 1000) {
155 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);161 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
156 }162 }
157 if (d->m_waitingForEndSession) {163 if (d->m_waitingForEndSession) {
158 UQ_WARNING << "gnome-session did not call back after" << MAX_END_SESSION_WAIT << "seconds, leaving";164 UQ_WARNING << "gnome-session did not call back after" << MAX_END_SESSION_WAIT << "seconds, leaving";
159 }165 }
166 if (d->m_waitingForQuitEvent) {
167 UQ_WARNING << "did not get the Quit event after" << MAX_END_SESSION_WAIT << "seconds, leaving";
168 }
160}169}
161170
162#include "gnomesessionclient.moc"171#include "gnomesessionclient.moc"
163172
=== modified file 'libunity-2d-private/src/gnomesessionclient.h'
--- libunity-2d-private/src/gnomesessionclient.h 2011-03-22 09:58:45 +0000
+++ libunity-2d-private/src/gnomesessionclient.h 2012-01-18 16:01:36 +0000
@@ -47,6 +47,8 @@
4747
48 void connectToSessionManager();48 void connectToSessionManager();
4949
50 bool eventFilter(QObject* watched, QEvent* event);
51
50private Q_SLOTS:52private Q_SLOTS:
51 void slotRegisterClientFinished(QDBusPendingCallWatcher* watcher);53 void slotRegisterClientFinished(QDBusPendingCallWatcher* watcher);
52 void stop();54 void stop();
5355
=== added file 'tests/manual-tests/other.txt'
--- tests/manual-tests/other.txt 1970-01-01 00:00:00 +0000
+++ tests/manual-tests/other.txt 2012-01-18 16:01:36 +0000
@@ -0,0 +1,4 @@
1----
2 * Logout of a Unity-2d session
3
4-> 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