Try make taskbar position heuristic more readable
authorKevin Ottens <kevin.ottens@nextcloud.com>
Mon, 25 May 2020 17:02:10 +0000 (19:02 +0200)
committerKevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com>
Mon, 15 Jun 2020 12:32:25 +0000 (12:32 +0000)
Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/gui/systray.cpp

index 5bc9e1479eff083045829dcb64737611c78e1644..97f19765c31abe9e0f2117d6743826eb9c374d31 100644 (file)
@@ -191,16 +191,18 @@ Systray::TaskBarPosition Systray::taskbarOrientation() const
     const auto screenRect = currentScreenRect();
     const auto trayIconCenter = calcTrayIconCenter();
 
-    auto distBottom = screenRect.bottom() - trayIconCenter.y();
-    auto distRight = screenRect.right() - trayIconCenter.x();
-    auto distLeft = trayIconCenter.x() - screenRect.left();
-    auto distTop = trayIconCenter.y() - screenRect.top();
+    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();
 
-    if (distBottom < distRight && distBottom < distTop && distBottom < distLeft) {
+    const auto minDist = std::min({distRight, distTop, distBottom});
+
+    if (minDist == distBottom) {
         return TaskBarPosition::Bottom;
-    } else if (distLeft < distTop && distLeft < distRight && distLeft < distBottom) {
+    } else if (minDist == distLeft) {
         return TaskBarPosition::Left;
-    } else if (distTop < distRight && distTop < distBottom && distTop < distLeft) {
+    } else if (minDist == distTop) {
         return TaskBarPosition::Top;
     } else {
         return TaskBarPosition::Right;