summaryrefslogtreecommitdiff
path: root/src/settings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/settings.cpp')
-rw-r--r--src/settings.cpp90
1 files changed, 72 insertions, 18 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index 7cea52fb..19eca5ec 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -22,7 +22,9 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "serverinfo.h"
#include "executableslist.h"
#include "appconfig.h"
-#include "expanderwidget.h"
+#include "env.h"
+#include "envmetrics.h"
+#include <expanderwidget.h>
#include <utility.h>
#include <iplugingame.h>
@@ -604,21 +606,80 @@ void GeometrySettings::resetIfNeeded()
removeSection(m_Settings, "Geometry");
}
-void GeometrySettings::saveGeometry(const QWidget* w)
+void GeometrySettings::saveGeometry(const QMainWindow* w)
+{
+ saveWindowGeometry(w);
+}
+
+bool GeometrySettings::restoreGeometry(QMainWindow* w) const
+{
+ return restoreWindowGeometry(w);
+}
+
+void GeometrySettings::saveGeometry(const QDialog* d)
+{
+ saveWindowGeometry(d);
+}
+
+bool GeometrySettings::restoreGeometry(QDialog* d) const
+{
+ return restoreWindowGeometry(d);
+}
+
+void GeometrySettings::saveWindowGeometry(const QWidget* w)
{
set(m_Settings, "Geometry", geoSettingName(w), w->saveGeometry());
}
-bool GeometrySettings::restoreGeometry(QWidget* w) const
+bool GeometrySettings::restoreWindowGeometry(QWidget* w) const
{
if (auto v=getOptional<QByteArray>(m_Settings, "Geometry", geoSettingName(w))) {
w->restoreGeometry(*v);
+ ensureWindowOnScreen(w);
return true;
}
return false;
}
+void GeometrySettings::ensureWindowOnScreen(QWidget* w) const
+{
+ // users report that the main window and/or dialogs are displayed off-screen;
+ // the usual workaround is keyboard navigation to move it
+ //
+ // qt should have code that deals with multiple monitors and off-screen
+ // geometries, but there seems to be bugs or inconsistencies that can't be
+ // reproduced
+ //
+ // the closest would probably be https://bugreports.qt.io/browse/QTBUG-64498,
+ // which is about multiple monitors and high dpi, but it seems fixed as of
+ // 5.12.4, which is shipped with 2.2.1
+ //
+ // without being to reproduce the problem, some simple checks are made in a
+ // timer, which may mitigate the issues
+
+ QTimer::singleShot(100, w, [w] {
+ const auto borders = 20;
+
+ // desktop geometry, made smaller to make sure there isn't just a few pixels
+ const auto originalDg = env::Environment().metrics().desktopGeometry();
+ const auto dg = originalDg.adjusted(borders, borders, -borders, -borders);
+
+ const auto g = w->geometry();
+
+ if (!dg.intersects(g)) {
+ log::warn(
+ "window '{}' is offscreen, moving to main monitor; geo={}, desktop={}",
+ w->objectName(), g, originalDg);
+
+ // widget is off-screen, center it on main monitor
+ centerOnMonitor(w, -1);
+
+ log::warn("window '{}' now at {}", w->objectName(), w->geometry());
+ }
+ });
+}
+
void GeometrySettings::saveState(const QMainWindow* w)
{
set(m_Settings, "Geometry", stateSettingName(w), w->saveState());
@@ -771,12 +832,17 @@ void GeometrySettings::setModInfoTabOrder(const QString& names)
void GeometrySettings::centerOnMainWindowMonitor(QWidget* w)
{
const auto monitor = getOptional<int>(
- m_Settings, "Geometry", "MainWindow_monitor");
+ m_Settings, "Geometry", "MainWindow_monitor").value_or(-1);
+
+ centerOnMonitor(w, monitor);
+}
+void GeometrySettings::centerOnMonitor(QWidget* w, int monitor)
+{
QPoint center;
- if (monitor && QGuiApplication::screens().size() > *monitor) {
- center = QGuiApplication::screens().at(*monitor)->geometry().center();
+ if (monitor >= 0 && monitor < QGuiApplication::screens().size()) {
+ center = QGuiApplication::screens().at(monitor)->geometry().center();
} else {
center = QGuiApplication::primaryScreen()->geometry().center();
}
@@ -1887,15 +1953,3 @@ void DiagnosticsSettings::setCrashDumpsMax(int n)
{
set(m_Settings, "Settings", "crash_dumps_max", n);
}
-
-
-GeometrySaver::GeometrySaver(Settings& s, QDialog* dialog)
- : m_settings(s), m_dialog(dialog)
-{
- m_settings.geometry().restoreGeometry(m_dialog);
-}
-
-GeometrySaver::~GeometrySaver()
-{
- m_settings.geometry().saveGeometry(m_dialog);
-}