diff --git a/main/GuiUtils.hpp b/main/GuiUtils.hpp index 82c729f..792d171 100644 --- a/main/GuiUtils.hpp +++ b/main/GuiUtils.hpp @@ -1,9 +1,5 @@ #pragma once -#ifdef Q_OS_WIN -#include "sys/windows/guihelper.h" -#endif - // Dialogs #define Dialog_DialogBasicSettings "DialogBasicSettings" @@ -80,23 +76,7 @@ if (result.isEmpty()) CACHE.a = ""; \ editor->deleteLater(); -// System - -#define _ACTIVE_THIS_WINDOW_COMMON \ - hide(); \ - showMinimized(); \ - showNormal(); \ - activateWindow(); \ - setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); \ - raise(); - -#ifdef Q_OS_WIN -#define ACTIVE_THIS_WINDOW \ - _ACTIVE_THIS_WINDOW_COMMON \ - Windows_QWidget_SetForegroundWindow(this); -#else -#define ACTIVE_THIS_WINDOW _ACTIVE_THIS_WINDOW_COMMON -#endif +// #define ADD_ASTERISK(parent) \ for (auto label: parent->findChildren()) { \ diff --git a/main/NekoGui_Utils.cpp b/main/NekoGui_Utils.cpp index a81ef23..83fc4ef 100644 --- a/main/NekoGui_Utils.cpp +++ b/main/NekoGui_Utils.cpp @@ -18,6 +18,10 @@ #include #include +#ifdef Q_OS_WIN +#include "sys/windows/guihelper.h" +#endif + QStringList SplitLines(const QString &_string) { #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) return _string.split(QRegularExpression("[\r\n]"), Qt::SplitBehaviorFlags::SkipEmptyParts); @@ -211,6 +215,16 @@ int MessageBoxInfo(const QString &title, const QString &text) { return QMessageBox::information(GetMessageBoxParent(), title, text); } +void ActivateWindow(QWidget *w) { + w->setWindowState(w->windowState() & ~Qt::WindowMinimized); + w->setVisible(true); +#ifdef Q_OS_WIN + Windows_QWidget_SetForegroundWindow(w); +#endif + w->raise(); + w->activateWindow(); +} + void runOnUiThread(const std::function &callback, QObject *parent) { // any thread auto *timer = new QTimer(); diff --git a/main/NekoGui_Utils.hpp b/main/NekoGui_Utils.hpp index 6a53239..8b9719c 100644 --- a/main/NekoGui_Utils.hpp +++ b/main/NekoGui_Utils.hpp @@ -147,6 +147,10 @@ int MessageBoxWarning(const QString &title, const QString &text); int MessageBoxInfo(const QString &title, const QString &text); +void ActivateWindow(QWidget *w); + +// + void runOnUiThread(const std::function &callback, QObject *parent = nullptr); void runOnNewThread(const std::function &callback); diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index df47284..02d2e29 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -251,7 +251,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi if (this->isVisible()) { hide(); } else { - ACTIVE_THIS_WINDOW + ActivateWindow(this); } } }); @@ -554,7 +554,7 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info) this->exit_reason = 2; on_menu_exit_triggered(); } else if (info == "Raise") { - ACTIVE_THIS_WINDOW + ActivateWindow(this); } else if (info == "ClearConnectionList") { refresh_connection_list({}); }