mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Implemented platform agnostic tray window positioning logic
Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
This commit is contained in:
parent
6f8ffc0357
commit
44bfc79caa
@ -18,8 +18,10 @@
|
||||
#include "config.h"
|
||||
#include "tray/UserModel.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlComponent>
|
||||
#include <QQmlEngine>
|
||||
#include <QScreen>
|
||||
|
||||
#ifdef USE_FDO_NOTIFICATIONS
|
||||
#include <QDBusConnection>
|
||||
@ -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
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user