on xenial help sign in
also move the window into bounds on restore
commit479b8b13649e846bc5412e327fd1704c0b18135d authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 2 Nov 2015, 19:12 (11 years ago) parenta21de65
3 files changed+51−4
qml/Stages/DesktopStage.qml+2 qml/Stages/WindowResizeArea.qml+6−4 tests/qmltests/Stages/tst_WindowResizeArea.qml+43
qml/Stages/DesktopStage.qml+2
@@ -366,6 +366,8 @@ Rectangle {
366366 minHeight: units.gu(10)
367367 borderThickness: units.gu(2)
368368 windowId: model.appId // FIXME: Change this to point to windowId once we have such a thing
369+ screenWidth: root.width
370+ screenHeight: root.height
369371
370372 onPressed: { ApplicationManager.focusApplication(model.appId) }
371373 }
qml/Stages/WindowResizeArea.qml+6−4
@@ -36,6 +36,8 @@ MouseArea {
3636 property int borderThickness: 0
3737 property int minWidth: 0
3838 property int minHeight: 0
39+ property int screenWidth: 0
40+ property int screenHeight: 0
3941
4042 QtObject {
4143 id: priv
@@ -66,10 +68,10 @@ MouseArea {
6668 Component.onCompleted: {
6769 var windowGeometry = windowStateStorage.getGeometry(root.windowId, Qt.rect(target.x, target.y, target.width, target.height))
6870 if (windowGeometry !== undefined) {
69− target.x = windowGeometry.x
70− target.y = Math.max(windowGeometry.y, PanelState.panelHeight)
71− target.width = windowGeometry.width
72− target.height = windowGeometry.height
71+ target.width = Math.min(windowGeometry.width, root.screenWidth)
72+ target.height = Math.min(windowGeometry.height, root.screenHeight - PanelState.panelHeight)
73+ target.x = Math.max(Math.min(windowGeometry.x, root.screenWidth - target.width), 0)
74+ target.y = Math.max(Math.min(windowGeometry.y, root.screenHeight - target.height), PanelState.panelHeight)
7375 }
7476 var windowState = windowStateStorage.getState(root.windowId, WindowStateStorage.WindowStateNormal)
7577 if (windowState === WindowStateStorage.WindowStateMaximized) {
tests/qmltests/Stages/tst_WindowResizeArea.qml+43
@@ -19,6 +19,7 @@ import QtQuick.Layouts 1.1
1919import QtTest 1.0
2020import Unity.Test 0.1
2121import ".."
22+import "../../../qml/Components/PanelState"
2223import "../../../qml/Stages"
2324import Ubuntu.Components 0.1
2425import Ubuntu.Components.ListItems 1.0 as ListItem
@@ -31,6 +32,12 @@ Item {
3132
3233 property var fakeWindow: windowLoader.item
3334
35+ Binding {
36+ target: PanelState
37+ property: "panelHeight"
38+ value: units.gu(2)
39+ }
40+
3441 Component {
3542 id: fakeWindowComponent
3643
@@ -57,6 +64,8 @@ Item {
5764 minWidth: units.gu(15)
5865 minHeight: units.gu(10)
5966 windowId: "test-window-id"
67+ screenWidth: root.width
68+ screenHeight: root.height
6069 }
6170
6271 Rectangle {
@@ -228,5 +237,39 @@ Item {
228237 // clean up
229238 fakeWindow.state = "normal"
230239 }
240+
241+
242+ function test_restoreMovesIntoBounds_data() {
243+ return [
244+ {tag: "left off", x: -units.gu(5), y: units.gu(5), w: units.gu(10), h: units.gu(10)},
245+ {tag: "top off", x: units.gu(5), y: -units.gu(5), w: units.gu(10), h: units.gu(10)},
246+ {tag: "right off", x: root.width - units.gu(5), y: units.gu(5), w: units.gu(10), h: units.gu(10)},
247+ {tag: "bottom off", x: units.gu(5), y: root.height - units.gu(5), w: units.gu(10), h: units.gu(10)},
248+ {tag: "width too large", x: units.gu(5), y: units.gu(5), w: root.width * 2, h: units.gu(10)},
249+ {tag: "height too large", x: units.gu(5), y: units.gu(5), w: units.gu(10), h: root.height * 2}
250+ ]
251+ }
252+
253+ function test_restoreMovesIntoBounds(data) {
254+ fakeWindow.x = data.x;
255+ fakeWindow.y = data.y;
256+ fakeWindow.width = data.w;
257+ fakeWindow.height = data.h;
258+ waitForRendering(root);
259+
260+ // This will destroy the window and recreate it
261+ windowLoader.active = false;
262+ waitForRendering(root);
263+ windowLoader.active = true;
264+ waitForRendering(root)
265+
266+ // Make sure it's again where we left it in normal state before destroying
267+ compare(fakeWindow.x >= 0, true)
268+ compare(fakeWindow.y >= PanelState.panelHeight, true)
269+ compare(fakeWindow.x + fakeWindow.width <= root.width, true)
270+ compare(fakeWindow.y + fakeWindow.height <= root.height, true)
271+
272+ waitForRendering(root)
273+ }
231274 }
232275}