on xenial help sign in
Make the appDelegate know when it's being focused

There's a "slide" animation that plays when apps are focused on their own request or on the request of an outside party. Unfortunately, this animation plays after the rightEdgeFocusAnimation, which calls 'appDelegate.activate()' when it stops. When that happens, the delegate acts like it was focused by another source and plays the sliding animation. This behavior was probably introduced in f1dcc66. The inhibitSlideAnimation property of each appDelegate gets set when it is focused with the flip animation and unset when it becomes unset. This strikes a good balance between simplicity and ensuring all the functionality (sliding in and out when another app is focused, for example) still works. Also, ensure the slide animations take the speed of the animations imposed by the Stage.

commitbb646a2649271af925c7e50c447b058ab2a77418 authorDalton Durst <dalton@ubports.com> dateTue 1 Oct 2019, 15:32 (7 years ago) parent4e758cb
2 files changed+18−2
qml/Stage/Stage.qml+15−1 qml/Stage/StageMaths.qml+3−1
qml/Stage/Stage.qml+15−1
@@ -829,6 +829,13 @@ FocusScope {
829829 onHeightChanged: appDelegate.updateNormalGeometry();
830830 }
831831
832+ // True when the Stage is focusing this app and playing its own animation.
833+ // Stays true until the app is unfocused.
834+ // If it is, we don't want to play the slide in/out transition from StageMaths.
835+ // Setting it imperatively is not great, but any declarative solution hits
836+ // race conditions, causing two animations to play for one focus event.
837+ property bool inhibitSlideAnimation: false
838+
832839 Binding {
833840 target: appDelegate
834841 property: "y"
@@ -975,6 +982,9 @@ FocusScope {
975982 target: model.window
976983 onFocusedChanged: {
977984 updateQmlFocusFromMirSurfaceFocus();
985+ if (!model.window.focused) {
986+ inhibitSlideAnimation = false;
987+ }
978988 }
979989 onFocusRequested: {
980990 appDelegate.activate();
@@ -1208,6 +1218,9 @@ FocusScope {
12081218 UbuntuNumberAnimation { target: appDelegate; properties: "x"; to: rightEdgeFocusAnimation.targetX; duration: priv.animationDuration }
12091219 UbuntuNumberAnimation { target: decoratedWindow; properties: "angle"; to: 0; duration: priv.animationDuration }
12101220 UbuntuNumberAnimation { target: decoratedWindow; properties: "itemScale"; to: 1; duration: priv.animationDuration }
1221+ onStarted: {
1222+ inhibitSlideAnimation = true;
1223+ }
12111224 onStopped: {
12121225 appDelegate.activate();
12131226 }
@@ -1235,6 +1248,7 @@ FocusScope {
12351248 sideStageX: sideStage.x
12361249 itemIndex: appDelegate.itemIndex
12371250 nextInStack: priv.nextInStack
1251+ animationDuration: priv.animationDuration
12381252 }
12391253
12401254 StagedRightEdgeMaths {
@@ -1387,7 +1401,7 @@ FocusScope {
13871401 }
13881402 PropertyChanges {
13891403 target: stageMaths
1390− animateX: !focusAnimation.running && itemIndex !== spreadItem.highlightedIndex
1404+ animateX: !focusAnimation.running && !rightEdgeFocusAnimation.running && itemIndex !== spreadItem.highlightedIndex && !inhibitSlideAnimation
13911405 }
13921406 PropertyChanges {
13931407 target: appDelegate.window
qml/Stage/StageMaths.qml+3−1
@@ -34,6 +34,8 @@ QtObject {
3434 property var mainStageDelegate: null
3535 property var sideStageDelegate: null
3636
37+ property int animationDuration: UbuntuAnimation.FastDuration
38+
3739 // output
3840
3941 // We need to shuffle z ordering a bit in order to keep side stage apps above main stage apps.
@@ -82,7 +84,7 @@ QtObject {
8284 }
8385 return sceneWidth;
8486 }
85− Behavior on itemX { enabled: root.animateX; UbuntuNumberAnimation {} }
87+ Behavior on itemX { enabled: root.animateX; UbuntuNumberAnimation {duration: animationDuration} }
8688
8789 readonly property int itemWidth: stage == ApplicationInfoInterface.MainStage ?
8890 sideStageDelegate != null ? sideStageX : sceneWidth :