From 4d17a1b0c29e8fd8510c75db1efb203b9b4f9eb0 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Sun, 14 Apr 2013 22:11:55 +0200 Subject: [PATCH] fix: GUI Disappearing #1522 (Mac OSX) - this solution works stable on mac and ensures that the window get's reopened when the user clicks the dock icon . - tested on 10.8 with Qt4.8.4 and Qt5.0.1 Signed-off-by: Jonas Schnelli --- src/qt/bitcoingui.cpp | 2 ++ src/qt/macdockiconhandler.h | 4 +++- src/qt/macdockiconhandler.mm | 11 ++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 14d738d9d..f6ea945c7 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -155,6 +155,7 @@ BitcoinGUI::~BitcoinGUI() trayIcon->hide(); #ifdef Q_OS_MAC delete appMenuBar; + MacDockIconHandler::instance()->setMainWindow(NULL); #endif } @@ -382,6 +383,7 @@ void BitcoinGUI::createTrayIconMenu() #else // Note: On Mac, the dock icon is used to provide the tray's functionality. MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance(); + dockIconHandler->setMainWindow((QMainWindow *)this); trayIconMenu = dockIconHandler->dockMenu(); #endif diff --git a/src/qt/macdockiconhandler.h b/src/qt/macdockiconhandler.h index 5018456aa..765b00475 100644 --- a/src/qt/macdockiconhandler.h +++ b/src/qt/macdockiconhandler.h @@ -2,6 +2,7 @@ #define MACDOCKICONHANDLER_H #include +#include QT_BEGIN_NAMESPACE class QMenu; @@ -26,7 +27,7 @@ public: QMenu *dockMenu(); void setIcon(const QIcon &icon); - + void setMainWindow(QMainWindow *window); static MacDockIconHandler *instance(); void handleDockIconClickEvent(); @@ -40,6 +41,7 @@ private: DockIconClickEventHandler *m_dockIconClickEventHandler; QWidget *m_dummyWidget; QMenu *m_dockMenu; + QMainWindow *mainWindow; }; #endif // MACDOCKICONCLICKHANDLER_H diff --git a/src/qt/macdockiconhandler.mm b/src/qt/macdockiconhandler.mm index ea868401c..b6ea8e1d0 100644 --- a/src/qt/macdockiconhandler.mm +++ b/src/qt/macdockiconhandler.mm @@ -37,8 +37,9 @@ extern void qt_mac_set_dock_menu(QMenu*); Q_UNUSED(event) Q_UNUSED(replyEvent) - if (dockIconHandler) + if (dockIconHandler) { dockIconHandler->handleDockIconClickEvent(); + } } @end @@ -54,10 +55,15 @@ MacDockIconHandler::MacDockIconHandler() : QObject() [pool release]; } +void MacDockIconHandler::setMainWindow(QMainWindow *window) { + this->mainWindow = window; +} + MacDockIconHandler::~MacDockIconHandler() { [this->m_dockIconClickEventHandler release]; delete this->m_dummyWidget; + this->setMainWindow(NULL); } QMenu *MacDockIconHandler::dockMenu() @@ -94,5 +100,8 @@ MacDockIconHandler *MacDockIconHandler::instance() void MacDockIconHandler::handleDockIconClickEvent() { + this->mainWindow->activateWindow(); + this->mainWindow->show(); + emit this->dockIconClicked(); }