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, 7 Sep 2016 20:47:02 +0000 (22:47 +0200)
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.

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

index 6e681e4..eb02b43 100644 (file)
@@ -173,7 +173,8 @@ MainWin::MainWin(QWidget *parent)
     _titleSetter(this),
     _awayLog(0),
     _layoutLoaded(false),
     _titleSetter(this),
     _awayLog(0),
     _layoutLoaded(false),
-    _activeBufferViewIndex(-1)
+    _activeBufferViewIndex(-1),
+    _aboutToQuit(false)
 {
     setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
 
 {
     setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
 
@@ -1509,14 +1510,21 @@ void MainWin::closeEvent(QCloseEvent *event)
     QtUiSettings s;
     QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
     Q_ASSERT(app);
     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();
     }
         QtUi::hideMainWidget();
         event->ignore();
     }
-    else {
+    else if(!_aboutToQuit) {
+        _aboutToQuit = true;
         event->accept();
         quit();
     }
         event->accept();
         quit();
     }
+    else {
+        event->ignore();
+    }
 }
 
 
 }
 
 
index 93a7112..efe91c6 100644 (file)
@@ -225,5 +225,7 @@ private:
     QHash<int, BufferId> _jumpKeyMap;
     int _activeBufferViewIndex;
 
     QHash<int, BufferId> _jumpKeyMap;
     int _activeBufferViewIndex;
 
+    bool _aboutToQuit; //closeEvent can occur multiple times on OSX
+
     friend class QtUi;
 };
     friend class QtUi;
 };