2019-08-25 06:13:39 -04:00
|
|
|
// Copyright (c) 2011-2019 The Bitcoin Core developers
|
2014-12-13 01:09:33 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-12-16 18:54:02 -03:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2011-10-07 08:21:45 -03:00
|
|
|
#include "macdockiconhandler.h"
|
|
|
|
|
2019-08-25 06:13:39 -04:00
|
|
|
#include <AppKit/AppKit.h>
|
|
|
|
#include <objc/runtime.h>
|
2011-10-07 08:21:45 -03:00
|
|
|
|
2017-08-16 12:26:07 -03:00
|
|
|
static MacDockIconHandler *s_instance = nullptr;
|
2011-10-07 08:21:45 -03:00
|
|
|
|
2018-11-02 05:58:14 -03:00
|
|
|
bool dockClickHandler(id self, SEL _cmd, ...) {
|
2015-03-11 20:08:22 -03:00
|
|
|
Q_UNUSED(self)
|
|
|
|
Q_UNUSED(_cmd)
|
2018-07-24 11:59:49 -04:00
|
|
|
|
2018-10-31 16:15:31 -03:00
|
|
|
Q_EMIT s_instance->dockIconClicked();
|
2018-07-24 11:59:49 -04:00
|
|
|
|
2018-10-31 16:15:31 -03:00
|
|
|
// Return NO (false) to suppress the default macOS actions
|
2015-03-11 20:08:22 -03:00
|
|
|
return false;
|
2011-10-07 08:21:45 -03:00
|
|
|
}
|
|
|
|
|
2015-03-11 20:08:22 -03:00
|
|
|
void setupDockClickHandler() {
|
2019-08-25 06:13:39 -04:00
|
|
|
Class delClass = (Class)[[[NSApplication sharedApplication] delegate] class];
|
2018-10-31 16:15:31 -03:00
|
|
|
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
|
|
|
|
class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:");
|
2011-10-07 08:21:45 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
MacDockIconHandler::MacDockIconHandler() : QObject()
|
|
|
|
{
|
2015-03-11 20:08:22 -03:00
|
|
|
setupDockClickHandler();
|
2011-10-07 08:21:45 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
MacDockIconHandler *MacDockIconHandler::instance()
|
|
|
|
{
|
|
|
|
if (!s_instance)
|
|
|
|
s_instance = new MacDockIconHandler();
|
|
|
|
return s_instance;
|
|
|
|
}
|
|
|
|
|
2015-03-13 11:40:53 -03:00
|
|
|
void MacDockIconHandler::cleanup()
|
|
|
|
{
|
|
|
|
delete s_instance;
|
|
|
|
}
|
2019-08-25 06:13:39 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Force application activation on macOS. With Qt 5.5.1 this is required when
|
|
|
|
* an action in the Dock menu is triggered.
|
|
|
|
* TODO: Define a Qt version where it's no-longer necessary.
|
|
|
|
*/
|
|
|
|
void ForceActivation()
|
|
|
|
{
|
|
|
|
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
|
|
|
|
}
|