Skip to content

Commit 0bb33b5

Browse files
committed
qt: Replace objc_msgSend with native syntax
1 parent db67101 commit 0bb33b5

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
@@ -58,9 +58,10 @@
5858
#pragma GCC diagnostic push
5959
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
6060

61-
#include <objc/objc-runtime.h>
6261
#include <CoreServices/CoreServices.h>
6362
#include <QProcess>
63+
64+
void ForceActivation();
6465
#endif
6566

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

369367
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)