diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -534,7 +534,7 @@ fi AX_CHECK_LINK_FLAG([[-Wl,-headerpad_max_install_names]], [LDFLAGS="$LDFLAGS -Wl,-headerpad_max_install_names"]) - CPPFLAGS="$CPPFLAGS -DMAC_OSX" + CPPFLAGS="$CPPFLAGS -DMAC_OSX -DOBJC_OLD_DISPATCH_PROTOTYPES=0" OBJCXXFLAGS="$CXXFLAGS" ;; *android*) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -77,7 +77,7 @@ endif() if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - add_definitions(-DMAC_OSX) + add_definitions(-DMAC_OSX -DOBJC_OLD_DISPATCH_PROTOTYPES=0) endif() if(ENABLE_REDUCE_EXPORTS) diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -66,7 +66,8 @@ #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #include -#include + +void ForceActivation(); #endif namespace GUIUtil { @@ -379,11 +380,7 @@ void bringToFront(QWidget *w) { #ifdef Q_OS_MAC - // Force application activation on macOS. With Qt 5.4 this is required when - // an action in the dock menu is triggered. - id app = objc_msgSend((id)objc_getClass("NSApplication"), - sel_registerName("sharedApplication")); - objc_msgSend(app, sel_registerName("activateIgnoringOtherApps:"), YES); + ForceActivation(); #endif if (w) { diff --git a/src/qt/macdockiconhandler.mm b/src/qt/macdockiconhandler.mm --- a/src/qt/macdockiconhandler.mm +++ b/src/qt/macdockiconhandler.mm @@ -1,12 +1,11 @@ -// Copyright (c) 2011-2018 The Bitcoin Core developers +// Copyright (c) 2011-2019 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "macdockiconhandler.h" -#undef slots -#include -#include +#include +#include static MacDockIconHandler *s_instance = nullptr; @@ -21,10 +20,8 @@ } void setupDockClickHandler() { - 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")); + Class delClass = + (Class)[[[NSApplication sharedApplication] delegate] class]; SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:"); class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:"); @@ -42,3 +39,12 @@ void MacDockIconHandler::cleanup() { delete s_instance; } + +/** + * 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]; +}