aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMalta Micael <[email protected]>2021-06-22 19:36:59 -0400
committerMalta Micael <[email protected]>2021-07-01 14:43:09 -0400
commit83121eacf71214799deafda9d7730600afb42ae9 (patch)
tree4a0f8d75b3d70e00c7b9153b07ca931f2056853b /src
parentMerge pull request #2322 from patricklodder/1.14.4-actions-win-tests (diff)
downloaddiscoin-83121eacf71214799deafda9d7730600afb42ae9.tar.xz
discoin-83121eacf71214799deafda9d7730600afb42ae9.zip
fix: macos qt build
Diffstat (limited to 'src')
-rw-r--r--src/qt/guiutil.cpp20
-rw-r--r--src/qt/macdockiconhandler.mm38
2 files changed, 41 insertions, 17 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index cfd5b0e98..71fe49ae5 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -80,6 +80,9 @@ extern double NSAppKitVersionNumber;
#if !defined(NSAppKitVersionNumber10_9)
#define NSAppKitVersionNumber10_9 1265
#endif
+#include <QProcess>
+
+void ForceActivation();
#endif
namespace GUIUtil {
@@ -405,6 +408,23 @@ bool isObscured(QWidget *w)
&& checkPoint(QPoint(w->width() / 2, w->height() / 2), w));
}
+void bringToFront(QWidget* w)
+{
+ #ifdef Q_OS_MAC
+ ForceActivation();
+ #endif
+ if (w) {
+ // activateWindow() (sometimes) helps with keyboard focus on Windows
+ if (w->isMinimized()) {
+ w->showNormal();
+ } else {
+ w->show();
+ }
+ w->activateWindow();
+ w->raise();
+ }
+}
+
void openDebugLogfile()
{
boost::filesystem::path pathDebug = GetDataDir() / "debug.log";
diff --git a/src/qt/macdockiconhandler.mm b/src/qt/macdockiconhandler.mm
index a41d39d51..15f44927d 100644
--- a/src/qt/macdockiconhandler.mm
+++ b/src/qt/macdockiconhandler.mm
@@ -9,10 +9,9 @@
#include <QBuffer>
#include <QWidget>
-#undef slots
#include <Cocoa/Cocoa.h>
-#include <objc/objc.h>
-#include <objc/message.h>
+#include <AppKit/AppKit.h>
+#include <objc/runtime.h>
#if QT_VERSION < 0x050000
extern void qt_mac_set_dock_menu(QMenu *);
@@ -23,26 +22,20 @@ static MacDockIconHandler *s_instance = NULL;
bool dockClickHandler(id self,SEL _cmd,...) {
Q_UNUSED(self)
Q_UNUSED(_cmd)
-
+
s_instance->handleDockIconClickEvent();
-
+
// Return NO (false) to suppress the default OS X actions
return false;
}
void setupDockClickHandler() {
- Class cls = objc_getClass("NSApplication");
- id appInst = objc_msgSend((id)cls, sel_registerName("sharedApplication"));
-
- if (appInst != NULL) {
- id delegate = objc_msgSend(appInst, sel_registerName("delegate"));
- Class delClass = (Class)objc_msgSend(delegate, sel_registerName("class"));
- SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
- if (class_getInstanceMethod(delClass, shouldHandle))
- class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:");
- else
- class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler,"B@:");
- }
+ Class delClass = (Class)[[[NSApplication sharedApplication] delegate] class];
+ SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
+ if (class_getInstanceMethod(delClass, shouldHandle))
+ class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:");
+ else
+ class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler,"B@:");
}
@@ -132,3 +125,14 @@ void MacDockIconHandler::handleDockIconClickEvent()
Q_EMIT this->dockIconClicked();
}
+
+/**
+ * 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];
+}
+