diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index 97f5137062..520450dd98 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -18,8 +18,10 @@ #include "config.h" #include "tray/UserModel.h" +#include #include #include +#include #ifdef USE_FDO_NOTIFICATIONS #include @@ -97,4 +99,60 @@ void Systray::setToolTip(const QString &tip) QSystemTrayIcon::setToolTip(tr("%1: %2").arg(Theme::instance()->appNameGUI(), tip)); } +int Systray::calcTrayWindowX() +{ + QScreen* trayScreen = QGuiApplication::screenAt(this->geometry().topRight()); + // get coordinates from top center point of tray icon + int trayIconTopCenterX = (this->geometry().topRight() - ((this->geometry().topRight() - this->geometry().topLeft()) * 0.5)).x(); + int trayIconTopCenterY = (this->geometry().topRight() - ((this->geometry().topRight() - this->geometry().topLeft()) * 0.5)).y(); + + if ( (trayScreen->geometry().width() - trayIconTopCenterX) < (trayScreen->geometry().width() * 0.5) ) { + // tray icon is on right side of the screen + if ( ((trayScreen->geometry().width() - trayIconTopCenterX) < trayScreen->geometry().height() - trayIconTopCenterY) + && ((trayScreen->geometry().width() - trayIconTopCenterX) < trayIconTopCenterY) ) { + // taskbar is on the right + return trayScreen->availableSize().width() - 400 - 6; + } else { + // taskbar is on the bottom or top + if (trayIconTopCenterX - (400 * 0.5) < 0) { + return 6; + } else if (trayIconTopCenterX - (400 * 0.5) > trayScreen->geometry().width()) { + return trayScreen->geometry().width() - 406; + } else { + return trayIconTopCenterX - (400 * 0.5); + } + } + } else { + // tray icon is on left side of the screen + return (trayScreen->geometry().width() - trayScreen->availableGeometry().width()) + 6; + } +} +int Systray::calcTrayWindowY() +{ + QScreen *trayScreen = QGuiApplication::screenAt(this->geometry().topRight()); + // get coordinates from top center point of tray icon + int trayIconTopCenterX = (this->geometry().topRight() - ((this->geometry().topRight() - this->geometry().topLeft()) * 0.5)).x(); + int trayIconTopCenterY = (this->geometry().topRight() - ((this->geometry().topRight() - this->geometry().topLeft()) * 0.5)).y(); + + if ( (trayScreen->geometry().height() - trayIconTopCenterY) < (trayScreen->geometry().height() * 0.5) ) { + // tray icon is on bottom side of the screen + if ( ((trayScreen->geometry().height() - trayIconTopCenterY) < trayScreen->geometry().width() - trayIconTopCenterX ) + && ((trayScreen->geometry().height() - trayIconTopCenterY) < trayIconTopCenterX) ) { + // taskbar is on the bottom + return trayScreen->availableSize().height() - 500 - 6; + } else { + // taskbar is on the right or left + if (trayIconTopCenterY - 500 > 0) { + return trayIconTopCenterY - 500; + } else { + return 6; + } + } + } else { + // tray icon is on the top + return (trayScreen->geometry().height() - trayScreen->availableGeometry().height()) + 6; + } +} + + } // namespace OCC diff --git a/src/gui/systray.h b/src/gui/systray.h index dde45be1a9..f99f024e67 100644 --- a/src/gui/systray.h +++ b/src/gui/systray.h @@ -48,6 +48,9 @@ public: void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int millisecondsTimeoutHint = 10000); void setToolTip(const QString &tip); + Q_INVOKABLE int calcTrayWindowX(); + Q_INVOKABLE int calcTrayWindowY(); + signals: void currentUserChanged(); diff --git a/src/gui/tray/window.qml b/src/gui/tray/window.qml index 12eb10e7fa..b01df1cf58 100644 --- a/src/gui/tray/window.qml +++ b/src/gui/tray/window.qml @@ -20,14 +20,6 @@ Window { } } - Component.onCompleted: { - /* desktopAvailableWidth and Height doesn't include the system tray bar - but breaks application anyway on windows when using multi monitor setup, - will look for a better solution later, for now just get this thing complete */ - //setX(Screen.desktopAvailableWidth - width); - //setY(Screen.desktopAvailableHeight + height); - } - Connections { target: userModelBackend onRefreshCurrentUserGui: { @@ -45,6 +37,8 @@ Window { onShowWindow: { trayWindow.show(); trayWindow.requestActivate(); + trayWindow.setX( systrayBackend.calcTrayWindowX()); + trayWindow.setY( systrayBackend.calcTrayWindowY()); } onHideWindow: { trayWindow.hide();