diff --git a/src/frontend/TopBar.cpp b/src/frontend/TopBar.cpp index 4867fa98..f9d13038 100644 --- a/src/frontend/TopBar.cpp +++ b/src/frontend/TopBar.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -110,19 +111,31 @@ void TopBar::SetupTopBar() { this->setFixedSize(QSize(this->width(), this->height())); this->setAttribute(Qt::WA_TranslucentBackground); - if (gSettings->getTopBarWindowPosition() == QPoint(0, 0)) { + QPoint savedPos = gSettings->getTopBarWindowPosition(); + bool validPosition = false; + + if (savedPos != QPoint(0, 0)) { + // Check if the saved position is within any known screen + for (QScreen *screen : QGuiApplication::screens()) { + if (screen->geometry().contains(savedPos)) { + validPosition = true; + break; + } + } + } + + if (validPosition) { + move(savedPos); + } else { int width = this->frameGeometry().width(); int height = this->frameGeometry().height(); - QApplication *app = (QApplication *) QApplication::instance(); - QScreen *screen = app->primaryScreen(); + QScreen *screen = QGuiApplication::primaryScreen(); int screenWidth = screen->geometry().width(); int screenHeight = screen->geometry().height(); this->setGeometry((screenWidth / 2) - (width / 2), (screenHeight / 2) - (height / 2), width, height); - } else { - move(gSettings->getTopBarWindowPosition()); } }