aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoão Barbosa <joao.paulo.barbosa@gmail.com>2018-08-31 23:08:07 +0100
committerJoão Barbosa <joao.paulo.barbosa@gmail.com>2018-12-30 11:22:20 +0000
commitac73c7d433e609f4516136c543623c6c6f0245e2 (patch)
tree6b72720f104e7689211a1cc4dbab7e048290b0ac
parent0c2fb87dc1ec1b13fa7abab038f6c52ce0c749e9 (diff)
downloadbitcoin-ac73c7d433e609f4516136c543623c6c6f0245e2.tar.xz
qt: Add GUIUtil::bringToFront
Github-Pull: #14123 Rebased-From: 5796671e1dd8a2d0b1e750c2dce19a10af624095
-rw-r--r--src/qt/guiutil.cpp34
-rw-r--r--src/qt/guiutil.h3
2 files changed, 32 insertions, 5 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index f8f031041c..0d80651431 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -64,6 +64,14 @@
static fs::detail::utf8_codecvt_facet utf8;
+#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)
@@ -357,6 +365,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";
@@ -682,13 +711,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)
{
diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h
index 011827e134..f1d0aa48ef 100644
--- a/src/qt/guiutil.h
+++ b/src/qt/guiutil.h
@@ -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();