Merge pull request #5880
8b60808
[QT] some mac specifiy cleanup (memory handling, unnecessary code) (Jonas Schnelli)89e70e9
[QT] fix OSX dock icon window reopening (Jonas Schnelli)
This commit is contained in:
commit
226f880498
@ -237,7 +237,7 @@ BitcoinGUI::~BitcoinGUI()
|
|||||||
trayIcon->hide();
|
trayIcon->hide();
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
delete appMenuBar;
|
delete appMenuBar;
|
||||||
MacDockIconHandler::instance()->setMainWindow(NULL);
|
MacDockIconHandler::cleanup();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delete rpcConsole;
|
delete rpcConsole;
|
||||||
|
@ -14,12 +14,6 @@ class QMenu;
|
|||||||
class QWidget;
|
class QWidget;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
#ifdef __OBJC__
|
|
||||||
@class DockIconClickEventHandler;
|
|
||||||
#else
|
|
||||||
class DockIconClickEventHandler;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Macintosh-specific dock icon handler.
|
/** Macintosh-specific dock icon handler.
|
||||||
*/
|
*/
|
||||||
class MacDockIconHandler : public QObject
|
class MacDockIconHandler : public QObject
|
||||||
@ -33,7 +27,7 @@ public:
|
|||||||
void setIcon(const QIcon &icon);
|
void setIcon(const QIcon &icon);
|
||||||
void setMainWindow(QMainWindow *window);
|
void setMainWindow(QMainWindow *window);
|
||||||
static MacDockIconHandler *instance();
|
static MacDockIconHandler *instance();
|
||||||
|
static void cleanup();
|
||||||
void handleDockIconClickEvent();
|
void handleDockIconClickEvent();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@ -42,7 +36,6 @@ signals:
|
|||||||
private:
|
private:
|
||||||
MacDockIconHandler();
|
MacDockIconHandler();
|
||||||
|
|
||||||
DockIconClickEventHandler *m_dockIconClickEventHandler;
|
|
||||||
QWidget *m_dummyWidget;
|
QWidget *m_dummyWidget;
|
||||||
QMenu *m_dockMenu;
|
QMenu *m_dockMenu;
|
||||||
QMainWindow *mainWindow;
|
QMainWindow *mainWindow;
|
||||||
|
@ -11,52 +11,46 @@
|
|||||||
|
|
||||||
#undef slots
|
#undef slots
|
||||||
#include <Cocoa/Cocoa.h>
|
#include <Cocoa/Cocoa.h>
|
||||||
|
#include <objc/objc.h>
|
||||||
|
#include <objc/message.h>
|
||||||
|
|
||||||
#if QT_VERSION < 0x050000
|
#if QT_VERSION < 0x050000
|
||||||
extern void qt_mac_set_dock_menu(QMenu *);
|
extern void qt_mac_set_dock_menu(QMenu *);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@interface DockIconClickEventHandler : NSObject
|
static MacDockIconHandler *s_instance = NULL;
|
||||||
{
|
|
||||||
MacDockIconHandler* dockIconHandler;
|
bool dockClickHandler(id self,SEL _cmd,...) {
|
||||||
|
Q_UNUSED(self)
|
||||||
|
Q_UNUSED(_cmd)
|
||||||
|
|
||||||
|
s_instance->handleDockIconClickEvent();
|
||||||
|
|
||||||
|
// Return NO (false) to suppress the default OS X actions
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
void setupDockClickHandler() {
|
||||||
|
Class cls = objc_getClass("NSApplication");
|
||||||
|
id appInst = objc_msgSend((id)cls, sel_registerName("sharedApplication"));
|
||||||
|
|
||||||
@implementation DockIconClickEventHandler
|
if (appInst != NULL) {
|
||||||
|
id delegate = objc_msgSend(appInst, sel_registerName("delegate"));
|
||||||
- (id)initWithDockIconHandler:(MacDockIconHandler *)aDockIconHandler
|
Class delClass = (Class)objc_msgSend(delegate, sel_registerName("class"));
|
||||||
{
|
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
|
||||||
self = [super init];
|
if (class_getInstanceMethod(delClass, shouldHandle))
|
||||||
if (self) {
|
class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:");
|
||||||
dockIconHandler = aDockIconHandler;
|
else
|
||||||
|
class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler,"B@:");
|
||||||
[[NSAppleEventManager sharedAppleEventManager]
|
|
||||||
setEventHandler:self
|
|
||||||
andSelector:@selector(handleDockClickEvent:withReplyEvent:)
|
|
||||||
forEventClass:kCoreEventClass
|
|
||||||
andEventID:kAEReopenApplication];
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)handleDockClickEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent
|
|
||||||
{
|
|
||||||
Q_UNUSED(event)
|
|
||||||
Q_UNUSED(replyEvent)
|
|
||||||
|
|
||||||
if (dockIconHandler) {
|
|
||||||
dockIconHandler->handleDockIconClickEvent();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
MacDockIconHandler::MacDockIconHandler() : QObject()
|
MacDockIconHandler::MacDockIconHandler() : QObject()
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
this->m_dockIconClickEventHandler = [[DockIconClickEventHandler alloc] initWithDockIconHandler:this];
|
setupDockClickHandler();
|
||||||
this->m_dummyWidget = new QWidget();
|
this->m_dummyWidget = new QWidget();
|
||||||
this->m_dockMenu = new QMenu(this->m_dummyWidget);
|
this->m_dockMenu = new QMenu(this->m_dummyWidget);
|
||||||
this->setMainWindow(NULL);
|
this->setMainWindow(NULL);
|
||||||
@ -74,7 +68,6 @@ void MacDockIconHandler::setMainWindow(QMainWindow *window) {
|
|||||||
|
|
||||||
MacDockIconHandler::~MacDockIconHandler()
|
MacDockIconHandler::~MacDockIconHandler()
|
||||||
{
|
{
|
||||||
[this->m_dockIconClickEventHandler release];
|
|
||||||
delete this->m_dummyWidget;
|
delete this->m_dummyWidget;
|
||||||
this->setMainWindow(NULL);
|
this->setMainWindow(NULL);
|
||||||
}
|
}
|
||||||
@ -119,12 +112,16 @@ void MacDockIconHandler::setIcon(const QIcon &icon)
|
|||||||
|
|
||||||
MacDockIconHandler *MacDockIconHandler::instance()
|
MacDockIconHandler *MacDockIconHandler::instance()
|
||||||
{
|
{
|
||||||
static MacDockIconHandler *s_instance = NULL;
|
|
||||||
if (!s_instance)
|
if (!s_instance)
|
||||||
s_instance = new MacDockIconHandler();
|
s_instance = new MacDockIconHandler();
|
||||||
return s_instance;
|
return s_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MacDockIconHandler::cleanup()
|
||||||
|
{
|
||||||
|
delete s_instance;
|
||||||
|
}
|
||||||
|
|
||||||
void MacDockIconHandler::handleDockIconClickEvent()
|
void MacDockIconHandler::handleDockIconClickEvent()
|
||||||
{
|
{
|
||||||
if (this->mainWindow)
|
if (this->mainWindow)
|
||||||
|
Loading…
Reference in New Issue
Block a user