From ddb443b5503f37878b8350ac48f542a5584fcfc3 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Thu, 5 Dec 2024 14:36:46 -0500 Subject: [PATCH] fix: Mainwindow can not start off screen Fixes #7451 --- src/gui/src/MainWindow.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index dea931364..e2ba069bd 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -101,7 +101,6 @@ MainWindow::~MainWindow() void MainWindow::restoreWindow() { - const auto &windowSize = m_AppConfig.mainWindowSize(); if (windowSize.has_value()) { qDebug("restoring main window size"); @@ -110,8 +109,23 @@ void MainWindow::restoreWindow() const auto &windowPosition = m_AppConfig.mainWindowPosition(); if (windowPosition.has_value()) { - qDebug("restoring main window position"); - move(windowPosition.value()); + int x = 0; + int y = 0; + int w = 0; + int h = 0; + for (auto screen : QGuiApplication::screens()) { + auto geo = screen->geometry(); + x = std::min(geo.x(), x); + y = std::min(geo.y(), y); + w = std::max(geo.x() + geo.width(), w); + h = std::max(geo.y() + geo.height(), h); + } + const QSize totalScreenSize(w, h); + const QPoint point = windowPosition.value(); + if (point.x() < totalScreenSize.width() && point.y() < totalScreenSize.height()) { + qDebug("restoring main window position"); + move(point); + } } else { // center main window in middle of screen const auto screen = QGuiApplication::primaryScreen();