mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-25 05:52:40 +03:00
Merge pull request #541 from Yubico/monitor-check
Make sure the application is always visible on a monitor
This commit is contained in:
commit
2dda96e4ab
17
main.cpp
17
main.cpp
@ -1,4 +1,5 @@
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <stdlib.h>
|
||||
@ -46,6 +47,21 @@ int main(int argc, char *argv[])
|
||||
application.setOrganizationName("Yubico");
|
||||
application.setOrganizationDomain("com.yubico");
|
||||
|
||||
// Get x and y coordinates of all monitors
|
||||
QVariantList monitorAreas;
|
||||
for (QScreen* screen : QGuiApplication::screens()) {
|
||||
QRect monitorArea = screen->geometry();
|
||||
|
||||
QVariantMap coordinates;
|
||||
|
||||
coordinates.insert("xMin", monitorArea.x());
|
||||
coordinates.insert("xMax", monitorArea.x() + monitorArea.width());
|
||||
coordinates.insert("yMin", monitorArea.y());
|
||||
coordinates.insert("yMax", monitorArea.y() + monitorArea.height());
|
||||
|
||||
monitorAreas << coordinates;
|
||||
}
|
||||
|
||||
QQuickStyle::setStyle("Material");
|
||||
|
||||
QCommandLineParser cliParser;
|
||||
@ -97,6 +113,7 @@ int main(int argc, char *argv[])
|
||||
engine.rootContext()->setContextProperty("appVersion", APP_VERSION);
|
||||
engine.rootContext()->setContextProperty("ScreenShot", &screenshot);
|
||||
engine.rootContext()->setContextProperty("application", &application);
|
||||
engine.rootContext()->setContextProperty("monitorAreas", monitorAreas);
|
||||
engine.load(QUrl(url_prefix + main_qml));
|
||||
|
||||
|
||||
|
24
qml/main.qml
24
qml/main.qml
@ -139,6 +139,30 @@ ApplicationWindow {
|
||||
&& (settings.desktopAvailableHeight === Screen.desktopAvailableHeight)
|
||||
app.x = (savedScreenLayout) ? settings.x : Screen.width / 2 - app.width / 2
|
||||
app.y = (savedScreenLayout) ? settings.y : Screen.height / 2 - app.height / 2
|
||||
|
||||
function isWindowPositionInsideSomeMonitor() {
|
||||
for (var i = 0; i < monitorAreas.length; i++) {
|
||||
var xMin = monitorAreas[i].xMin
|
||||
var xMax = monitorAreas[i].xMax
|
||||
var yMin = monitorAreas[i].yMin
|
||||
var yMax = monitorAreas[i].yMax
|
||||
|
||||
if (app.x > xMin && app.x < xMax) {
|
||||
if (app.y > yMin && app.y < yMax) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// If app.x and app.y are outside of the available screen geometry,
|
||||
// put the app in the middle of the screen.
|
||||
if (!isWindowPositionInsideSomeMonitor()) {
|
||||
app.x = Screen.width / 2 - app.width / 2
|
||||
app.y = Screen.height / 2 - app.height / 2
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function updateTrayVisibility() {
|
||||
|
Loading…
Reference in New Issue
Block a user