diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index 6bcb226..832da4a 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -81,7 +81,6 @@ MainWindow::MainWindow(QWidget *parent) : installEventFilter(this); initConnections(); - // connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this,[&](WId activeWindowId){ // qDebug() << "activeWindowChanged!!!" << activeWindowId; // if (activeWindowId != this->winId()) { @@ -134,8 +133,7 @@ void MainWindow::initUi() { void MainWindow::initConnections() { connect(m_sys_tray_icon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivatedSlot); - connect(QApplication::primaryScreen(), &QScreen::geometryChanged, this, &MainWindow::monitorResolutionChange); - connect(qApp, &QApplication::primaryScreenChanged, this, &MainWindow::primaryScreenChangedSlot); + connect(QApplication::primaryScreen(), &QScreen::geometryChanged, this, &MainWindow::ScreenGeometryChanged); connect(m_askDialog, &CreateIndexAskDialog::closed, this, [ = ]() { m_isAskDialogVisible = false; }); @@ -258,21 +256,11 @@ void MainWindow::tryHide() this->tryHideMainwindow(); } -/** - * @brief monitorResolutionChange 监听屏幕改变 - * @param rect - */ -void MainWindow::monitorResolutionChange(QRect rect) { +void MainWindow::ScreenGeometryChanged(QRect rect) { Q_UNUSED(rect); -} - -/** - * @brief primaryScreenChangedSlot 监听分辨率改变 - * @param screen - */ -void MainWindow::primaryScreenChangedSlot(QScreen *screen) { - Q_UNUSED(screen); - + if(this->isVisible()) { + centerToScreen(this); + } } /** @@ -336,12 +324,10 @@ void MainWindow::centerToScreen(QWidget* widget) { if(!widget) return; KWindowSystem::setState(this->winId(),NET::SkipTaskbar | NET::SkipPager); - QDesktopWidget* m = QApplication::desktop(); - QRect desk_rect = m->screenGeometry(m->screenNumber(QCursor::pos())); + QRect desk_rect = qApp->screenAt(QCursor::pos())->geometry(); int desk_x = desk_rect.width(); int desk_y = desk_rect.height(); int x = widget->width(); - int y = widget->height(); widget->show(); kdk::WindowManager::setGeometry(this->windowHandle(),QRect(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 3 + desk_rect.top(), diff --git a/frontend/mainwindow.h b/frontend/mainwindow.h index 7c03cfd..cb5ed84 100644 --- a/frontend/mainwindow.h +++ b/frontend/mainwindow.h @@ -87,16 +87,8 @@ public: bool eventFilter(QObject *watched, QEvent *event) override; public Q_SLOTS: - /** - * @brief Monitor screen resolution - * @param rect: Screen resolution - */ - void monitorResolutionChange(QRect rect); - /** - * @brief Monitor primary screen changes - * @param screen: Primary screen - */ - void primaryScreenChangedSlot(QScreen *screen); + + void ScreenGeometryChanged(QRect rect); void bootOptionsFilter(QString opt); // 过滤终端命令 void clearSearchResult(); //清空搜索结果 void trayIconActivatedSlot(QSystemTrayIcon::ActivationReason reason);