Skip to content

Commit 7d6f63c

Browse files
committed
Merge #16720: qt: Replace objc_msgSend() function calls with the native Objective-C syntax
0bb33b5 qt: Replace objc_msgSend with native syntax (Hennadii Stepanov) Pull request description: Changes in Xcode 11 Objective-C Runtime cause an error (#16387) during building on MacOS 10.15 Catalina. This PR fixes this issue by replacing `objc_msgSend()` function calls with the native Objective-C syntax. Refs: - [changes in `objc_msgSend` function](https://developer.apple.com/documentation/objectivec/1456712-objc_msgsend?changes=latest_minor&language=objc) - [`OBJC_OLD_DISPATCH_PROTOTYPES` macro](https://developer.apple.com/documentation/objectivec/objc_old_dispatch_prototypes?language=objc) ACKs for top commit: l2a5b1: ACK 0bb33b5 - Diff looks good. Sending messages via native Objective-C code feels more robust and is more readable than casting all the `objc_msgSend` function calls to the appropriate function signature (which would also have fixed the issue). jonasschnelli: utACK 0bb33b5 - Confirmed that the called macOS framework function is available on our build targets. fanquake: ACK 0bb33b5 - Still works as expected. Tree-SHA512: c09cb684d06bd1da053a17c182b7bb1642e45bb347d26c76e1c5d835c320567caee366d85e34bb7f2be38e63ed041e0d06a56c2a9d89f7e5bece9b19cc5c6772
2 parents 495db72 + 0bb33b5 commit 7d6f63c

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ case $host in
585585
fi
586586

587587
AX_CHECK_LINK_FLAG([[-Wl,-headerpad_max_install_names]], [LDFLAGS="$LDFLAGS -Wl,-headerpad_max_install_names"])
588-
CPPFLAGS="$CPPFLAGS -DMAC_OSX"
588+
CPPFLAGS="$CPPFLAGS -DMAC_OSX -DOBJC_OLD_DISPATCH_PROTOTYPES=0"
589589
OBJCXXFLAGS="$CXXFLAGS"
590590
;;
591591
*android*)

src/qt/guiutil.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@
5757
#pragma GCC diagnostic push
5858
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
5959

60-
#include <objc/objc-runtime.h>
6160
#include <CoreServices/CoreServices.h>
6261
#include <QProcess>
62+
63+
void ForceActivation();
6364
#endif
6465

6566
namespace GUIUtil {
@@ -359,10 +360,7 @@ bool isObscured(QWidget *w)
359360
void bringToFront(QWidget* w)
360361
{
361362
#ifdef Q_OS_MAC
362-
// Force application activation on macOS. With Qt 5.4 this is required when
363-
// an action in the dock menu is triggered.
364-
id app = objc_msgSend((id) objc_getClass("NSApplication"), sel_registerName("sharedApplication"));
365-
objc_msgSend(app, sel_registerName("activateIgnoringOtherApps:"), YES);
363+
ForceActivation();
366364
#endif
367365

368366
if (w) {

src/qt/macdockiconhandler.mm

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// Copyright (c) 2011-2018 The Bitcoin Core developers
1+
// Copyright (c) 2011-2019 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include "macdockiconhandler.h"
66

7-
#undef slots
8-
#include <objc/objc.h>
9-
#include <objc/message.h>
7+
#include <AppKit/AppKit.h>
8+
#include <objc/runtime.h>
109

1110
static MacDockIconHandler *s_instance = nullptr;
1211

@@ -21,9 +20,7 @@ bool dockClickHandler(id self, SEL _cmd, ...) {
2120
}
2221

2322
void setupDockClickHandler() {
24-
id app = objc_msgSend((id)objc_getClass("NSApplication"), sel_registerName("sharedApplication"));
25-
id delegate = objc_msgSend(app, sel_registerName("delegate"));
26-
Class delClass = (Class)objc_msgSend(delegate, sel_registerName("class"));
23+
Class delClass = (Class)[[[NSApplication sharedApplication] delegate] class];
2724
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
2825
class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:");
2926
}
@@ -44,3 +41,13 @@ void setupDockClickHandler() {
4441
{
4542
delete s_instance;
4643
}
44+
45+
/**
46+
* Force application activation on macOS. With Qt 5.5.1 this is required when
47+
* an action in the Dock menu is triggered.
48+
* TODO: Define a Qt version where it's no-longer necessary.
49+
*/
50+
void ForceActivation()
51+
{
52+
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
53+
}

0 commit comments

Comments
 (0)