return 0;
}
-int Systray::taskbarOrientation()
+Systray::TaskBarPosition Systray::taskbarOrientation()
{
// macOS: Always on top
#if defined(Q_OS_MACOS)
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
}
trayWindow.requestActivate();\r
var trayWindowX;\r
var trayWindowY;\r
- var taskbarHeight;\r
- var taskbarWidth;\r
- var tbOrientation;\r
- if (Qt.platform.os === "linux") {\r
- var distBottom = Screen.height - (trayIconCenter.y - Screen.virtualY);\r
- var distRight = Screen.width - (trayIconCenter.x - Screen.virtualX);\r
- var distLeft = trayIconCenter.x - Screen.virtualX;\r
- var distTop = trayIconCenter.y - Screen.virtualY;\r
- if (distBottom < distRight && distBottom < distTop && distBottom < distLeft) {\r
- tbOrientation = 0;\r
- } else if (distLeft < distTop && distLeft < distRight && distLeft < distBottom) {\r
- tbOrientation = 1;\r
- } else if (distTop < distRight && distTop < distBottom && distTop < distLeft) {\r
- tbOrientation = 2;\r
- } else {\r
- tbOrientation = 3;\r
- }\r
- } else {\r
- tbOrientation = systrayBackend.taskbarOrientation();\r
- }\r
- if (Qt.platform.os === "osx") {\r
- taskbarHeight = 22;\r
- taskbarWidth = Screen.width;\r
- } else if (Qt.platform.os === "linux") {\r
- taskbarHeight = (tbOrientation === 0 || tbOrientation === 2) ? 32 : Screen.height;\r
- taskbarWidth = (tbOrientation === 0 || tbOrientation === 2) ? Screen.width : 32;\r
- } else {\r
- taskbarHeight = systrayBackend.taskbarRect().height;\r
- taskbarWidth = systrayBackend.taskbarRect().width;\r
- }\r
+ var tbOrientation = systrayBackend.taskbarOrientation();\r
+ var taskbarRect = systrayBackend.taskbarRect();\r
\r
switch(tbOrientation) {\r
// Platform separation here: Windows and macOS draw coordinates have to be given in screen-coordinates\r
case 0:\r
console.debug("Taskbar is on the bottom.");\r
trayWindowX = trayIconCenter.x - trayWindow.width / 2;\r
- trayWindowY = (Qt.platform.os !== "linux") ? (Screen.height - taskbarHeight - trayWindow.height - 4)\r
- : (Screen.height + Screen.virtualY - taskbarHeight - trayWindow.height - 4);\r
+ trayWindowY = (Qt.platform.os !== "linux") ? (Screen.height - taskbarRect.height - trayWindow.height - 4)\r
+ : (Screen.height + Screen.virtualY - taskbarRect.height - trayWindow.height - 4);\r
break;\r
case 1:\r
console.debug("Taskbar is on the left.");\r
- trayWindowX = (Qt.platform.os !== "linux") ? (taskbarWidth + 4)\r
- : (Screen.virtualX + taskbarWidth + 4);\r
+ trayWindowX = (Qt.platform.os !== "linux") ? (taskbarRect.width + 4)\r
+ : (Screen.virtualX + taskbarRect.width + 4);\r
trayWindowY = trayIconCenter.y;\r
break;\r
case 2:\r
console.debug("Taskbar is on the top.");\r
trayWindowX = trayIconCenter.x - trayWindow.width / 2;\r
- trayWindowY = Screen.virtualY + taskbarHeight + 4;\r
+ trayWindowY = Screen.virtualY + taskbarRect.height + 4;\r
break;\r
case 3:\r
console.debug("Taskbar is on the right.");\r
- trayWindowX = (Qt.platform.os !== "linux") ? (Screen.width - taskbarWidth - trayWindow.width - 4)\r
- : (Screen.width + Screen.virtualX - taskbarWidth - trayWindow.width - 4);\r
+ trayWindowX = (Qt.platform.os !== "linux") ? (Screen.width - taskbarRect.width - trayWindow.width - 4)\r
+ : (Screen.width + Screen.virtualX - taskbarRect.width - trayWindow.width - 4);\r
trayWindowY = trayIconCenter.y;\r
break;\r
}\r
\r
- console.debug("Screen.height:",Screen.height);\r
- console.debug("Screen.desktopAvailableHeight:",Screen.desktopAvailableHeight);\r
- console.debug("Screen.virtualY:",Screen.virtualY);\r
- console.debug("Screen.width:",Screen.width);\r
- console.debug("Screen.desktopAvailableWidth:",Screen.desktopAvailableWidth);\r
- console.debug("Screen.virtualX:",Screen.virtualX);\r
- console.debug("Taskbar height:",taskbarHeight);\r
- console.debug("Taskbar width:",taskbarWidth);\r
+ console.debug("Screen.height:", Screen.height);\r
+ console.debug("Screen.desktopAvailableHeight:", Screen.desktopAvailableHeight);\r
+ console.debug("Screen.virtualY:", Screen.virtualY);\r
+ console.debug("Screen.width:", Screen.width);\r
+ console.debug("Screen.desktopAvailableWidth:", Screen.desktopAvailableWidth);\r
+ console.debug("Screen.virtualX:", Screen.virtualX);\r
+ console.debug("Taskbar height:", taskbarRect.height);\r
+ console.debug("Taskbar width:", taskbarRect.width);\r
\r
if (Screen.width <= trayWindowX + trayWindow.width) {\r
console.debug("Out-of-screen condition on the right detected. Adjusting window position.");\r
if (Qt.platform.os !== "linux") {\r
trayWindowX = Screen.width - trayWindow.width - 4;\r
} else {\r
- trayWindowX = Screen.width + Screen.virtualX - trayWindow.width - 4 - (tbOrientation === 3 ? taskbarWidth : 0);\r
+ trayWindowX = Screen.width + Screen.virtualX - trayWindow.width - 4 - (tbOrientation === 3 ? taskbarRect.width : 0);\r
}\r
}\r
if (trayWindowX <= Screen.x && Qt.platform.os !== "linux") {\r
}\r
if (trayWindowX <= Screen.virtualX && Qt.platform.os === "linux") {\r
console.debug("Out-of-screen condition on the left detected. Adjusting window position.");\r
- trayWindowX = Screen.virtualX + 4 + (tbOrientation === 1 ? taskbarWidth : 0)\r
+ trayWindowX = Screen.virtualX + 4 + (tbOrientation === 1 ? taskbarRect.width : 0)\r
}\r
if (trayWindowY <= Screen.y && Qt.platform.os !== "linux") {\r
console.debug("Out-of-screen condition on the top detected. Adjusting window position.");\r
}\r
if (trayWindowY <= Screen.virtualY && Qt.platform.os === "linux") {\r
console.debug("Out-of-screen condition on the top detected. Adjusting window position.");\r
- trayWindowY = Screen.virtualY + 4 + (tbOrientation === 2 ? taskbarHeight : 0);\r
+ trayWindowY = Screen.virtualY + 4 + (tbOrientation === 2 ? taskbarRect.height : 0);\r
}\r
if (Screen.height <= trayWindowY - Screen.virtualY + trayWindow.height) {\r
console.debug("Out-of-screen condition on the bottom detected. Adjusting window position.");\r