Skip to content

Commit

Permalink
Do not use saved position if it falls outside of primary screen
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
maxnet committed Jul 21, 2020
1 parent 65c6377 commit bcd2855
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Priority: optional
Maintainer: Floris Bos <bos@je-eigen-domein.nl>
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
Expand Down
43 changes: 43 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <QTranslator>
#include <QLocale>
#include <QScreen>
#include <QSettings>
#ifndef QT_NO_WIDGETS
#include <QtWidgets/QApplication>
#endif
Expand Down Expand Up @@ -164,7 +165,49 @@ 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)
{
qDebug() << "w" << w << "h" << h;
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;
}

8 changes: 0 additions & 8 deletions main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit bcd2855

Please sign in to comment.