on xenial help sign in
also move the window into bounds on restore
479b8b1Michael Zanetti
qml/Stages/DesktopStage.qml+2
@@ -366,6 +366,8 @@ Rectangle {
366 minHeight: units.gu(10)
366 minHeight: units.gu(10)
367 borderThickness: units.gu(2)
367 borderThickness: units.gu(2)
368 windowId: model.appId // FIXME: Change this to point to windowId once we have such a thing
368 windowId: model.appId // FIXME: Change this to point to windowId once we have such a thing
369+ screenWidth: root.width
370+ screenHeight: root.height
369
371
370 onPressed: { ApplicationManager.focusApplication(model.appId) }
372 onPressed: { ApplicationManager.focusApplication(model.appId) }
371 }
373 }
qml/Stages/WindowResizeArea.qml+6−4
@@ -36,6 +36,8 @@ MouseArea {
36 property int borderThickness: 0
36 property int borderThickness: 0
37 property int minWidth: 0
37 property int minWidth: 0
38 property int minHeight: 0
38 property int minHeight: 0
39+ property int screenWidth: 0
40+ property int screenHeight: 0
39
41
40 QtObject {
42 QtObject {
41 id: priv
43 id: priv
@@ -66,10 +68,10 @@ MouseArea {
66 Component.onCompleted: {
68 Component.onCompleted: {
67 var windowGeometry = windowStateStorage.getGeometry(root.windowId, Qt.rect(target.x, target.y, target.width, target.height))
69 var windowGeometry = windowStateStorage.getGeometry(root.windowId, Qt.rect(target.x, target.y, target.width, target.height))
68 if (windowGeometry !== undefined) {
70 if (windowGeometry !== undefined) {
69− target.x = windowGeometry.x
71+ target.width = Math.min(windowGeometry.width, root.screenWidth)
70− target.y = Math.max(windowGeometry.y, PanelState.panelHeight)
72+ target.height = Math.min(windowGeometry.height, root.screenHeight - PanelState.panelHeight)
71− target.width = windowGeometry.width
73+ target.x = Math.max(Math.min(windowGeometry.x, root.screenWidth - target.width), 0)
72− target.height = windowGeometry.height
74+ target.y = Math.max(Math.min(windowGeometry.y, root.screenHeight - target.height), PanelState.panelHeight)
73 }
75 }
74 var windowState = windowStateStorage.getState(root.windowId, WindowStateStorage.WindowStateNormal)
76 var windowState = windowStateStorage.getState(root.windowId, WindowStateStorage.WindowStateNormal)
75 if (windowState === WindowStateStorage.WindowStateMaximized) {
77 if (windowState === WindowStateStorage.WindowStateMaximized) {
tests/qmltests/Stages/tst_WindowResizeArea.qml+43
@@ -19,6 +19,7 @@ import QtQuick.Layouts 1.1
19import QtTest 1.0
19import QtTest 1.0
20import Unity.Test 0.1
20import Unity.Test 0.1
21import ".."
21import ".."
22+import "../../../qml/Components/PanelState"
22import "../../../qml/Stages"
23import "../../../qml/Stages"
23import Ubuntu.Components 0.1
24import Ubuntu.Components 0.1
24import Ubuntu.Components.ListItems 1.0 as ListItem
25import Ubuntu.Components.ListItems 1.0 as ListItem
@@ -31,6 +32,12 @@ Item {
31
32
32 property var fakeWindow: windowLoader.item
33 property var fakeWindow: windowLoader.item
33
34
35+ Binding {
36+ target: PanelState
37+ property: "panelHeight"
38+ value: units.gu(2)
39+ }
40+
34 Component {
41 Component {
35 id: fakeWindowComponent
42 id: fakeWindowComponent
36
43
@@ -57,6 +64,8 @@ Item {
57 minWidth: units.gu(15)
64 minWidth: units.gu(15)
58 minHeight: units.gu(10)
65 minHeight: units.gu(10)
59 windowId: "test-window-id"
66 windowId: "test-window-id"
67+ screenWidth: root.width
68+ screenHeight: root.height
60 }
69 }
61
70
62 Rectangle {
71 Rectangle {
@@ -228,5 +237,39 @@ Item {
228 // clean up
237 // clean up
229 fakeWindow.state = "normal"
238 fakeWindow.state = "normal"
230 }
239 }
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+ }
231 }
274 }
232}
275}