Skip to content

Commit

Permalink
qt: Add GUIUtil::bringToFront
Browse files Browse the repository at this point in the history
  • Loading branch information
promag committed Nov 5, 2018
1 parent 6b1d297 commit 5796671
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@
#include <QFontDatabase>
#endif

#if defined(Q_OS_MAC)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

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

namespace GUIUtil {

QString dateTimeStr(const QDateTime &date)
Expand Down Expand Up @@ -353,6 +361,27 @@ bool isObscured(QWidget *w)
&& checkPoint(QPoint(w->width() / 2, w->height() / 2), 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);
#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()
{
fs::path pathDebug = GetDataDir() / "debug.log";
Expand Down Expand Up @@ -663,13 +692,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)


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

#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>

LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl);
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl)
{
Expand Down
3 changes: 3 additions & 0 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ namespace GUIUtil
// Determine whether a widget is hidden behind other windows
bool isObscured(QWidget *w);

// Activate, show and raise the widget
void bringToFront(QWidget* w);

// Open debug.log
void openDebugLogfile();

Expand Down

0 comments on commit 5796671

Please sign in to comment.