From f3062f6c96d11706ff97e1c5cfe8de10b2abaa26 Mon Sep 17 00:00:00 2001 From: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> Date: Tue, 21 Jan 2020 09:55:26 +0100 Subject: [PATCH] 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> --- src/gui/systray.cpp | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) 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) { -- 2.30.2