on xenial help sign in
Add support for closing apps from the spread with "Q" (LP: #1670327)

Approved by: Albert Astals Cid, Unity8 CI Bot

commitbcc34ecd20fe3e0725337e67f6c0b4fe40142e5f authorMichael Zanetti <michael.zanetti@canonical.com> dateTue 21 Mar 2017, 10:52 (10 years ago) parentea9234c7770e26
3 files changed+97
qml/Stage/Spread/Spread.qml+11 qml/Stage/Stage.qml+6 tests/qmltests/tst_Shell.qml+80
qml/Stage/Spread/Spread.qml+11
@@ -40,6 +40,7 @@ Item {
4040 property real rightEdgeBreakPoint: Math.min(units.gu(40) / root.width, .35)
4141
4242 signal leaveSpread()
43+ signal closeCurrentApp();
4344
4445 // Calculated stuff
4546 readonly property int totalItemCount: model.count
@@ -118,6 +119,13 @@ Item {
118119 Behavior on opacity { UbuntuNumberAnimation { } }
119120 }
120121
122+ readonly property int itemCount: root.model.count
123+ onItemCountChanged: {
124+ if (highlightedIndex >= itemCount) {
125+ highlightedIndex = itemCount - 1
126+ }
127+ }
128+
121129 Keys.onPressed: {
122130 switch (event.key) {
123131 case Qt.Key_Left:
@@ -130,6 +138,9 @@ Item {
130138 selectNext(event.isAutoRepeat)
131139 event.accepted = true;
132140 break;
141+ case Qt.Key_Q:
142+ closeCurrentApp();
143+ break;
133144 case Qt.Key_Escape:
134145 highlightedIndex = -1
135146 // Falling through intentionally
qml/Stage/Stage.qml+6
@@ -575,6 +575,12 @@ FocusScope {
575575 onLeaveSpread: {
576576 priv.goneToSpread = false;
577577 }
578+
579+ onCloseCurrentApp: {
580+ if (!appRepeater.itemAt(highlightedIndex).isDash) {
581+ appRepeater.itemAt(highlightedIndex).close();
582+ }
583+ }
578584 }
579585
580586 Connections {
tests/qmltests/tst_Shell.qml+80
@@ -2913,6 +2913,86 @@ Rectangle {
29132913 tryCompare(appDelegate, "state", "maximizedRight");
29142914 }
29152915
2916+
2917+ function test_closeAppsInSpreadWithQ() {
2918+ loadShell("desktop");
2919+ shell.usageScenario = "desktop";
2920+ waitForRendering(shell);
2921+ swipeAwayGreeter();
2922+
2923+ var appSurfaceId = topLevelSurfaceList.nextId;
2924+ var app = ApplicationManager.startApplication("dialer-app")
2925+ waitUntilAppWindowIsFullyLoaded(appSurfaceId);
2926+
2927+ appSurfaceId = topLevelSurfaceList.nextId;
2928+ app = ApplicationManager.startApplication("calendar-app")
2929+ waitUntilAppWindowIsFullyLoaded(appSurfaceId);
2930+
2931+ keyPress(Qt.Key_Alt);
2932+ keyClick(Qt.Key_Tab);
2933+
2934+ var stage = findChild(shell, "stage");
2935+ var spread = findChild(stage, "spreadItem");
2936+ var appRepeater = findChild(stage, "appRepeater");
2937+
2938+ tryCompare(stage, "state", "spread");
2939+
2940+ tryCompare(ApplicationManager, "count", 3);
2941+ tryCompareFunction(function() {return appRepeater.itemAt(spread.highlightedIndex).appId == "dialer-app"}, true);
2942+
2943+ // Close one app with Q while in spread
2944+ keyClick(Qt.Key_Q);
2945+
2946+ tryCompare(ApplicationManager, "count", 2);
2947+
2948+ // Now the dash should be highlighted
2949+ tryCompareFunction(function() {return appRepeater.itemAt(spread.highlightedIndex).appId == "unity8-dash"}, true);
2950+
2951+ keyClick(Qt.Key_Q);
2952+
2953+ // Dash is not closeable, should still be 2
2954+ tryCompare(ApplicationManager, "count", 2);
2955+
2956+ // Move to the next one, should be closable again
2957+ keyClick(Qt.Key_Tab);
2958+ tryCompareFunction(function() {return appRepeater.itemAt(spread.highlightedIndex).appId == "calendar-app"}, true);
2959+
2960+ // close it
2961+ keyClick(Qt.Key_Q);
2962+ tryCompare(ApplicationManager, "count", 1);
2963+
2964+ keyRelease(Qt.Key_Alt);
2965+
2966+ // Now start the apps again
2967+ appSurfaceId = topLevelSurfaceList.nextId;
2968+ app = ApplicationManager.startApplication("dialer-app");
2969+ waitUntilAppWindowIsFullyLoaded(appSurfaceId);
2970+
2971+ appSurfaceId = topLevelSurfaceList.nextId;
2972+ app = ApplicationManager.startApplication("calendar-app");
2973+ waitUntilAppWindowIsFullyLoaded(appSurfaceId);
2974+
2975+ // First focus the dash so it'll be the leftmost in the spread
2976+ ApplicationManager.requestFocusApplication("unity8-dash");
2977+
2978+ keyPress(Qt.Key_Alt);
2979+ keyClick(Qt.Key_Tab);
2980+ tryCompare(stage, "state", "spread");
2981+
2982+ // Move to the last one
2983+ keyClick(Qt.Key_Tab);
2984+
2985+ // Close the last one, make sure the highlight fixes itself to stick within the list
2986+ tryCompare(spread, "highlightedIndex", ApplicationManager.count - 1);
2987+ var oldHighlighted = spread.highlightedIndex;
2988+
2989+ keyClick(Qt.Key_Q);
2990+ tryCompare(spread, "highlightedIndex", oldHighlighted - 1);
2991+
2992+ keyRelease(Qt.Key_Alt);
2993+
2994+ }
2995+
29162996 function test_altTabToMinimizedApp() {
29172997 loadShell("desktop");
29182998 shell.usageScenario = "desktop";