diff --git a/interface/resources/qml/desktop/Desktop.qml b/interface/resources/qml/desktop/Desktop.qml index 79babcb87d..7fb5cd3127 100644 --- a/interface/resources/qml/desktop/Desktop.qml +++ b/interface/resources/qml/desktop/Desktop.qml @@ -230,19 +230,23 @@ FocusScope { return; } - var windowRect = targetWindow.framedRect(); - var minPosition = Qt.vector2d(-windowRect.x, -windowRect.y); - var maxPosition = Qt.vector2d(desktop.width - windowRect.width, desktop.height - windowRect.height); var newPosition = Qt.vector2d(targetWindow.x, targetWindow.y); - if (newPosition.x === -1 && newPosition.y === -1) { - // Set initial window position - // newPosition = Utils.randomPosition(minPosition, maxPosition); - console.log("Target has no defined position, putting in center of the screen") - newPosition = Qt.vector2d(desktop.width / 2 - windowRect.width / 2, - desktop.height / 2 - windowRect.height / 2); + // If the window is completely offscreen, reposition it + if ((targetWindow.x > desktop.width || (targetWindow.x + targetWindow.width) < 0) || + (targetWindow.y > desktop.height || (targetWindow.y + targetWindow.height) < 0)) { + newPosition.x = -1 + newPosition.y = -1 } - newPosition = Utils.clampVector(newPosition, minPosition, maxPosition); + if (newPosition.x === -1 && newPosition.y === -1) { + // Set initial window position + // var minPosition = Qt.vector2d(-windowRect.x, -windowRect.y); + // var maxPosition = Qt.vector2d(desktop.width - windowRect.width, desktop.height - windowRect.height); + // newPosition = Utils.clampVector(newPosition, minPosition, maxPosition); + // newPosition = Utils.randomPosition(minPosition, maxPosition); + newPosition = Qt.vector2d(desktop.width / 2 - targetWindow.width / 2, + desktop.height / 2 - targetWindow.height / 2); + } targetWindow.x = newPosition.x; targetWindow.y = newPosition.y; }