|
60 | 60 | #include <QFontDatabase> |
61 | 61 | #endif |
62 | 62 |
|
| 63 | +#if defined(Q_OS_MAC) |
| 64 | +#pragma GCC diagnostic push |
| 65 | +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 66 | + |
| 67 | +#include <objc/objc-runtime.h> |
| 68 | +#include <CoreServices/CoreServices.h> |
| 69 | +#endif |
| 70 | + |
63 | 71 | namespace GUIUtil { |
64 | 72 |
|
65 | 73 | QString dateTimeStr(const QDateTime &date) |
@@ -353,6 +361,27 @@ bool isObscured(QWidget *w) |
353 | 361 | && checkPoint(QPoint(w->width() / 2, w->height() / 2), w)); |
354 | 362 | } |
355 | 363 |
|
| 364 | +void bringToFront(QWidget* w) |
| 365 | +{ |
| 366 | +#ifdef Q_OS_MAC |
| 367 | + // Force application activation on macOS. With Qt 5.4 this is required when |
| 368 | + // an action in the dock menu is triggered. |
| 369 | + id app = objc_msgSend((id) objc_getClass("NSApplication"), sel_registerName("sharedApplication")); |
| 370 | + objc_msgSend(app, sel_registerName("activateIgnoringOtherApps:"), YES); |
| 371 | +#endif |
| 372 | + |
| 373 | + if (w) { |
| 374 | + // activateWindow() (sometimes) helps with keyboard focus on Windows |
| 375 | + if (w->isMinimized()) { |
| 376 | + w->showNormal(); |
| 377 | + } else { |
| 378 | + w->show(); |
| 379 | + } |
| 380 | + w->activateWindow(); |
| 381 | + w->raise(); |
| 382 | + } |
| 383 | +} |
| 384 | + |
356 | 385 | void openDebugLogfile() |
357 | 386 | { |
358 | 387 | fs::path pathDebug = GetDataDir() / "debug.log"; |
@@ -663,13 +692,8 @@ bool SetStartOnSystemStartup(bool fAutoStart) |
663 | 692 |
|
664 | 693 |
|
665 | 694 | #elif defined(Q_OS_MAC) |
666 | | -#pragma GCC diagnostic push |
667 | | -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
668 | 695 | // based on: https://github.com/Mozketo/LaunchAtLoginController/blob/master/LaunchAtLoginController.m |
669 | 696 |
|
670 | | -#include <CoreFoundation/CoreFoundation.h> |
671 | | -#include <CoreServices/CoreServices.h> |
672 | | - |
673 | 697 | LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl); |
674 | 698 | LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl) |
675 | 699 | { |
|
0 commit comments