Rewrite of screen selection logic, plus synamic screen selection Window.qml
authorDominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Tue, 21 Jan 2020 12:54:04 +0000 (13:54 +0100)
committerDominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Tue, 21 Jan 2020 12:54:04 +0000 (13:54 +0100)
Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
src/gui/systray.cpp
src/gui/systray.h
src/gui/tray/UserLine.qml
src/gui/tray/Window.qml

index 22e62aac73b585a3a275cfa968b6641ca4800d1b..f613fe3d04ef42e35507d0f1bd2d06f67c592f2c 100644 (file)
@@ -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();
 
index b491b749fc28c76709a7a6cae9ab47a2aad2736f..d562dcf426aade93ceeb10a740d024265c913808 100644 (file)
@@ -57,6 +57,7 @@ public:
     Q_INVOKABLE bool syncIsPaused();
     Q_INVOKABLE void setOpened();
     Q_INVOKABLE void setClosed();
+    Q_INVOKABLE int screenIndex();
 
 signals:
     void currentUserChanged();
index 357be60052461c128095173556dbb32302258232..0cc6e67de1599c13843baf185b56cf934be8f5bf 100644 (file)
@@ -1,5 +1,5 @@
 import QtQuick 2.9\r
-import QtQuick.Window 2.2\r
+import QtQuick.Window 2.3\r
 import QtQuick.Controls 2.2\r
 import QtQuick.Layouts 1.2\r
 \r
index 5a040c9709898c001f898cef30c5f1a38c8a8c5d..37d1c8a96939e951a210cebb1420e4b300f933e1 100644 (file)
@@ -1,7 +1,7 @@
 import QtQml 2.1\r
 import QtQml.Models 2.1\r
 import QtQuick 2.9\r
-import QtQuick.Window 2.2\r
+import QtQuick.Window 2.3\r
 import QtQuick.Controls 2.2\r
 import QtQuick.Layouts 1.2\r
 import QtGraphicalEffects 1.0\r
@@ -58,8 +58,8 @@ Window {
             trayWindow.show();\r
             trayWindow.raise();\r
             trayWindow.requestActivate();\r
-            trayWindow.setX( systrayBackend.calcTrayWindowX());\r
-            trayWindow.setY( systrayBackend.calcTrayWindowY());\r
+            trayWindow.setX( Qt.application.screens[systrayBackend.screenIndex()].virtualX + systrayBackend.calcTrayWindowX());\r
+            trayWindow.setY( Qt.application.screens[systrayBackend.screenIndex()].virtualY + systrayBackend.calcTrayWindowY());\r
             systrayBackend.setOpened();\r
             userModelBackend.fetchCurrentActivityModel();\r
         }\r