Skip to content

Commit

Permalink
Merge pull request #773 from qtumproject/neil/fix-osx-build
Browse files Browse the repository at this point in the history
qt: Replace objc_msgSend with native syntax
  • Loading branch information
qtum-neil committed Oct 14, 2019
2 parents 784b346 + dbd2bfe commit bdd5738
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ case $host in
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*)
Expand Down
8 changes: 3 additions & 5 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

#include <objc/objc-runtime.h>
#include <CoreServices/CoreServices.h>
#include <QProcess>

void ForceActivation();
#endif

namespace GUIUtil {
Expand Down Expand Up @@ -366,10 +367,7 @@ bool isObscured(QWidget *w)
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) {
Expand Down
21 changes: 14 additions & 7 deletions src/qt/macdockiconhandler.mm
Original file line number Diff line number Diff line change
@@ -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 <objc/objc.h>
#include <objc/message.h>
#include <AppKit/AppKit.h>
#include <objc/runtime.h>

static MacDockIconHandler *s_instance = nullptr;

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

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@:");
}
Expand All @@ -44,3 +41,13 @@ void setupDockClickHandler() {
{
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];
}

0 comments on commit bdd5738

Please sign in to comment.