diff --git a/frontend/control/create-index-ask-dialog.cpp b/frontend/control/create-index-ask-dialog.cpp index 5c2a16a..8724ec4 100644 --- a/frontend/control/create-index-ask-dialog.cpp +++ b/frontend/control/create-index-ask-dialog.cpp @@ -167,5 +167,10 @@ bool CreateIndexAskDialog::eventFilter(QObject *watched, QEvent *event) this->hide(); return true; } + if (event->type() == QEvent::ActivationChange) { + if (QApplication::activeWindow() != this) { + Q_EMIT this->focusChanged(); + } + } return QDialog::eventFilter(watched, event); } diff --git a/frontend/control/create-index-ask-dialog.h b/frontend/control/create-index-ask-dialog.h index 4be0ae4..9d3d9f5 100644 --- a/frontend/control/create-index-ask-dialog.h +++ b/frontend/control/create-index-ask-dialog.h @@ -72,6 +72,7 @@ protected: Q_SIGNALS: void closed(); void btnClicked(const bool&, const bool&); + void focusChanged(); }; } diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index f9c980d..f9a6f11 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -155,6 +155,11 @@ void MainWindow::initConnections() connect(m_askDialog, &CreateIndexAskDialog::btnClicked, this, [ = ](const bool &isCreateIndex, const bool &isAskAgain) { setSearchMethodConfig(isCreateIndex, isAskAgain); }); + connect(m_askDialog, &CreateIndexAskDialog::focusChanged, this, [ & ] { + if (QApplication::activeWindow() != this) { + this->tryHideMainwindow(); + } + }); // connect(m_settingsBtn, &QPushButton::clicked, this, &MainWindow::settingsBtnClickedSlot); //主题改变时,更新自定义标题栏的图标 // connect(qApp, &QApplication::paletteChanged, this, [ = ]() { @@ -178,6 +183,7 @@ void MainWindow::bootOptionsFilter(QString opt) { this->m_searchBarWidget->setFocus(); } this->activateWindow(); + this->raise(); } } @@ -200,8 +206,8 @@ void MainWindow::trayIconActivatedSlot(QSystemTrayIcon::ActivationReason reason) clearSearchResult(); centerToScreen(this); // this->m_searchLineEdit->focusIn(); //打开主界面时输入框夺焦,可直接输入 - this->raise(); this->activateWindow(); + this->raise(); } else { tryHideMainwindow(); } @@ -377,7 +383,7 @@ void MainWindow::initTimer() { */ bool MainWindow::tryHideMainwindow() { - if (!m_isAskDialogVisible && QApplication::activeModalWidget() == nullptr) { + if (QApplication::activeModalWidget() == nullptr) { qDebug()<<"Mainwindow will be hidden"; m_currentSearchAsked = false; m_askTimer->stop(); @@ -454,7 +460,7 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event) if (watched == this) { //失焦退出 if (event->type() == QEvent::ActivationChange) { - if (QApplication::activeWindow() != this) { + if (QApplication::activeWindow() != this && QApplication::activeWindow() != m_askDialog) { tryHideMainwindow(); return true; } diff --git a/frontend/ukui-search-dbus-service.cpp b/frontend/ukui-search-dbus-service.cpp index f18958c..524c101 100644 --- a/frontend/ukui-search-dbus-service.cpp +++ b/frontend/ukui-search-dbus-service.cpp @@ -151,7 +151,7 @@ void UkuiSearchDbusServices::onSearchKeyword(const QString &display, const QStri void UkuiSearchDbusServices::onMainWindowSwitch(const QString &display) { if(m_display == display) { - if (m_mainWindow->isActiveWindow()) { + if (m_mainWindow->isVisible()) { m_mainWindow->tryHide(); } else { m_mainWindow->bootOptionsFilter("-s");