diff options
author | Jonas Schnelli <jonas.schnelli@include7.ch> | 2015-03-12 00:08:22 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-03-16 13:56:13 +0100 |
commit | 81145a6ccd1060ce4b53c98b819a12bd0a99854f (patch) | |
tree | a1671920acdf0ddfe628b169d3b9db0e0cbdca3c /src | |
parent | 11173786ce0a8e170b6a96317b6bc82785ed5d1b (diff) |
[QT] fix OSX dock icon window reopening
fixes #5878
Rebased-From: 89e70e931d3d320d2dae4c296601aab113b2e508
Github-Pull: #5880
Diffstat (limited to 'src')
-rw-r--r-- | src/qt/macdockiconhandler.mm | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/src/qt/macdockiconhandler.mm b/src/qt/macdockiconhandler.mm index a2ff148d9d..5834a8dfca 100644 --- a/src/qt/macdockiconhandler.mm +++ b/src/qt/macdockiconhandler.mm @@ -11,52 +11,46 @@ #undef slots #include <Cocoa/Cocoa.h> +#include <objc/objc.h> +#include <objc/message.h> #if QT_VERSION < 0x050000 extern void qt_mac_set_dock_menu(QMenu *); #endif -@interface DockIconClickEventHandler : NSObject -{ - MacDockIconHandler* dockIconHandler; -} - -@end - -@implementation DockIconClickEventHandler +static MacDockIconHandler *s_instance = NULL; -- (id)initWithDockIconHandler:(MacDockIconHandler *)aDockIconHandler -{ - self = [super init]; - if (self) { - dockIconHandler = aDockIconHandler; - - [[NSAppleEventManager sharedAppleEventManager] - setEventHandler:self - andSelector:@selector(handleDockClickEvent:withReplyEvent:) - forEventClass:kCoreEventClass - andEventID:kAEReopenApplication]; - } - return self; +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; } -- (void)handleDockClickEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent -{ - Q_UNUSED(event) - Q_UNUSED(replyEvent) - - if (dockIconHandler) { - dockIconHandler->handleDockIconClickEvent(); +void setupDockClickHandler() { + Class cls = objc_getClass("NSApplication"); + id appInst = objc_msgSend((id)cls, sel_registerName("sharedApplication")); + + if (appInst != NULL) { + id delegate = objc_msgSend(appInst, sel_registerName("delegate")); + Class delClass = (Class)objc_msgSend(delegate, sel_registerName("class")); + SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:"); + if (class_getInstanceMethod(delClass, shouldHandle)) + class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:"); + else + class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler,"B@:"); } } -@end MacDockIconHandler::MacDockIconHandler() : QObject() { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - this->m_dockIconClickEventHandler = [[DockIconClickEventHandler alloc] initWithDockIconHandler:this]; + setupDockClickHandler(); this->m_dummyWidget = new QWidget(); this->m_dockMenu = new QMenu(this->m_dummyWidget); this->setMainWindow(NULL); @@ -119,7 +113,6 @@ void MacDockIconHandler::setIcon(const QIcon &icon) MacDockIconHandler *MacDockIconHandler::instance() { - static MacDockIconHandler *s_instance = NULL; if (!s_instance) s_instance = new MacDockIconHandler(); return s_instance; |