2018-10-31 20:15:31 +01:00
|
|
|
// Copyright (c) 2011-2018 The Bitcoin Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-12-16 22:54:02 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2011-10-07 13:21:45 +02:00
|
|
|
#include "macdockiconhandler.h"
|
|
|
|
|
|
|
|
#undef slots
|
2015-03-12 00:08:22 +01:00
|
|
|
#include <objc/objc.h>
|
|
|
|
#include <objc/message.h>
|
2011-10-07 13:21:45 +02:00
|
|
|
|
2017-08-16 17:26:07 +02:00
|
|
|
static MacDockIconHandler *s_instance = nullptr;
|
2011-10-07 13:21:45 +02:00
|
|
|
|
2018-11-02 09:58:14 +01:00
|
|
|
bool dockClickHandler(id self, SEL _cmd, ...) {
|
2015-03-12 00:08:22 +01:00
|
|
|
Q_UNUSED(self)
|
|
|
|
Q_UNUSED(_cmd)
|
2018-07-24 17:59:49 +02:00
|
|
|
|
2018-10-31 20:15:31 +01:00
|
|
|
Q_EMIT s_instance->dockIconClicked();
|
2018-07-24 17:59:49 +02:00
|
|
|
|
2018-10-31 20:15:31 +01:00
|
|
|
// Return NO (false) to suppress the default macOS actions
|
2015-03-12 00:08:22 +01:00
|
|
|
return false;
|
2011-10-07 13:21:45 +02:00
|
|
|
}
|
|
|
|
|
2015-03-12 00:08:22 +01:00
|
|
|
void setupDockClickHandler() {
|
2018-10-31 20:15:31 +01:00
|
|
|
id app = objc_msgSend((id)objc_getClass("NSApplication"), sel_registerName("sharedApplication"));
|
|
|
|
id delegate = objc_msgSend(app, sel_registerName("delegate"));
|
|
|
|
Class delClass = (Class)objc_msgSend(delegate, sel_registerName("class"));
|
|
|
|
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
|
|
|
|
class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:");
|
2011-10-07 13:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MacDockIconHandler::MacDockIconHandler() : QObject()
|
|
|
|
{
|
2015-03-12 00:08:22 +01:00
|
|
|
setupDockClickHandler();
|
2011-10-07 13:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MacDockIconHandler *MacDockIconHandler::instance()
|
|
|
|
{
|
|
|
|
if (!s_instance)
|
|
|
|
s_instance = new MacDockIconHandler();
|
|
|
|
return s_instance;
|
|
|
|
}
|
|
|
|
|
2015-03-13 15:40:53 +01:00
|
|
|
void MacDockIconHandler::cleanup()
|
|
|
|
{
|
|
|
|
delete s_instance;
|
|
|
|
}
|