Fix cmd+Q invalidating the layout somehow
authorromibi <romibi@bluewin.ch>
Sat, 9 Jul 2016 16:30:44 +0000 (18:30 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 28 Feb 2018 22:24:42 +0000 (23:24 +0100)
On Mac OSX Qt Applications (with Frameworks packaged) receive the
CloseEvent twice. (See https://bugreports.qt.io/browse/QTBUG-43344)
This triggers a bug where Quassels Main-Window stays hidden and all
Layout states get reset on next launch.
Workaround by checking if event already received...

Resolves GH-230.

(cherry picked from commit 89175f57858e885d23dac1401f6f14db20ba9002)

src/qtui/mainwin.cpp
src/qtui/mainwin.h

index a1da410..262b4d8 100644 (file)
@@ -164,7 +164,8 @@ MainWin::MainWin(QWidget *parent)
     _titleSetter(this),
     _awayLog(0),
     _layoutLoaded(false),
-    _activeBufferViewIndex(-1)
+    _activeBufferViewIndex(-1),
+    _aboutToQuit(false)
 {
     setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
 
@@ -1482,14 +1483,21 @@ void MainWin::closeEvent(QCloseEvent *event)
     QtUiSettings s;
     QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
     Q_ASSERT(app);
-    if (!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
+    // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
+    // This messes up MainWinState/MainWinHidden save/restore.
+    // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
+    if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
         QtUi::hideMainWidget();
         event->ignore();
     }
-    else {
+    else if(!_aboutToQuit) {
+        _aboutToQuit = true;
         event->accept();
         quit();
     }
+    else {
+        event->ignore();
+    }
 }
 
 
index 6f0bf84..ed53610 100644 (file)
@@ -223,5 +223,7 @@ private:
     QHash<int, BufferId> _jumpKeyMap;
     int _activeBufferViewIndex;
 
+    bool _aboutToQuit; //closeEvent can occur multiple times on OSX
+
     friend class QtUi;
 };