From: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> Date: Tue, 21 Jan 2020 12:54:04 +0000 (+0100) Subject: Rewrite of screen selection logic, plus synamic screen selection Window.qml X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~222^2^2~342^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=0697c81ae6a1c63dc3a8616aca2a102e78143755;p=nextcloud-desktop.git Rewrite of screen selection logic, plus synamic screen selection Window.qml Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> --- diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index 22e62aac7..f613fe3d0 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -95,6 +95,17 @@ bool Systray::isOpen() return _isOpen; } +Q_INVOKABLE int Systray::screenIndex() +{ + auto qPos = QCursor::pos(); + for (int i = 0; i < QGuiApplication::screens().count(); i++) { + if (QGuiApplication::screens().at(i)->geometry().contains(qPos)) { + return i; + } + } + return 0; +} + Q_INVOKABLE void Systray::setOpened() { _isOpen = true; @@ -142,29 +153,13 @@ int Systray::calcTrayWindowX() int trayIconTopCenterX = (topRight - ((topRight - topLeft) * 0.5)).x(); return trayIconTopCenterX - (400 * 0.5); #else -QScreen* trayScreen = nullptr; -#if (QT_VERSION >= QT_VERSION_CHECK(5,10,0)) - if (this->geometry().left() == 0 || this->geometry().top() == 0) { - trayScreen = QGuiApplication::screenAt(QCursor::pos()); + QScreen* trayScreen = nullptr; + if (QGuiApplication::screens().count() > 1) { + trayScreen = QGuiApplication::screens().at(screenIndex()); } else { - trayScreen = QGuiApplication::screenAt(this->geometry().topLeft()); - } -#else - foreach (QScreen* screen, QGuiApplication::screens()) { - if (this->geometry().left() == 0 || this->geometry().top() == 0) { - if (screen->geometry().contains(QCursor::pos())) { - trayScreen = screen; - } - } else { - if (screen->geometry().contains(this->geometry().topLeft())) { - trayScreen = screen; - } - } - } - if (trayScreen == nullptr) { trayScreen = QGuiApplication::primaryScreen(); } -#endif + int screenWidth = trayScreen->geometry().width(); int screenHeight = trayScreen->geometry().height(); int availableWidth = trayScreen->availableGeometry().width(); @@ -210,30 +205,13 @@ int Systray::calcTrayWindowY() // don't use availableGeometry() here, because this also excludes the dock return 22+6; #else -QScreen* trayScreen = nullptr; -#if (QT_VERSION >= QT_VERSION_CHECK(5,10,0)) - if (this->geometry().left() == 0 || this->geometry().top() == 0) { - trayScreen = QGuiApplication::screenAt(QCursor::pos()); + QScreen* trayScreen = nullptr; + if (QGuiApplication::screens().count() > 1) { + trayScreen = QGuiApplication::screens().at(screenIndex()); } else { - trayScreen = QGuiApplication::screenAt(this->geometry().topLeft()); - } -#else - foreach (QScreen* screen, QGuiApplication::screens()) { - if (this->geometry().left() == 0 || this->geometry().top() == 0) { - if (screen->geometry().contains(QCursor::pos())) { - trayScreen = screen; - } - } else { - if (screen->geometry().contains(this->geometry().topLeft())) { - trayScreen = screen; - } - } - } - if (trayScreen == nullptr) { trayScreen = QGuiApplication::primaryScreen(); } -#endif - int screenWidth = trayScreen->geometry().width(); + int screenHeight = trayScreen->geometry().height(); int availableHeight = trayScreen->availableGeometry().height(); diff --git a/src/gui/systray.h b/src/gui/systray.h index b491b749f..d562dcf42 100644 --- a/src/gui/systray.h +++ b/src/gui/systray.h @@ -57,6 +57,7 @@ public: Q_INVOKABLE bool syncIsPaused(); Q_INVOKABLE void setOpened(); Q_INVOKABLE void setClosed(); + Q_INVOKABLE int screenIndex(); signals: void currentUserChanged(); diff --git a/src/gui/tray/UserLine.qml b/src/gui/tray/UserLine.qml index 357be6005..0cc6e67de 100644 --- a/src/gui/tray/UserLine.qml +++ b/src/gui/tray/UserLine.qml @@ -1,5 +1,5 @@ import QtQuick 2.9 -import QtQuick.Window 2.2 +import QtQuick.Window 2.3 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.2 diff --git a/src/gui/tray/Window.qml b/src/gui/tray/Window.qml index 5a040c970..37d1c8a96 100644 --- a/src/gui/tray/Window.qml +++ b/src/gui/tray/Window.qml @@ -1,7 +1,7 @@ import QtQml 2.1 import QtQml.Models 2.1 import QtQuick 2.9 -import QtQuick.Window 2.2 +import QtQuick.Window 2.3 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.2 import QtGraphicalEffects 1.0 @@ -58,8 +58,8 @@ Window { trayWindow.show(); trayWindow.raise(); trayWindow.requestActivate(); - trayWindow.setX( systrayBackend.calcTrayWindowX()); - trayWindow.setY( systrayBackend.calcTrayWindowY()); + trayWindow.setX( Qt.application.screens[systrayBackend.screenIndex()].virtualX + systrayBackend.calcTrayWindowX()); + trayWindow.setY( Qt.application.screens[systrayBackend.screenIndex()].virtualY + systrayBackend.calcTrayWindowY()); systrayBackend.setOpened(); userModelBackend.fetchCurrentActivityModel(); }