on xenial help sign in
Provide window/surface close shortcuts across all the stages (LP: #1578392, #1606528)

Approved by: Michael Terry, Unity8 CI Bot

commit50521764a2eba42b59d5366814d80529d3b304de authorLukáš Tinkl <lukas.tinkl@canonical.com> dateWed 3 Aug 2016, 15:48 (10 years ago) parente01964abaeebf5
5 files changed+63−12
qml/Stages/AbstractStage.qml+9 qml/Stages/DesktopStage.qml+8−8 qml/Stages/PhoneStage.qml+8−2 qml/Stages/TabletStage.qml+8−2 tests/qmltests/tst_Shell.qml+30
qml/Stages/AbstractStage.qml+9
@@ -16,6 +16,7 @@
1616
1717import QtQuick 2.4
1818import Ubuntu.Components 1.3
19+import GlobalShortcut 1.0
1920import GSettings 1.0
2021
2122FocusScope {
@@ -78,4 +79,12 @@ FocusScope {
7879 color: "#060606"
7980 anchors.fill: parent
8081 }
82+
83+ // shared Alt+F4 functionality
84+ function closeFocusedDelegate() {} // to be implemented by stages
85+
86+ GlobalShortcut {
87+ shortcut: Qt.AltModifier|Qt.Key_F4
88+ onTriggered: closeFocusedDelegate()
89+ }
8190}
qml/Stages/DesktopStage.qml+8−8
@@ -36,6 +36,11 @@ AbstractStage {
3636 edgeBarrier.push(amount);
3737 }
3838 }
39+ function closeFocusedDelegate() {
40+ if (priv.focusedAppDelegate && !priv.focusedAppDelegate.isDash) {
41+ priv.focusedAppDelegate.close();
42+ }
43+ }
3944
4045 // Used by TutorialRight
4146 property bool spreadShown: spread.state == "altTab"
@@ -47,13 +52,6 @@ AbstractStage {
4752
4853 orientationChangesEnabled: true
4954
50− GlobalShortcut {
51− id: closeWindowShortcut
52− shortcut: Qt.AltModifier|Qt.Key_F4
53− onTriggered: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.close(); } }
54− active: priv.focusedAppDelegate !== null
55− }
56−
5755 GlobalShortcut {
5856 id: showSpreadShortcut
5957 shortcut: Qt.MetaModifier|Qt.Key_W
@@ -205,7 +203,7 @@ AbstractStage {
205203 Binding {
206204 target: PanelState
207205 property: "closeButtonShown"
208− value: priv.focusedAppDelegate && priv.focusedAppDelegate.maximized && priv.focusedAppDelegate.application.appId !== "unity8-dash"
206+ value: priv.focusedAppDelegate && priv.focusedAppDelegate.maximized && !priv.focusedAppDelegate.isDash
209207 }
210208
211209 Component.onDestruction: {
@@ -337,6 +335,8 @@ AbstractStage {
337335 readonly property var surface: model.surface
338336 readonly property alias resizeArea: resizeArea
339337
338+ readonly property bool isDash: model.application.appId == "unity8-dash"
339+
340340 function claimFocus() {
341341 if (spread.state == "altTab") {
342342 spread.cancel();
qml/Stages/PhoneStage.qml+8−2
@@ -108,6 +108,12 @@ AbstractStage {
108108 }
109109 }
110110
111+ function closeFocusedDelegate() {
112+ if (priv.focusedAppDelegate && priv.focusedAppDelegate.closeable) {
113+ priv.focusedAppDelegate.closed();
114+ }
115+ }
116+
111117 mainApp: priv.focusedAppDelegate ? priv.focusedAppDelegate.application : null
112118
113119 orientationChangesEnabled: priv.focusedAppOrientationChangesEnabled
@@ -465,13 +471,13 @@ AbstractStage {
465471 model: topLevelSurfaceList
466472
467473 onItemRemoved: {
468− // Unless we're closing the app ourselves in the spread,
474+ // Unless we're closing the app ourselves,
469475 // lets make sure the spread doesn't mess up by the changing app list.
470476 if (spreadView.closingIndex == -1) {
471477 spreadView.phase = 0;
472478 spreadView.contentX = -spreadView.shift;
473− focusTopMostApp();
474479 }
480+ focusTopMostApp();
475481 }
476482 function focusTopMostApp() {
477483 if (spreadRepeater.count > 0) {
qml/Stages/TabletStage.qml+8−2
@@ -84,6 +84,12 @@ AbstractStage {
8484 }
8585 }
8686
87+ function closeFocusedDelegate() {
88+ if (priv.focusedAppDelegate && priv.focusedAppDelegate.closeable) {
89+ priv.focusedAppDelegate.closed();
90+ }
91+ }
92+
8793 orientationChangesEnabled: priv.mainAppOrientationChangesEnabled
8894
8995 mainApp: {
@@ -707,13 +713,13 @@ AbstractStage {
707713
708714 onItemRemoved: {
709715 priv.updateMainAndSideStageIndexes();
710− // Unless we're closing the app ourselves in the spread,
716+ // Unless we're closing the app ourselves,
711717 // lets make sure the spread doesn't mess up by the changing app list.
712718 if (spreadView.closingIndex == -1) {
713719 spreadView.phase = 0;
714720 spreadView.contentX = -spreadView.shift;
715− focusTopMostApp();
716721 }
722+ focusTopMostApp();
717723 }
718724 function focusTopMostApp() {
719725 if (spreadRepeater.count > 0) {
tests/qmltests/tst_Shell.qml+30
@@ -2506,5 +2506,35 @@ Rectangle {
25062506 verify(greeter.shown);
25072507 verify(greeter.locked);
25082508 }
2509+
2510+ function test_closeFocusedDelegate_data() {
2511+ return [
2512+ { tag: "phone" },
2513+ { tag: "tablet" },
2514+ { tag: "desktop" }
2515+ ]
2516+ }
2517+
2518+ function test_closeFocusedDelegate(data) {
2519+ loadShell(data.tag);
2520+ shell.usageScenario = data.tag;
2521+ waitForRendering(shell);
2522+ swipeAwayGreeter();
2523+
2524+ var app2SurfaceId = topLevelSurfaceList.nextId;
2525+ var app2 = ApplicationManager.startApplication("calendar-app");
2526+ waitUntilAppWindowIsFullyLoaded(app2SurfaceId);
2527+
2528+ var app1SurfaceId = topLevelSurfaceList.nextId;
2529+ var app1 = ApplicationManager.startApplication("dialer-app")
2530+ waitUntilAppWindowIsFullyLoaded(app1SurfaceId);
2531+
2532+ var countBeforeClose = topLevelSurfaceList.count;
2533+
2534+ keyClick(Qt.Key_F4, Qt.AltModifier);
2535+
2536+ tryCompare(topLevelSurfaceList, "count", countBeforeClose - 1);
2537+ tryCompareFunction(function() { return ApplicationManager.focusedApplicationId; }, "calendar-app");
2538+ }
25092539 }
25102540}