Introduce a screenRect as coordinate space
authorKevin Ottens <kevin.ottens@nextcloud.com>
Wed, 20 May 2020 15:59:40 +0000 (17:59 +0200)
committerKevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com>
Mon, 15 Jun 2020 12:32:25 +0000 (12:32 +0000)
The top left corner of that screenRect is (0,0) or based on
(virtualX,virtualY) depending on the platform. This leads to easier
reduction in code duplication.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/gui/tray/Window.qml

index 3684162d7e506c5b3cf1301a1d0637f718683c40..55e20f205a6d93a57ab896b3b1c36ad1e111469c 100644 (file)
@@ -26,6 +26,11 @@ Window {
         var trayWindowY;\r
         var tbOrientation = systrayBackend.taskbarOrientation();\r
         var taskbarRect = systrayBackend.taskbarRect();\r
+        var screenRect = Qt.rect(0, 0, Screen.width, Screen.height)\r
+        if (Qt.platform.os === "linux") {\r
+            screenRect.x = Screen.virtualX\r
+            screenRect.y = Screen.virtualY\r
+        }\r
 \r
         switch(tbOrientation) {\r
             // Platform separation here: Windows and macOS draw coordinates have to be given in screen-coordinates\r
@@ -33,24 +38,21 @@ Window {
             case Systray.Bottom:\r
                 console.debug("Taskbar is on the bottom.");\r
                 trayWindowX = trayIconCenter.x - trayWindow.width / 2;\r
-                trayWindowY = (Qt.platform.os !== "linux") ? (Screen.height - taskbarRect.height - trayWindow.height - 4)\r
-                                                           : (Screen.height + Screen.virtualY - taskbarRect.height - trayWindow.height - 4);\r
+                trayWindowY = screenRect.bottom - taskbarRect.height - trayWindow.height - 4;\r
                 break;\r
             case Systray.Left:\r
                 console.debug("Taskbar is on the left.");\r
-                trayWindowX = (Qt.platform.os !== "linux") ? (taskbarRect.width + 4)\r
-                                                           : (Screen.virtualX + taskbarRect.width + 4);\r
+                trayWindowX = screenRect.left + taskbarRect.width + 4;\r
                 trayWindowY = trayIconCenter.y;\r
                 break;\r
             case Systray.Top:\r
                 console.debug("Taskbar is on the top.");\r
                 trayWindowX = trayIconCenter.x - trayWindow.width / 2;\r
-                trayWindowY = Screen.virtualY + taskbarRect.height + 4;\r
+                trayWindowY = screenRect.top + taskbarRect.height + 4;\r
                 break;\r
             case Systray.Right:\r
                 console.debug("Taskbar is on the right.");\r
-                trayWindowX = (Qt.platform.os !== "linux") ? (Screen.width - taskbarRect.width - trayWindow.width - 4)\r
-                                                           : (Screen.width + Screen.virtualX - taskbarRect.width - trayWindow.width - 4);\r
+                trayWindowX = screenRect.right - taskbarRect.width - trayWindow.width - 4;\r
                 trayWindowY = trayIconCenter.y;\r
                 break;\r
         }\r
@@ -64,38 +66,33 @@ Window {
         console.debug("Taskbar height:", taskbarRect.height);\r
         console.debug("Taskbar width:", taskbarRect.width);\r
 \r
-        if (Screen.width <= trayWindowX + trayWindow.width) {\r
+        if (screenRect.right <= 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 === Systray.Right ? taskbarRect.width : 0);\r
+            trayWindowX = screenRect.right - trayWindow.width - 4;\r
+\r
+            if (Qt.platform.os === "linux") {\r
+                trayWindowX -= tbOrientation === Systray.Right ? taskbarRect.width : 0;\r
             }\r
         }\r
-        if (trayWindowX <= Screen.x && Qt.platform.os !== "linux") {\r
+        if (trayWindowX <= screenRect.left) {\r
             console.debug("Out-of-screen condition on the left detected. Adjusting window position.");\r
-            trayWindowX = Screen.x + 4;\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 === Systray.Left ? 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
-            trayWindowY = Screen.y + 4;\r
+            trayWindowX = screenRect.left + 4;\r
+\r
+            if (Qt.platform.os === "linux") {\r
+               trayWindowX += tbOrientation === Systray.Left ? taskbarRect.width : 0;\r
+            }\r
         }\r
-        if (trayWindowY <= Screen.virtualY && Qt.platform.os === "linux") {\r
+        if (trayWindowY <= screenRect.top) {\r
             console.debug("Out-of-screen condition on the top detected. Adjusting window position.");\r
-            trayWindowY = Screen.virtualY + 4 + (tbOrientation === Systray.Top ? taskbarRect.height : 0);\r
+            trayWindowY = screenRect.top + 4;\r
+\r
+            if (Qt.platform.os === "linux") {\r
+                trayWindowY += tbOrientation === Systray.Top ? taskbarRect.height : 0;\r
+            }\r
         }\r
-        if (Screen.height <= trayWindowY - Screen.virtualY + trayWindow.height) {\r
+        if (screenRect.bottom <= trayWindowY + trayWindow.height) {\r
             console.debug("Out-of-screen condition on the bottom detected. Adjusting window position.");\r
-            if (Qt.platform.os !== "linux") {\r
-                trayWindowY = Screen.height - trayWindow.height - 4;\r
-            } else {\r
-                trayWindowY = Screen.height + Screen.virtualY - trayWindow.height - 4;\r
-            }\r
-\r
+            trayWindowY = screenRect.bottom - trayWindow.height - 4;\r
         }\r
         console.debug("Tray window position: x =",trayWindowX," y =",trayWindowY);\r
         trayWindow.setX(trayWindowX);\r