Skip to content

Commit 5796671

Browse files
committed
qt: Add GUIUtil::bringToFront
1 parent 6b1d297 commit 5796671

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/qt/guiutil.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@
6060
#include <QFontDatabase>
6161
#endif
6262

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+
6371
namespace GUIUtil {
6472

6573
QString dateTimeStr(const QDateTime &date)
@@ -353,6 +361,27 @@ bool isObscured(QWidget *w)
353361
&& checkPoint(QPoint(w->width() / 2, w->height() / 2), w));
354362
}
355363

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+
356385
void openDebugLogfile()
357386
{
358387
fs::path pathDebug = GetDataDir() / "debug.log";
@@ -663,13 +692,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)
663692

664693

665694
#elif defined(Q_OS_MAC)
666-
#pragma GCC diagnostic push
667-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
668695
// based on: https://github.com/Mozketo/LaunchAtLoginController/blob/master/LaunchAtLoginController.m
669696

670-
#include <CoreFoundation/CoreFoundation.h>
671-
#include <CoreServices/CoreServices.h>
672-
673697
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl);
674698
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl)
675699
{

src/qt/guiutil.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ namespace GUIUtil
115115
// Determine whether a widget is hidden behind other windows
116116
bool isObscured(QWidget *w);
117117

118+
// Activate, show and raise the widget
119+
void bringToFront(QWidget* w);
120+
118121
// Open debug.log
119122
void openDebugLogfile();
120123

0 commit comments

Comments
 (0)