From: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> Date: Wed, 20 May 2020 08:12:55 +0000 (+0200) Subject: More simplifications, also transfer of more tray positioning logic to C++ backend. X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~222^2^2~160^2~10 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=a6f918f3c215dca6b14f9dab8a5c2d057c399f56;p=nextcloud-desktop.git More simplifications, also transfer of more tray positioning logic to C++ backend. Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> --- diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index 98d55c1f9..88d6812a4 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -157,7 +157,7 @@ int Systray::screenIndex() return 0; } -int Systray::taskbarOrientation() +Systray::TaskBarPosition Systray::taskbarOrientation() { // macOS: Always on top #if defined(Q_OS_MACOS) @@ -180,18 +180,56 @@ int Systray::taskbarOrientation() default: return TaskBarPosition::Bottom; } -// Else (generally linux DEs): fallback to cursor position nearest edge logic +// Probably Linux #else - return 0; + auto currentScreen = screenIndex(); + auto screenWidth = QGuiApplication::screens().at(currentScreen)->geometry().width(); + auto screenHeight = QGuiApplication::screens().at(currentScreen)->geometry().height(); + auto virtualY = QGuiApplication::screens().at(currentScreen)->virtualGeometry().y(); + auto virtualX = QGuiApplication::screens().at(currentScreen)->virtualGeometry().x(); + QPoint trayIconCenter = calcTrayIconCenter(); + + auto distBottom = screenHeight - (trayIconCenter.y() - virtualY); + auto distRight = screenWidth - (trayIconCenter.x() - virtualX); + auto distLeft = trayIconCenter.x() - virtualX; + auto distTop = trayIconCenter.y() - virtualY; + + if (distBottom < distRight && distBottom < distTop && distBottom < distLeft) { + return TaskBarPosition::Bottom; + } else if (distLeft < distTop && distLeft < distRight && distLeft < distBottom) { + return TaskBarPosition::Left; + } else if (distTop < distRight && distTop < distBottom && distTop < distLeft) { + return TaskBarPosition::Top; + } else { + return TaskBarPosition::Right; + } #endif } +// TODO: Get real taskbar dimensions Linux as well QRect Systray::taskbarRect() { #if defined(Q_OS_WIN) - return Utility::getTaskbarDimensions(); + QRect tbRect = Utility::getTaskbarDimensions(); + //QML side expects effective pixels, convert taskbar dimensions if necessary + auto pixelRatio = QGuiApplication::screens().at(screenIndex())->devicePixelRatio(); + 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) + auto screenWidth = QGuiApplication::screens().at(screenIndex())->geometry().width(); + return QRect(0, 0, screenWidth, 22); #else - return QRect(0, 0, 0, 32); + if (taskbarOrientation() == TaskBarPosition::Bottom || taskbarOrientation() == TaskBarPosition::Top) { + auto screenWidth = QGuiApplication::screens().at(screenIndex())->geometry().width(); + return QRect(0, 0, screenWidth, 32); + } else { + auto screenHeight = QGuiApplication::screens().at(screenIndex())->geometry().height(); + return QRect(0, 0, 32, screenHeight); + } #endif } diff --git a/src/gui/systray.h b/src/gui/systray.h index ad92c7a54..5dd26ad04 100644 --- a/src/gui/systray.h +++ b/src/gui/systray.h @@ -33,13 +33,6 @@ namespace Ui { class Systray; } -enum TaskBarPosition { - Bottom = 0, - Left, - Top, - Right -}; - /** * @brief The Systray class * @ingroup gui @@ -52,6 +45,9 @@ public: static Systray *instance(); virtual ~Systray() {}; + enum class TaskBarPosition { Bottom, Left, Top, Right }; + Q_ENUM(TaskBarPosition); + void create(); void showMessage(const QString &title, const QString &message, MessageIcon icon = Information); void setToolTip(const QString &tip); @@ -63,7 +59,7 @@ public: Q_INVOKABLE void setClosed(); Q_INVOKABLE int screenIndex(); Q_INVOKABLE QPoint calcTrayIconCenter(); - Q_INVOKABLE int taskbarOrientation(); + Q_INVOKABLE TaskBarPosition taskbarOrientation(); Q_INVOKABLE QRect taskbarRect(); signals: diff --git a/src/gui/tray/Window.qml b/src/gui/tray/Window.qml index 1ae7973db..77c097ba6 100644 --- a/src/gui/tray/Window.qml +++ b/src/gui/tray/Window.qml @@ -23,36 +23,8 @@ Window { trayWindow.requestActivate(); var trayWindowX; var trayWindowY; - var taskbarHeight; - var taskbarWidth; - var tbOrientation; - if (Qt.platform.os === "linux") { - var distBottom = Screen.height - (trayIconCenter.y - Screen.virtualY); - var distRight = Screen.width - (trayIconCenter.x - Screen.virtualX); - var distLeft = trayIconCenter.x - Screen.virtualX; - var distTop = trayIconCenter.y - Screen.virtualY; - if (distBottom < distRight && distBottom < distTop && distBottom < distLeft) { - tbOrientation = 0; - } else if (distLeft < distTop && distLeft < distRight && distLeft < distBottom) { - tbOrientation = 1; - } else if (distTop < distRight && distTop < distBottom && distTop < distLeft) { - tbOrientation = 2; - } else { - tbOrientation = 3; - } - } else { - tbOrientation = systrayBackend.taskbarOrientation(); - } - if (Qt.platform.os === "osx") { - taskbarHeight = 22; - taskbarWidth = Screen.width; - } else if (Qt.platform.os === "linux") { - taskbarHeight = (tbOrientation === 0 || tbOrientation === 2) ? 32 : Screen.height; - taskbarWidth = (tbOrientation === 0 || tbOrientation === 2) ? Screen.width : 32; - } else { - taskbarHeight = systrayBackend.taskbarRect().height; - taskbarWidth = systrayBackend.taskbarRect().width; - } + var tbOrientation = systrayBackend.taskbarOrientation(); + var taskbarRect = systrayBackend.taskbarRect(); switch(tbOrientation) { // Platform separation here: Windows and macOS draw coordinates have to be given in screen-coordinates @@ -60,43 +32,43 @@ Window { case 0: console.debug("Taskbar is on the bottom."); trayWindowX = trayIconCenter.x - trayWindow.width / 2; - trayWindowY = (Qt.platform.os !== "linux") ? (Screen.height - taskbarHeight - trayWindow.height - 4) - : (Screen.height + Screen.virtualY - taskbarHeight - trayWindow.height - 4); + trayWindowY = (Qt.platform.os !== "linux") ? (Screen.height - taskbarRect.height - trayWindow.height - 4) + : (Screen.height + Screen.virtualY - taskbarRect.height - trayWindow.height - 4); break; case 1: console.debug("Taskbar is on the left."); - trayWindowX = (Qt.platform.os !== "linux") ? (taskbarWidth + 4) - : (Screen.virtualX + taskbarWidth + 4); + trayWindowX = (Qt.platform.os !== "linux") ? (taskbarRect.width + 4) + : (Screen.virtualX + taskbarRect.width + 4); trayWindowY = trayIconCenter.y; break; case 2: console.debug("Taskbar is on the top."); trayWindowX = trayIconCenter.x - trayWindow.width / 2; - trayWindowY = Screen.virtualY + taskbarHeight + 4; + trayWindowY = Screen.virtualY + taskbarRect.height + 4; break; case 3: console.debug("Taskbar is on the right."); - trayWindowX = (Qt.platform.os !== "linux") ? (Screen.width - taskbarWidth - trayWindow.width - 4) - : (Screen.width + Screen.virtualX - taskbarWidth - trayWindow.width - 4); + trayWindowX = (Qt.platform.os !== "linux") ? (Screen.width - taskbarRect.width - trayWindow.width - 4) + : (Screen.width + Screen.virtualX - taskbarRect.width - trayWindow.width - 4); trayWindowY = trayIconCenter.y; break; } - console.debug("Screen.height:",Screen.height); - console.debug("Screen.desktopAvailableHeight:",Screen.desktopAvailableHeight); - console.debug("Screen.virtualY:",Screen.virtualY); - console.debug("Screen.width:",Screen.width); - console.debug("Screen.desktopAvailableWidth:",Screen.desktopAvailableWidth); - console.debug("Screen.virtualX:",Screen.virtualX); - console.debug("Taskbar height:",taskbarHeight); - console.debug("Taskbar width:",taskbarWidth); + console.debug("Screen.height:", Screen.height); + console.debug("Screen.desktopAvailableHeight:", Screen.desktopAvailableHeight); + console.debug("Screen.virtualY:", Screen.virtualY); + console.debug("Screen.width:", Screen.width); + console.debug("Screen.desktopAvailableWidth:", Screen.desktopAvailableWidth); + console.debug("Screen.virtualX:", Screen.virtualX); + console.debug("Taskbar height:", taskbarRect.height); + console.debug("Taskbar width:", taskbarRect.width); if (Screen.width <= trayWindowX + trayWindow.width) { console.debug("Out-of-screen condition on the right detected. Adjusting window position."); if (Qt.platform.os !== "linux") { trayWindowX = Screen.width - trayWindow.width - 4; } else { - trayWindowX = Screen.width + Screen.virtualX - trayWindow.width - 4 - (tbOrientation === 3 ? taskbarWidth : 0); + trayWindowX = Screen.width + Screen.virtualX - trayWindow.width - 4 - (tbOrientation === 3 ? taskbarRect.width : 0); } } if (trayWindowX <= Screen.x && Qt.platform.os !== "linux") { @@ -105,7 +77,7 @@ Window { } if (trayWindowX <= Screen.virtualX && Qt.platform.os === "linux") { console.debug("Out-of-screen condition on the left detected. Adjusting window position."); - trayWindowX = Screen.virtualX + 4 + (tbOrientation === 1 ? taskbarWidth : 0) + trayWindowX = Screen.virtualX + 4 + (tbOrientation === 1 ? taskbarRect.width : 0) } if (trayWindowY <= Screen.y && Qt.platform.os !== "linux") { console.debug("Out-of-screen condition on the top detected. Adjusting window position."); @@ -113,7 +85,7 @@ Window { } if (trayWindowY <= Screen.virtualY && Qt.platform.os === "linux") { console.debug("Out-of-screen condition on the top detected. Adjusting window position."); - trayWindowY = Screen.virtualY + 4 + (tbOrientation === 2 ? taskbarHeight : 0); + trayWindowY = Screen.virtualY + 4 + (tbOrientation === 2 ? taskbarRect.height : 0); } if (Screen.height <= trayWindowY - Screen.virtualY + trayWindow.height) { console.debug("Out-of-screen condition on the bottom detected. Adjusting window position.");