2013-03-20 13:03:49 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Cédric Bellegarde <gnumdk@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
2019-12-02 16:10:18 +03:00
|
|
|
#include "accountmanager.h"
|
2013-03-20 13:03:49 +04:00
|
|
|
#include "systray.h"
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "theme.h"
|
2017-03-27 12:12:28 +03:00
|
|
|
#include "config.h"
|
2020-04-24 19:34:11 +03:00
|
|
|
#include "common/utility.h"
|
2019-12-03 20:50:34 +03:00
|
|
|
#include "tray/UserModel.h"
|
2013-03-20 13:03:49 +04:00
|
|
|
|
2020-01-21 11:55:26 +03:00
|
|
|
#include <QCursor>
|
2019-12-30 16:14:28 +03:00
|
|
|
#include <QGuiApplication>
|
2020-03-22 18:14:26 +03:00
|
|
|
#include <QQmlApplicationEngine>
|
2020-05-21 01:28:23 +03:00
|
|
|
#include <QQmlContext>
|
2020-06-23 12:20:30 +03:00
|
|
|
#include <QQuickWindow>
|
2019-12-30 16:14:28 +03:00
|
|
|
#include <QScreen>
|
2020-06-29 20:41:51 +03:00
|
|
|
#include <QMenu>
|
2019-12-02 16:10:18 +03:00
|
|
|
|
2013-03-22 14:34:21 +04:00
|
|
|
#ifdef USE_FDO_NOTIFICATIONS
|
2013-03-20 13:03:49 +04:00
|
|
|
#include <QDBusConnection>
|
2013-03-22 14:58:55 +04:00
|
|
|
#include <QDBusInterface>
|
2013-03-20 13:03:49 +04:00
|
|
|
#include <QDBusMessage>
|
|
|
|
#include <QDBusPendingCall>
|
2013-03-22 14:58:55 +04:00
|
|
|
#define NOTIFICATIONS_SERVICE "org.freedesktop.Notifications"
|
|
|
|
#define NOTIFICATIONS_PATH "/org/freedesktop/Notifications"
|
|
|
|
#define NOTIFICATIONS_IFACE "org.freedesktop.Notifications"
|
2013-03-20 13:03:49 +04:00
|
|
|
#endif
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2013-10-01 15:51:40 +04:00
|
|
|
|
2020-06-11 20:27:40 +03:00
|
|
|
Q_LOGGING_CATEGORY(lcSystray, "nextcloud.gui.systray")
|
|
|
|
|
2020-01-11 19:34:56 +03:00
|
|
|
Systray *Systray::_instance = nullptr;
|
|
|
|
|
|
|
|
Systray *Systray::instance()
|
|
|
|
{
|
2020-06-10 04:47:49 +03:00
|
|
|
if (!_instance) {
|
2020-01-11 19:34:56 +03:00
|
|
|
_instance = new Systray();
|
|
|
|
}
|
|
|
|
return _instance;
|
|
|
|
}
|
|
|
|
|
2020-06-24 14:50:17 +03:00
|
|
|
void Systray::setTrayEngine(QQmlApplicationEngine *trayEngine)
|
2019-12-02 16:10:18 +03:00
|
|
|
{
|
2020-06-24 14:50:17 +03:00
|
|
|
_trayEngine = trayEngine;
|
|
|
|
|
2020-01-19 22:13:12 +03:00
|
|
|
_trayEngine->addImportPath("qrc:/qml/theme");
|
2020-01-03 15:09:29 +03:00
|
|
|
_trayEngine->addImageProvider("avatars", new ImageProvider);
|
2020-06-24 14:50:17 +03:00
|
|
|
}
|
2020-06-15 18:01:39 +03:00
|
|
|
|
2020-06-24 14:50:17 +03:00
|
|
|
Systray::Systray()
|
|
|
|
: QSystemTrayIcon(nullptr)
|
|
|
|
{
|
2020-06-15 18:01:39 +03:00
|
|
|
qmlRegisterSingletonType<UserModel>("com.nextcloud.desktopclient", 1, 0, "UserModel",
|
|
|
|
[](QQmlEngine *, QJSEngine *) -> QObject * {
|
|
|
|
return UserModel::instance();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
qmlRegisterSingletonType<UserAppsModel>("com.nextcloud.desktopclient", 1, 0, "UserAppsModel",
|
|
|
|
[](QQmlEngine *, QJSEngine *) -> QObject * {
|
|
|
|
return UserAppsModel::instance();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
qmlRegisterSingletonType<Systray>("com.nextcloud.desktopclient", 1, 0, "Systray",
|
|
|
|
[](QQmlEngine *, QJSEngine *) -> QObject * {
|
|
|
|
return Systray::instance();
|
|
|
|
}
|
|
|
|
);
|
2020-01-03 18:15:15 +03:00
|
|
|
|
2020-06-29 20:41:51 +03:00
|
|
|
#ifndef Q_OS_MAC
|
|
|
|
auto contextMenu = new QMenu();
|
|
|
|
contextMenu->addAction(tr("Open main dialog"), this, &Systray::openMainDialog);
|
|
|
|
contextMenu->addAction(tr("Settings"), this, &Systray::openSettings);
|
|
|
|
contextMenu->addAction(tr("Exit %1").arg(Theme::instance()->appNameGUI()), this, &Systray::shutdown);
|
|
|
|
setContextMenu(contextMenu);
|
|
|
|
#endif
|
|
|
|
|
2020-01-03 18:15:15 +03:00
|
|
|
connect(UserModel::instance(), &UserModel::newUserSelected,
|
2020-01-15 18:42:06 +03:00
|
|
|
this, &Systray::slotNewUserSelected);
|
2020-01-11 19:06:42 +03:00
|
|
|
|
|
|
|
connect(AccountManager::instance(), &AccountManager::accountAdded,
|
|
|
|
this, &Systray::showWindow);
|
2019-12-02 16:10:18 +03:00
|
|
|
}
|
|
|
|
|
2020-01-11 17:05:37 +03:00
|
|
|
void Systray::create()
|
|
|
|
{
|
2020-06-24 14:50:17 +03:00
|
|
|
if (_trayEngine) {
|
|
|
|
if (!AccountManager::instance()->accounts().isEmpty()) {
|
|
|
|
_trayEngine->rootContext()->setContextProperty("activityModel", UserModel::instance()->currentActivityModel());
|
|
|
|
}
|
|
|
|
_trayEngine->load(QStringLiteral("qrc:/qml/src/gui/tray/Window.qml"));
|
2020-01-11 17:05:37 +03:00
|
|
|
}
|
2020-03-22 18:14:26 +03:00
|
|
|
hideWindow();
|
2020-04-24 19:34:11 +03:00
|
|
|
emit activated(QSystemTrayIcon::ActivationReason::Unknown);
|
2020-07-21 12:44:52 +03:00
|
|
|
|
|
|
|
const auto folderMap = FolderMan::instance()->map();
|
|
|
|
for (const auto *folder : folderMap) {
|
2020-07-21 13:44:45 +03:00
|
|
|
if (!folder->syncPaused()) {
|
2020-07-17 16:18:03 +03:00
|
|
|
_syncIsPaused = false;
|
2020-07-21 13:44:45 +03:00
|
|
|
break;
|
2020-07-17 16:18:03 +03:00
|
|
|
}
|
|
|
|
}
|
2020-01-11 17:05:37 +03:00
|
|
|
}
|
|
|
|
|
2020-01-15 18:42:06 +03:00
|
|
|
void Systray::slotNewUserSelected()
|
2019-12-02 16:10:18 +03:00
|
|
|
{
|
2020-06-24 14:50:17 +03:00
|
|
|
if (_trayEngine) {
|
|
|
|
// Change ActivityModel
|
|
|
|
_trayEngine->rootContext()->setContextProperty("activityModel", UserModel::instance()->currentActivityModel());
|
|
|
|
}
|
2020-01-15 18:42:06 +03:00
|
|
|
|
|
|
|
// Rebuild App list
|
|
|
|
UserAppsModel::instance()->buildAppList();
|
2019-12-02 16:10:18 +03:00
|
|
|
}
|
|
|
|
|
2020-01-05 18:25:32 +03:00
|
|
|
bool Systray::isOpen()
|
|
|
|
{
|
|
|
|
return _isOpen;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_INVOKABLE void Systray::setOpened()
|
|
|
|
{
|
|
|
|
_isOpen = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_INVOKABLE void Systray::setClosed()
|
|
|
|
{
|
|
|
|
_isOpen = false;
|
|
|
|
}
|
|
|
|
|
2020-03-21 02:38:57 +03:00
|
|
|
void Systray::showMessage(const QString &title, const QString &message, MessageIcon icon)
|
2013-03-20 13:03:49 +04:00
|
|
|
{
|
2013-03-22 14:34:21 +04:00
|
|
|
#ifdef USE_FDO_NOTIFICATIONS
|
2019-11-29 19:06:35 +03:00
|
|
|
if (QDBusInterface(NOTIFICATIONS_SERVICE, NOTIFICATIONS_PATH, NOTIFICATIONS_IFACE).isValid()) {
|
2020-04-14 22:37:49 +03:00
|
|
|
const QVariantMap hints = {{QStringLiteral("desktop-entry"), LINUX_APPLICATION_ID}};
|
2017-03-27 12:12:28 +03:00
|
|
|
QList<QVariant> args = QList<QVariant>() << APPLICATION_NAME << quint32(0) << APPLICATION_ICON_NAME
|
2020-03-21 02:20:51 +03:00
|
|
|
<< title << message << QStringList() << hints << qint32(-1);
|
2013-03-22 14:58:55 +04:00
|
|
|
QDBusMessage method = QDBusMessage::createMethodCall(NOTIFICATIONS_SERVICE, NOTIFICATIONS_PATH, NOTIFICATIONS_IFACE, "Notify");
|
|
|
|
method.setArguments(args);
|
|
|
|
QDBusConnection::sessionBus().asyncCall(method);
|
2013-05-22 19:39:49 +04:00
|
|
|
} else
|
2015-02-07 20:23:09 +03:00
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_OSX
|
2017-05-17 11:55:42 +03:00
|
|
|
if (canOsXSendUserNotification()) {
|
2015-02-07 20:23:09 +03:00
|
|
|
sendOsXUserNotification(title, message);
|
|
|
|
} else
|
2013-05-22 19:39:49 +04:00
|
|
|
#endif
|
|
|
|
{
|
2020-03-21 02:38:57 +03:00
|
|
|
QSystemTrayIcon::showMessage(title, message, icon);
|
2013-03-22 14:58:55 +04:00
|
|
|
}
|
2013-03-22 14:34:21 +04:00
|
|
|
}
|
2013-10-01 15:51:40 +04:00
|
|
|
|
2013-11-23 03:05:50 +04:00
|
|
|
void Systray::setToolTip(const QString &tip)
|
|
|
|
{
|
|
|
|
QSystemTrayIcon::setToolTip(tr("%1: %2").arg(Theme::instance()->appNameGUI(), tip));
|
|
|
|
}
|
|
|
|
|
2020-04-24 19:34:11 +03:00
|
|
|
bool Systray::syncIsPaused()
|
2019-12-30 16:14:28 +03:00
|
|
|
{
|
2020-04-24 19:34:11 +03:00
|
|
|
return _syncIsPaused;
|
|
|
|
}
|
2020-01-21 15:54:04 +03:00
|
|
|
|
2020-04-24 19:34:11 +03:00
|
|
|
void Systray::pauseResumeSync()
|
|
|
|
{
|
|
|
|
if (_syncIsPaused) {
|
|
|
|
_syncIsPaused = false;
|
|
|
|
emit resumeSync();
|
2020-01-21 11:55:26 +03:00
|
|
|
} else {
|
2020-04-24 19:34:11 +03:00
|
|
|
_syncIsPaused = true;
|
|
|
|
emit pauseSync();
|
2020-01-21 11:55:26 +03:00
|
|
|
}
|
2020-04-24 19:34:11 +03:00
|
|
|
}
|
2020-01-21 11:55:26 +03:00
|
|
|
|
2020-04-24 19:34:11 +03:00
|
|
|
/********************************************************************************************/
|
|
|
|
/* Helper functions for cross-platform tray icon position and taskbar orientation detection */
|
|
|
|
/********************************************************************************************/
|
2020-01-14 00:11:57 +03:00
|
|
|
|
2020-06-23 12:20:30 +03:00
|
|
|
void Systray::positionWindow(QQuickWindow *window) const
|
|
|
|
{
|
|
|
|
window->setScreen(currentScreen());
|
|
|
|
|
|
|
|
const auto position = computeWindowPosition(window->width(), window->height());
|
|
|
|
window->setPosition(position);
|
|
|
|
}
|
|
|
|
|
2020-05-20 20:36:57 +03:00
|
|
|
QScreen *Systray::currentScreen() const
|
|
|
|
{
|
|
|
|
const auto screens = QGuiApplication::screens();
|
|
|
|
const auto cursorPos = QCursor::pos();
|
|
|
|
|
|
|
|
for (const auto screen : screens) {
|
|
|
|
if (screen->geometry().contains(cursorPos)) {
|
|
|
|
return screen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Systray::TaskBarPosition Systray::taskbarOrientation() const
|
2020-04-24 19:34:11 +03:00
|
|
|
{
|
|
|
|
// macOS: Always on top
|
|
|
|
#if defined(Q_OS_MACOS)
|
|
|
|
return TaskBarPosition::Top;
|
|
|
|
// Windows: Check registry for actual taskbar orientation
|
|
|
|
#elif defined(Q_OS_WIN)
|
|
|
|
auto taskbarPosition = Utility::registryGetKeyValue(HKEY_CURRENT_USER,
|
|
|
|
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StuckRects3",
|
|
|
|
"Settings");
|
|
|
|
switch (taskbarPosition.toInt()) {
|
|
|
|
// Mapping windows binary value (0 = left, 1 = top, 2 = right, 3 = bottom) to qml logic (0 = bottom, 1 = left...)
|
|
|
|
case 0:
|
|
|
|
return TaskBarPosition::Left;
|
|
|
|
case 1:
|
|
|
|
return TaskBarPosition::Top;
|
|
|
|
case 2:
|
|
|
|
return TaskBarPosition::Right;
|
|
|
|
case 3:
|
|
|
|
return TaskBarPosition::Bottom;
|
|
|
|
default:
|
|
|
|
return TaskBarPosition::Bottom;
|
2019-12-30 16:14:28 +03:00
|
|
|
}
|
2020-05-20 11:12:55 +03:00
|
|
|
// Probably Linux
|
2020-04-24 19:34:11 +03:00
|
|
|
#else
|
2020-05-20 21:03:08 +03:00
|
|
|
const auto screenRect = currentScreenRect();
|
|
|
|
const auto trayIconCenter = calcTrayIconCenter();
|
2020-05-20 11:12:55 +03:00
|
|
|
|
2020-05-25 20:02:10 +03:00
|
|
|
const auto distBottom = screenRect.bottom() - trayIconCenter.y();
|
|
|
|
const auto distRight = screenRect.right() - trayIconCenter.x();
|
|
|
|
const auto distLeft = trayIconCenter.x() - screenRect.left();
|
|
|
|
const auto distTop = trayIconCenter.y() - screenRect.top();
|
2020-05-20 11:12:55 +03:00
|
|
|
|
2020-05-25 20:02:10 +03:00
|
|
|
const auto minDist = std::min({distRight, distTop, distBottom});
|
|
|
|
|
|
|
|
if (minDist == distBottom) {
|
2020-05-20 11:12:55 +03:00
|
|
|
return TaskBarPosition::Bottom;
|
2020-05-25 20:02:10 +03:00
|
|
|
} else if (minDist == distLeft) {
|
2020-05-20 11:12:55 +03:00
|
|
|
return TaskBarPosition::Left;
|
2020-05-25 20:02:10 +03:00
|
|
|
} else if (minDist == distTop) {
|
2020-05-20 11:12:55 +03:00
|
|
|
return TaskBarPosition::Top;
|
|
|
|
} else {
|
|
|
|
return TaskBarPosition::Right;
|
|
|
|
}
|
2020-01-04 14:15:01 +03:00
|
|
|
#endif
|
2019-12-30 16:14:28 +03:00
|
|
|
}
|
2020-01-05 23:06:42 +03:00
|
|
|
|
2020-05-20 11:12:55 +03:00
|
|
|
// TODO: Get real taskbar dimensions Linux as well
|
2020-05-20 20:36:57 +03:00
|
|
|
QRect Systray::taskbarGeometry() const
|
2020-01-05 23:06:42 +03:00
|
|
|
{
|
2020-04-24 19:34:11 +03:00
|
|
|
#if defined(Q_OS_WIN)
|
2020-05-20 11:12:55 +03:00
|
|
|
QRect tbRect = Utility::getTaskbarDimensions();
|
|
|
|
//QML side expects effective pixels, convert taskbar dimensions if necessary
|
2020-05-20 21:03:08 +03:00
|
|
|
auto pixelRatio = currentScreen()->devicePixelRatio();
|
2020-05-20 11:12:55 +03:00
|
|
|
if (pixelRatio != 1) {
|
|
|
|
tbRect.setHeight(tbRect.height() / pixelRatio);
|
|
|
|
tbRect.setWidth(tbRect.width() / pixelRatio);
|
|
|
|
}
|
|
|
|
return tbRect;
|
|
|
|
#elif defined(Q_OS_MACOS)
|
|
|
|
// Finder bar is always 22px height on macOS (when treating as effective pixels)
|
2020-05-20 21:03:08 +03:00
|
|
|
auto screenWidth = currentScreenRect().width();
|
2020-07-07 10:43:22 +03:00
|
|
|
return {0, 0, screenWidth, 22};
|
2020-04-24 19:34:11 +03:00
|
|
|
#else
|
2020-05-20 11:12:55 +03:00
|
|
|
if (taskbarOrientation() == TaskBarPosition::Bottom || taskbarOrientation() == TaskBarPosition::Top) {
|
2020-05-20 21:03:08 +03:00
|
|
|
auto screenWidth = currentScreenRect().width();
|
2020-07-07 10:43:22 +03:00
|
|
|
return {0, 0, screenWidth, 32};
|
2020-05-20 11:12:55 +03:00
|
|
|
} else {
|
2020-05-20 21:03:08 +03:00
|
|
|
auto screenHeight = currentScreenRect().height();
|
2020-07-07 10:43:22 +03:00
|
|
|
return {0, 0, 32, screenHeight};
|
2020-05-20 11:12:55 +03:00
|
|
|
}
|
2020-04-24 19:34:11 +03:00
|
|
|
#endif
|
2020-01-05 23:06:42 +03:00
|
|
|
}
|
|
|
|
|
2020-05-20 20:36:57 +03:00
|
|
|
QRect Systray::currentScreenRect() const
|
|
|
|
{
|
|
|
|
const auto screen = currentScreen();
|
2020-07-15 12:23:11 +03:00
|
|
|
Q_ASSERT(screen);
|
|
|
|
return screen->geometry();
|
2020-05-20 20:36:57 +03:00
|
|
|
}
|
|
|
|
|
2020-05-20 22:36:08 +03:00
|
|
|
QPoint Systray::computeWindowReferencePoint() const
|
2020-05-20 20:36:57 +03:00
|
|
|
{
|
2020-05-20 22:36:08 +03:00
|
|
|
constexpr auto spacing = 4;
|
2020-05-20 20:36:57 +03:00
|
|
|
const auto trayIconCenter = calcTrayIconCenter();
|
|
|
|
const auto taskbarRect = taskbarGeometry();
|
|
|
|
const auto taskbarScreenEdge = taskbarOrientation();
|
|
|
|
const auto screenRect = currentScreenRect();
|
|
|
|
|
2020-06-11 20:27:40 +03:00
|
|
|
qCDebug(lcSystray) << "screenRect:" << screenRect;
|
|
|
|
qCDebug(lcSystray) << "taskbarRect:" << taskbarRect;
|
|
|
|
qCDebug(lcSystray) << "taskbarScreenEdge:" << taskbarScreenEdge;
|
|
|
|
qCDebug(lcSystray) << "trayIconCenter:" << trayIconCenter;
|
|
|
|
|
2020-05-20 20:36:57 +03:00
|
|
|
switch(taskbarScreenEdge) {
|
|
|
|
case TaskBarPosition::Bottom:
|
|
|
|
return {
|
2020-05-20 22:36:08 +03:00
|
|
|
trayIconCenter.x(),
|
|
|
|
screenRect.bottom() - taskbarRect.height() - spacing
|
2020-05-20 20:36:57 +03:00
|
|
|
};
|
|
|
|
case TaskBarPosition::Left:
|
|
|
|
return {
|
2020-05-20 22:36:08 +03:00
|
|
|
screenRect.left() + taskbarRect.width() + spacing,
|
2020-05-20 20:36:57 +03:00
|
|
|
trayIconCenter.y()
|
|
|
|
};
|
|
|
|
case TaskBarPosition::Top:
|
|
|
|
return {
|
2020-05-20 22:36:08 +03:00
|
|
|
trayIconCenter.x(),
|
|
|
|
screenRect.top() + taskbarRect.height() + spacing
|
2020-05-20 20:36:57 +03:00
|
|
|
};
|
|
|
|
case TaskBarPosition::Right:
|
|
|
|
return {
|
2020-05-20 22:36:08 +03:00
|
|
|
screenRect.right() - taskbarRect.width() - spacing,
|
2020-05-20 20:36:57 +03:00
|
|
|
trayIconCenter.y()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint Systray::computeWindowPosition(int width, int height) const
|
|
|
|
{
|
2020-05-20 22:36:08 +03:00
|
|
|
const auto referencePoint = computeWindowReferencePoint();
|
2020-05-20 20:36:57 +03:00
|
|
|
|
|
|
|
const auto taskbarScreenEdge = taskbarOrientation();
|
|
|
|
const auto screenRect = currentScreenRect();
|
|
|
|
|
2020-05-20 22:36:08 +03:00
|
|
|
const auto topLeft = [=]() {
|
|
|
|
switch(taskbarScreenEdge) {
|
|
|
|
case TaskBarPosition::Bottom:
|
|
|
|
return referencePoint - QPoint(width / 2, height);
|
|
|
|
case TaskBarPosition::Left:
|
|
|
|
return referencePoint;
|
|
|
|
case TaskBarPosition::Top:
|
|
|
|
return referencePoint - QPoint(width / 2, 0);
|
|
|
|
case TaskBarPosition::Right:
|
|
|
|
return referencePoint - QPoint(width, 0);
|
|
|
|
}
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}();
|
|
|
|
const auto bottomRight = topLeft + QPoint(width, height);
|
|
|
|
const auto windowRect = [=]() {
|
|
|
|
const auto rect = QRect(topLeft, bottomRight);
|
|
|
|
auto offset = QPoint();
|
|
|
|
|
|
|
|
if (rect.left() < screenRect.left()) {
|
|
|
|
offset.setX(screenRect.left() - rect.left() + 4);
|
|
|
|
} else if (rect.right() > screenRect.right()) {
|
|
|
|
offset.setX(screenRect.right() - rect.right() - 4);
|
|
|
|
}
|
2020-05-20 20:36:57 +03:00
|
|
|
|
2020-05-20 22:36:08 +03:00
|
|
|
if (rect.top() < screenRect.top()) {
|
|
|
|
offset.setY(screenRect.top() - rect.top() + 4);
|
|
|
|
} else if (rect.bottom() > screenRect.bottom()) {
|
|
|
|
offset.setY(screenRect.bottom() - rect.bottom() - 4);
|
|
|
|
}
|
2020-05-20 20:36:57 +03:00
|
|
|
|
2020-05-20 22:36:08 +03:00
|
|
|
return rect.translated(offset);
|
|
|
|
}();
|
2020-06-11 20:27:40 +03:00
|
|
|
|
|
|
|
qCDebug(lcSystray) << "taskbarScreenEdge:" << taskbarScreenEdge;
|
|
|
|
qCDebug(lcSystray) << "screenRect:" << screenRect;
|
|
|
|
qCDebug(lcSystray) << "windowRect (reference)" << QRect(topLeft, bottomRight);
|
|
|
|
qCDebug(lcSystray) << "windowRect (adjusted )" << windowRect;
|
|
|
|
|
2020-05-20 22:36:08 +03:00
|
|
|
return windowRect.topLeft();
|
2020-05-20 20:36:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QPoint Systray::calcTrayIconCenter() const
|
2020-01-05 23:06:42 +03:00
|
|
|
{
|
2020-05-20 20:36:57 +03:00
|
|
|
// QSystemTrayIcon::geometry() is broken for ages on most Linux DEs (invalid geometry returned)
|
|
|
|
// thus we can use this only for Windows and macOS
|
2020-04-24 19:34:11 +03:00
|
|
|
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
|
|
|
|
auto trayIconCenter = geometry().center();
|
|
|
|
return trayIconCenter;
|
|
|
|
#else
|
2020-05-20 20:36:57 +03:00
|
|
|
// On Linux, fall back to mouse position (assuming tray icon is activated by mouse click)
|
2020-07-15 12:23:11 +03:00
|
|
|
return QCursor::pos(currentScreen());
|
2020-04-24 19:34:11 +03:00
|
|
|
#endif
|
2020-01-05 23:06:42 +03:00
|
|
|
}
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
} // namespace OCC
|