Do not use saved position if it falls outside of primary screen

- Only use saved position if the coordinates fall inside of the primary screen
  Prevents problems for people with laptops that sometimes but not always use
  external screens.
- Since we now set window position in C++ instead of QML, drop the
  dependency on qml-module-qt-labs-settings module.

Closes #91
This commit is contained in:
Floris Bos 2020-07-21 16:10:43 +02:00
parent 65c6377052
commit c08887f788
4 changed files with 45 additions and 11 deletions

View file

@ -18,6 +18,7 @@
#include <QTranslator>
#include <QLocale>
#include <QScreen>
#include <QSettings>
#ifndef QT_NO_WIDGETS
#include <QtWidgets/QApplication>
#endif
@ -164,7 +165,48 @@ int main(int argc, char *argv[])
qmlwindow->connect(&imageWriter, SIGNAL(finalizing()), qmlwindow, SLOT(onFinalizing()));
qmlwindow->connect(&imageWriter, SIGNAL(networkOnline()), qmlwindow, SLOT(fetchOSlist()));
#ifndef QT_NO_WIDGETS
QSettings settings;
/* Set window position */
auto screensize = app.primaryScreen()->geometry();
int x = settings.value("General/x", -1).toInt();
int y = settings.value("General/y", -1).toInt();
int w = qmlwindow->property("width").toInt();
int h = qmlwindow->property("height").toInt();
if (x != -1 && y != -1)
{
if ( (screensize.width()-x) < w || (screensize.height()-y) < h)
{
qDebug() << "Not restoring saved window position as it falls outside of primary screen";
x = y = -1;
}
}
if (x == -1 || y == -1)
{
x = qMax(1, (screensize.width()-w)/2);
y = qMax(1, (screensize.height()-h)/2);
}
qmlwindow->setProperty("x", x);
qmlwindow->setProperty("y", y);
#endif
int rc = app.exec();
#ifndef QT_NO_WIDGETS
int newX = qmlwindow->property("x").toInt();
int newY = qmlwindow->property("y").toInt();
if (x != newX || y != newY)
{
settings.setValue("General/x", newX);
settings.setValue("General/y", newY);
settings.sync();
}
#endif
return rc;
}