on xenial help sign in
Restore focus to where it was when our ShellDialogs get unloaded
7b99df2Albert Astals Cid
qml/Components/Dialogs.qml+19
@@ -149,6 +149,25 @@ MouseArea {
149 objectName: "dialogLoader"
149 objectName: "dialogLoader"
150 anchors.fill: parent
150 anchors.fill: parent
151 active: false
151 active: false
152+ onActiveChanged: {
153+ if (!active) {
154+ if (previousFocusedItem) {
155+ previousFocusedItem.forceActiveFocus(Qt.OtherFocusReason);
156+ previousFocusedItem = undefined;
157+ }
158+ previousSourceComponent = undefined;
159+ sourceComponent = undefined;
160+ }
161+ }
162+ onSourceComponentChanged: {
163+ if (previousSourceComponent !== sourceComponent) {
164+ previousSourceComponent = sourceComponent;
165+ previousFocusedItem = window.activeFocusItem;
166+ }
167+ }
168+
169+ property var previousSourceComponent: undefined
170+ property var previousFocusedItem: undefined
152 }
171 }
153
172
154 Component {
173 Component {
tests/qmltests/tst_OrientedShell.qml+35
@@ -1603,5 +1603,40 @@ Rectangle {
1603
1603
1604 tryCompare(dialogLoader, "item", null);
1604 tryCompare(dialogLoader, "item", null);
1605 }
1605 }
1606+
1607+ function test_focusOnShutdownDialogClose() {
1608+ loadShell("manta");
1609+ usageModeSelector.selectWindowed();
1610+
1611+ var surfaceId = topLevelSurfaceList.nextId;
1612+ var app = ApplicationManager.startApplication("twitter-webapp");
1613+ waitUntilAppWindowIsFullyLoaded(surfaceId);
1614+
1615+ var primaryAppWindow = findAppWindowForSurfaceId(surfaceId);
1616+ var surface = app.surfaceList.get(0);
1617+ var surfaceItem = findSurfaceItem(primaryAppWindow, surface);
1618+
1619+ compare(window.activeFocusItem, surfaceItem);
1620+
1621+ testCase.showPowerDialog();
1622+
1623+ var dialogLoader = findChild(orientedShell, "dialogLoader");
1624+ tryCompareFunction(function() { return dialogLoader.item !== null }, true);
1625+
1626+ keyClick(Qt.Key_Escape);
1627+
1628+ tryCompare(dialogLoader, "item", null);
1629+ compare(window.activeFocusItem, surfaceItem);
1630+
1631+ // Do it twice, our previous solution failed the second time ^_^
1632+ testCase.showPowerDialog();
1633+
1634+ tryCompareFunction(function() { return dialogLoader.item !== null }, true);
1635+
1636+ keyClick(Qt.Key_Escape);
1637+
1638+ tryCompare(dialogLoader, "item", null);
1639+ compare(window.activeFocusItem, surfaceItem);
1640+ }
1606 }
1641 }
1607}
1642}