From 080505ef4637faa1a0cc11c75d46af1b9e6270bc Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Tue, 23 Jun 2020 11:20:30 +0200 Subject: [PATCH] Simplify tray window positioning 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 --- src/gui/systray.cpp | 16 +++++++++------- src/gui/systray.h | 3 ++- src/gui/tray/Window.qml | 6 +----- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index 0cb3c86a6..93c0eba09 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #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 diff --git a/src/gui/systray.h b/src/gui/systray.h index 02a0034cf..d2b908252 100644 --- a/src/gui/systray.h +++ b/src/gui/systray.h @@ -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; diff --git a/src/gui/tray/Window.qml b/src/gui/tray/Window.qml index 5bd3c5777..92183f59f 100644 --- a/src/gui/tray/Window.qml +++ b/src/gui/tray/Window.qml @@ -58,11 +58,7 @@ Window { accountMenu.close(); appsMenu.close(); - trayWindow.screen = Qt.application.screens[Systray.currentScreenIndex()]; - - var position = Systray.computeWindowPosition(trayWindow.width, trayWindow.height) - trayWindow.x = position.x - trayWindow.y = position.y + Systray.positionWindow(trayWindow); trayWindow.show(); trayWindow.raise();