Simplify tray window positioning
authorStephan Beyer <s-beyer@gmx.net>
Tue, 23 Jun 2020 09:20:30 +0000 (11:20 +0200)
committerKevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com>
Fri, 26 Jun 2020 12:03:26 +0000 (12:03 +0000)
The Qml position setting code is moved to C++, which allowed to get rid
of the currentScreenIndex() method (which seemed to be just a detour to
pass the screen from C++ to Qml).

Signed-off-by: Stephan Beyer <s-beyer@gmx.net>
src/gui/systray.cpp
src/gui/systray.h
src/gui/tray/Window.qml

index 0cb3c86a6cf0bfcbbe1990b159c1ef9fc2a2e3ff..93c0eba09e83f9d4e704f5f1221b9bdcef37bbaf 100644 (file)
@@ -23,6 +23,7 @@
 #include <QGuiApplication>
 #include <QQmlApplicationEngine>
 #include <QQmlContext>
+#include <QQuickWindow>
 #include <QScreen>
 
 #ifdef USE_FDO_NOTIFICATIONS
@@ -170,6 +171,14 @@ void Systray::pauseResumeSync()
 /* Helper functions for cross-platform tray icon position and taskbar orientation detection */
 /********************************************************************************************/
 
+void Systray::positionWindow(QQuickWindow *window) const
+{
+    window->setScreen(currentScreen());
+
+    const auto position = computeWindowPosition(window->width(), window->height());
+    window->setPosition(position);
+}
+
 QScreen *Systray::currentScreen() const
 {
     const auto screens = QGuiApplication::screens();
@@ -184,13 +193,6 @@ QScreen *Systray::currentScreen() const
     return nullptr;
 }
 
-int Systray::currentScreenIndex() const
-{
-    const auto screens = QGuiApplication::screens();
-    const auto screenIndex = screens.indexOf(currentScreen());
-    return screenIndex > 0 ? screenIndex : 0;
-}
-
 Systray::TaskBarPosition Systray::taskbarOrientation() const
 {
 // macOS: Always on top
index 02a0034cf71bc8f5d7191f943d9ad8367d3db432..d2b908252d5f1a669edd36dbd8962326b60ca0f4 100644 (file)
@@ -22,6 +22,7 @@
 
 class QScreen;
 class QQmlApplicationEngine;
+class QQuickWindow;
 
 namespace OCC {
 
@@ -59,7 +60,7 @@ public:
     Q_INVOKABLE bool syncIsPaused();
     Q_INVOKABLE void setOpened();
     Q_INVOKABLE void setClosed();
-    Q_INVOKABLE int currentScreenIndex() const;
+    Q_INVOKABLE void positionWindow(QQuickWindow *window) const;
     Q_INVOKABLE QPoint calcTrayIconCenter() const;
     Q_INVOKABLE TaskBarPosition taskbarOrientation() const;
     Q_INVOKABLE QRect taskbarGeometry() const;
index 5bd3c577796e3c8824e762527116e4b6e9cfe7b9..92183f59fe7649ee4001eae26538febbb7543ad1 100644 (file)
@@ -58,11 +58,7 @@ Window {
             accountMenu.close();\r
             appsMenu.close();\r
 \r
-            trayWindow.screen = Qt.application.screens[Systray.currentScreenIndex()];\r
-\r
-            var position = Systray.computeWindowPosition(trayWindow.width, trayWindow.height)\r
-            trayWindow.x = position.x\r
-            trayWindow.y = position.y\r
+            Systray.positionWindow(trayWindow);\r
 \r
             trayWindow.show();\r
             trayWindow.raise();\r