From: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> Date: Tue, 21 Jan 2020 08:55:26 +0000 (+0100) Subject: Fix wrong window position on some linux DEs - worked around invalid geometry() return... X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~222^2^2~342^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=f3062f6c96d11706ff97e1c5cfe8de10b2abaa26;p=nextcloud-desktop.git Fix wrong window position on some linux DEs - worked around invalid geometry() returned by QT Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> --- diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index 6134adcee..3527793c6 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -18,6 +18,7 @@ #include "config.h" #include "tray/UserModel.h" +#include #include #include #include @@ -146,12 +147,21 @@ int Systray::calcTrayWindowX() int screenHeight = trayScreen->geometry().height(); int availableWidth = trayScreen->availableGeometry().width(); int availableHeight = trayScreen->availableGeometry().height(); - QPoint topRightDpiAware = this->geometry().topRight() / trayScreen->devicePixelRatio(); - QPoint topLeftDpiAware = this->geometry().topLeft() / trayScreen->devicePixelRatio(); - // get coordinates from top center point of tray icon + QPoint topRightDpiAware = QPoint(); + QPoint topLeftDpiAware = QPoint(); + if (this->geometry().left() == 0 || this->geometry().top() == 0) { + // tray geometry is invalid - QT bug on some linux desktop environments + // Use mouse position instead. Cringy, but should work for now + topRightDpiAware = QCursor::pos() / trayScreen->devicePixelRatio(); + topLeftDpiAware = QCursor::pos() / trayScreen->devicePixelRatio(); + } else { + topRightDpiAware = this->geometry().topRight() / trayScreen->devicePixelRatio(); + topLeftDpiAware = this->geometry().topLeft() / trayScreen->devicePixelRatio(); + } + + // get x coordinate from top center point of tray icon int trayIconTopCenterX = (topRightDpiAware - ((topRightDpiAware - topLeftDpiAware) * 0.5)).x(); - int trayIconTopCenterY = (topRightDpiAware - ((topRightDpiAware - topLeftDpiAware) * 0.5)).y(); if (availableHeight < screenHeight) { // taskbar is on top or bottom @@ -182,11 +192,19 @@ int Systray::calcTrayWindowY() int screenWidth = trayScreen->geometry().width(); int screenHeight = trayScreen->geometry().height(); int availableHeight = trayScreen->availableGeometry().height(); - QPoint topRightDpiAware = this->geometry().topRight() / trayScreen->devicePixelRatio(); - QPoint topLeftDpiAware = this->geometry().topLeft() / trayScreen->devicePixelRatio(); - // get coordinates from top center point of tray icon - int trayIconTopCenterX = (topRightDpiAware - ((topRightDpiAware - topLeftDpiAware) * 0.5)).x(); + QPoint topRightDpiAware = QPoint(); + QPoint topLeftDpiAware = QPoint(); + if (this->geometry().left() == 0 || this->geometry().top() == 0) { + // tray geometry is invalid - QT bug on some linux desktop environments + // Use mouse position instead. Cringy, but should work for now + topRightDpiAware = QCursor::pos() / trayScreen->devicePixelRatio(); + topLeftDpiAware = QCursor::pos() / trayScreen->devicePixelRatio(); + } else { + topRightDpiAware = this->geometry().topRight() / trayScreen->devicePixelRatio(); + topLeftDpiAware = this->geometry().topLeft() / trayScreen->devicePixelRatio(); + } + // get y coordinate from top center point of tray icon int trayIconTopCenterY = (topRightDpiAware - ((topRightDpiAware - topLeftDpiAware) * 0.5)).y(); if (availableHeight < screenHeight) {