From 1febf47a719949b0c7ac788572a1eb289705a808 Mon Sep 17 00:00:00 2001 From: Roberto Santacroce Martins Date: Tue, 2 Jun 2020 12:26:25 +0200 Subject: [PATCH] added force application activation on macosx with qt 5.5.1 --- src/qt/guiutil.cpp | 10 ++++------ src/qt/macdockiconhandler.mm | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 285c22f1fd..2aa8698b1f 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -59,9 +59,10 @@ #if defined(Q_OS_MAC) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#include + +void ForceActivation(); -#include -#include #endif namespace GUIUtil { @@ -359,10 +360,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) { diff --git a/src/qt/macdockiconhandler.mm b/src/qt/macdockiconhandler.mm index 102adce6c5..26b0245932 100644 --- a/src/qt/macdockiconhandler.mm +++ b/src/qt/macdockiconhandler.mm @@ -5,8 +5,8 @@ #include "macdockiconhandler.h" #undef slots -#include -#include +#include +#include static MacDockIconHandler *s_instance = nullptr; @@ -21,9 +21,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@:"); } @@ -44,3 +42,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]; +}