From: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> Date: Tue, 21 Jan 2020 11:16:24 +0000 (+0100) Subject: Fix also screen selection for different Qt versions and for buggy linux DEs X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~222^2^2~342^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=77be6729a2cc8c43d633ceb5106a385ac076821b;p=nextcloud-desktop.git Fix also screen selection for different Qt versions and for buggy linux DEs Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> --- diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index 3527793c6..22e62aac7 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -142,7 +142,29 @@ int Systray::calcTrayWindowX() int trayIconTopCenterX = (topRight - ((topRight - topLeft) * 0.5)).x(); return trayIconTopCenterX - (400 * 0.5); #else - QScreen *trayScreen = QGuiApplication::primaryScreen(); +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()); + } 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(); @@ -188,7 +210,29 @@ int Systray::calcTrayWindowY() // don't use availableGeometry() here, because this also excludes the dock return 22+6; #else - QScreen *trayScreen = QGuiApplication::primaryScreen(); +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()); + } 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();