Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@
#if defined(Q_OS_MAC)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#include <QProcess>

void ForceActivation();

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

namespace GUIUtil {
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 13 additions & 5 deletions src/qt/macdockiconhandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#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 +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@:");
}
Expand All @@ -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];
}