From c08887f788bf1e67d246403d61dd5025e2b4765d Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Tue, 21 Jul 2020 16:10:43 +0200 Subject: [PATCH] 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 --- README.md | 2 +- debian/control | 4 ++-- main.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ main.qml | 8 -------- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 540a7a1..aa96af4 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Install the build dependencies: ``` sudo apt install --no-install-recommends build-essential devscripts debhelper cmake git libarchive-dev libcurl4-openssl-dev \ qtbase5-dev qtbase5-dev-tools qtdeclarative5-dev libqt5svg5-dev qttools5-dev qt5-default libssl-dev \ - qml-module-qtquick2 qml-module-qtquick-controls2 qml-module-qt-labs-settings qml-module-qtquick-layouts qml-module-qtquick-templates2 qml-module-qtquick-window2 qml-module-qtgraphicaleffects + qml-module-qtquick2 qml-module-qtquick-controls2 qml-module-qtquick-layouts qml-module-qtquick-templates2 qml-module-qtquick-window2 qml-module-qtgraphicaleffects ``` #### Get the source diff --git a/debian/control b/debian/control index b83dfa6..d4f7c94 100644 --- a/debian/control +++ b/debian/control @@ -4,14 +4,14 @@ Priority: optional Maintainer: Floris Bos Build-Depends: debhelper (>= 10), cmake, libarchive-dev, libcurl4-openssl-dev | libcurl4-gnutls-dev, qtbase5-dev, qtbase5-dev-tools, qtdeclarative5-dev, libqt5svg5-dev, qttools5-dev, libssl-dev, - qml-module-qtquick2, qml-module-qtquick-controls2, qml-module-qt-labs-settings, qml-module-qtquick-layouts, qml-module-qtquick-templates2, qml-module-qtquick-window2, qml-module-qtgraphicaleffects + qml-module-qtquick2, qml-module-qtquick-controls2, qml-module-qtquick-layouts, qml-module-qtquick-templates2, qml-module-qtquick-window2, qml-module-qtgraphicaleffects Standards-Version: 4.1.2 Homepage: https://www.raspberrypi.org/ Package: rpi-imager Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, - qml-module-qtquick2, qml-module-qtquick-controls2, qml-module-qt-labs-settings, qml-module-qtquick-layouts, qml-module-qtquick-templates2, qml-module-qtquick-window2, qml-module-qtgraphicaleffects, + qml-module-qtquick2, qml-module-qtquick-controls2, qml-module-qtquick-layouts, qml-module-qtquick-templates2, qml-module-qtquick-window2, qml-module-qtgraphicaleffects, dosfstools, fdisk Recommends: udisks2 Description: Raspberry Pi imaging utility diff --git a/main.cpp b/main.cpp index 0af33c6..3c4f690 100644 --- a/main.cpp +++ b/main.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #ifndef QT_NO_WIDGETS #include #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; } diff --git a/main.qml b/main.qml index 880c9a0..816b39f 100644 --- a/main.qml +++ b/main.qml @@ -8,7 +8,6 @@ import QtQuick.Window 2.2 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.0 import QtQuick.Controls.Material 2.2 -import Qt.labs.settings 1.0 ApplicationWindow { id: window @@ -768,13 +767,6 @@ ApplicationWindow { } } - /* Persistent settings */ - Settings { - category: "General" - property alias x: window.x - property alias y: window.y - } - /* Utility functions */ function httpRequest(url, callback) { var xhr = new XMLHttpRequest();