diff options
author | Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> | 2020-01-21 15:54:04 +0300 |
---|---|---|
committer | Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> | 2020-01-21 15:54:04 +0300 |
commit | 0697c81ae6a1c63dc3a8616aca2a102e78143755 (patch) | |
tree | 2122d8637dfc4b260dcb8585698f8dcbab82d377 /src/gui/systray.cpp | |
parent | 77be6729a2cc8c43d633ceb5106a385ac076821b (diff) |
Rewrite of screen selection logic, plus synamic screen selection Window.qml
Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Diffstat (limited to 'src/gui/systray.cpp')
-rw-r--r-- | src/gui/systray.cpp | 60 |
1 files changed, 19 insertions, 41 deletions
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(); |