diff options
| author | Ross Nicoll <[email protected]> | 2021-07-07 19:40:10 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-07-07 19:40:10 +0100 |
| commit | c13e509a6c36b0cb12a7ad6c53ec257f9b0badba (patch) | |
| tree | 4c1035c1bf5a1cd0cdfee862f2177c89decaab46 /src | |
| parent | Merge pull request #2343 from micaelmalta/1.14.4-dev-fix-gitian (diff) | |
| parent | fix: macos qt build (diff) | |
| download | discoin-c13e509a6c36b0cb12a7ad6c53ec257f9b0badba.tar.xz discoin-c13e509a6c36b0cb12a7ad6c53ec257f9b0badba.zip | |
Merge pull request #2333 from micaelmalta/1.14.4-dev-fix-macos-gui
fix: macos qt build
Diffstat (limited to 'src')
| -rw-r--r-- | src/qt/guiutil.cpp | 20 | ||||
| -rw-r--r-- | src/qt/macdockiconhandler.mm | 38 |
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]; +} + |