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 <s-beyer@gmx.net>
This commit is contained in:
Stephan Beyer 2020-06-23 11:20:30 +02:00 committed by Kevin Ottens (Rebase PR Action)
parent afa5267932
commit 080505ef46
3 changed files with 12 additions and 13 deletions

View 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

View 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;

View file

@ -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();