From 076be21d401b2f3051264eb33ace3413eaeb0fe4 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Thu, 26 Aug 2021 22:37:35 +0200 Subject: [PATCH] Validate window position before setting it --- src/general.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/general.cpp b/src/general.cpp index 8e90871c..9dbefa53 100644 --- a/src/general.cpp +++ b/src/general.cpp @@ -3,6 +3,10 @@ #include "headers/version.h" #include +#include +#if __linux__ +#include +#endif QMetaObject::Connection inactivePluse; @@ -377,9 +381,23 @@ void AdvSceneSwitcher::setTabOrder() connect(bar, &QTabBar::tabMoved, this, &AdvSceneSwitcher::on_tabMoved); } +bool windowPosValid(QPoint pos) +{ +#if __linux__ + // QDesktopWidget::availableGeometry() is deprecated. + // Switch to QGuiApplication::screenAt() when it is available on most Linux platforms. + QDesktopWidget *desktop = QApplication::desktop(); + auto screen = desktop->availableGeometry(pos); + return (pos.x() > screen.x()) && (pos.y() > screen.y()) && + (pos.x() < screen.width() && (pos.y() < screen.height())); +#else + return !!QGuiApplication::screenAt(pos); +#endif +} + void AdvSceneSwitcher::restoreWindowGeo() { - if (switcher->saveWindowGeo) { + if (switcher->saveWindowGeo && windowPosValid(switcher->windowPos)) { this->resize(switcher->windowSize); this->move(switcher->windowPos); }