connect(UserModel::instance(), &UserModel::addAccount,
this, &Systray::openAccountWizard);
+#if defined(Q_OS_MACOS) || defined(Q_OS_WIN)
connect(AccountManager::instance(), &AccountManager::accountAdded,
- this, &Systray::showWindow);
+ this, [this]{ emit showWindow(); });
+#else
+ // Since the positioning of the QSystemTrayIcon is borked on non-Windows and non-macOS desktop environments,
+ // we hardcode the position of the tray to be in the center when we add a new account from somewhere like
+ // the wizard. Otherwise with the conventional method we end up with the tray appearing wherever the cursor
+ // is placed
+
+ connect(AccountManager::instance(), &AccountManager::accountAdded,
+ this, [this]{ emit showWindow(WindowPosition::Center); });
+#endif
}
void Systray::create()
/* Helper functions for cross-platform tray icon position and taskbar orientation detection */
/********************************************************************************************/
-void Systray::positionWindow(QQuickWindow *window) const
+void Systray::positionWindowAtTray(QQuickWindow *window) const
{
if (!useNormalWindow()) {
window->setScreen(currentScreen());
}
}
+void Systray::positionWindowAtScreenCenter(QQuickWindow *window) const
+{
+ if(!useNormalWindow()) {
+ window->setScreen(currentScreen());
+ const QPoint windowAdjustment(window->geometry().width() / 2, window->geometry().height() / 2);
+ const auto position = currentScreen()->virtualGeometry().center() - windowAdjustment;
+ window->setPosition(position);
+ }
+}
+
void Systray::forceWindowInit(QQuickWindow *window) const
{
// HACK: At least on Windows, if the systray window is not shown at least once
window->setPosition(position);
} else {
// For other DEs we play it safe and place the notification in the centre of the screen
- const QPoint windowAdjustment(window->geometry().width() / 2, window->geometry().height() / 2);
- const auto position = currentScreen()->geometry().center();// - windowAdjustment;
- window->setPosition(position);
+ positionWindowAtScreenCenter(window);
}
// TODO: Get actual notification positions for the DEs
}
enum class NotificationPosition { Default, TopLeft, TopRight, BottomLeft, BottomRight };
Q_ENUM(NotificationPosition);
+ enum class WindowPosition { Default, Center };
+ Q_ENUM(WindowPosition);
+
void setTrayEngine(QQmlApplicationEngine *trayEngine);
void create();
void showMessage(const QString &title, const QString &message, MessageIcon icon = Information);
Q_INVOKABLE bool syncIsPaused();
Q_INVOKABLE void setOpened();
Q_INVOKABLE void setClosed();
- Q_INVOKABLE void positionWindow(QQuickWindow *window) const;
Q_INVOKABLE void forceWindowInit(QQuickWindow *window) const;
Q_INVOKABLE void positionNotificationWindow(QQuickWindow *window) const;
void openHelp();
void shutdown();
+ // These window signals are listened to in Window.qml
void hideWindow();
- void showWindow();
+ void showWindow(WindowPosition position = WindowPosition::Default);
+
void openShareDialog(const QString &sharePath, const QString &localPath);
void showFileActivityDialog(const QString &objectName, const int objectId);
void sendChatMessage(const QString &token, const QString &message, const QString &replyTo);
public slots:
void slotNewUserSelected();
+ void positionWindowAtTray(QQuickWindow *window) const;
+ void positionWindowAtScreenCenter(QQuickWindow *window) const;
private slots:
void slotUnpauseAllFolders();
\r
Connections {\r
target: Systray\r
- function onShowWindow() {\r
+\r
+ function onShowWindow(position) {\r
+ if(trayWindow.visible) {\r
+ return;\r
+ }\r
+\r
accountMenu.close();\r
appsMenu.close();\r
- Systray.positionWindow(trayWindow);\r
+\r
+ if(position === Systray.WindowPosition.Center) {\r
+ Systray.positionWindowAtScreenCenter(trayWindow);\r
+ } else {\r
+ Systray.positionWindowAtTray(trayWindow);\r
+ }\r
\r
trayWindow.show();\r
trayWindow.raise();\r
Systray.setOpened();\r
UserModel.fetchCurrentActivityModel();\r
}\r
+\r
function onHideWindow() {\r
trayWindow.hide();\r
Systray.setClosed();\r