2 * Copyright 2014 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import Ubuntu.Components 1.1
19 import Unity.Application 0.1
24 // to be read from outside
25 readonly property bool fullscreen: application ? application.fullscreen : false
26 property alias interactive: sessionContainer.interactive
28 // to be set from outside
29 property QtObject application
30 property int orientation
35 // helpers so that we don't have to check for the existence of an application everywhere
36 // (in order to avoid breaking qml binding due to a javascript exception)
37 readonly property string name: root.application ? root.application.name : ""
38 readonly property url icon: root.application ? root.application.icon : ""
39 readonly property int applicationState: root.application ? root.application.state : -1
41 // Whether the Application had a surface before but lost it.
42 property bool hadSurface: sessionContainer.surfaceContainer.hadSurface
44 property bool needToTakeScreenshot:
45 sessionContainer.surface && d.surfaceInitialized && screenshotImage.status === Image.Null
46 && d.applicationState === ApplicationInfoInterface.Stopped
47 onNeedToTakeScreenshotChanged: {
48 if (needToTakeScreenshot) {
49 screenshotImage.take();
53 //FIXME - this is a hack to avoid the first few rendered frames as they
54 // might show the UI accommodating due to surface resizes on startup.
55 // Remove this when possible
56 property bool surfaceInitialized: false
58 function forceSurfaceActiveFocusIfReady() {
59 if (sessionContainer.surface !== null &&
60 sessionContainer.surface.focus &&
61 sessionContainer.surface.parent === sessionContainer.surfaceContainer &&
62 sessionContainer.surface.enabled) {
63 sessionContainer.surface.forceActiveFocus();
71 onTriggered: { if (sessionContainer.surface) {d.surfaceInitialized = true;} }
75 target: sessionContainer.surface
76 // FIXME: I would rather not need to do this, but currently it doesn't get
77 // active focus without it and I don't know why.
78 onFocusChanged: d.forceSurfaceActiveFocusIfReady();
79 onParentChanged: d.forceSurfaceActiveFocusIfReady();
80 onEnabledChanged: d.forceSurfaceActiveFocusIfReady();
85 objectName: "screenshotImage"
90 // Format: "image://application/$APP_ID/$CURRENT_TIME_MS"
91 // eg: "image://application/calculator-app/123456"
92 var timeMs = new Date().getTime();
93 source = "image://application/" + root.application.appId + "/" + timeMs;
96 // Save memory by using a half-resolution (thus quarter size) screenshot
97 sourceSize.width: root.width / 2
98 sourceSize.height: root.height / 2
106 sourceComponent: Component {
107 Splash { name: d.name; image: d.icon }
113 session: application ? application.session : null
115 orientation: root.orientation
118 if (sessionContainer.surface) {
119 surfaceInitTimer.start();
120 d.forceSurfaceActiveFocusIfReady();
122 d.surfaceInitialized = false;
128 objectName: "applicationWindowStateGroup"
133 d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
135 screenshotImage.status !== Image.Ready
140 !d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
142 screenshotImage.status !== Image.Ready
147 (sessionContainer.surface && d.surfaceInitialized)
149 (d.applicationState !== ApplicationInfoInterface.Stopped
150 || screenshotImage.status !== Image.Ready)
155 screenshotImage.status === Image.Ready
157 (d.applicationState === ApplicationInfoInterface.Stopped
158 || !sessionContainer.surface || !d.surfaceInitialized)
164 from: ""; to: "splashScreen"
165 PropertyAction { target: splashLoader; property: "active"; value: true }
166 PropertyAction { target: sessionContainer.surfaceContainer
167 property: "visible"; value: false }
170 from: "splashScreen"; to: "surface"
171 SequentialAnimation {
172 PropertyAction { target: sessionContainer.surfaceContainer
173 property: "opacity"; value: 0.0 }
174 PropertyAction { target: sessionContainer.surfaceContainer
175 property: "visible"; value: true }
176 UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
178 duration: UbuntuAnimation.BriskDuration }
179 PropertyAction { target: splashLoader; property: "active"; value: false }
183 from: "surface"; to: "splashScreen"
184 SequentialAnimation {
185 PropertyAction { target: splashLoader; property: "active"; value: true }
186 PropertyAction { target: sessionContainer.surfaceContainer
187 property: "visible"; value: true }
188 UbuntuNumberAnimation { target: splashLoader; property: "opacity";
190 duration: UbuntuAnimation.BriskDuration }
191 PropertyAction { target: sessionContainer.surfaceContainer
192 property: "visible"; value: false }
196 from: "surface"; to: "screenshot"
197 SequentialAnimation {
198 PropertyAction { target: screenshotImage
199 property: "visible"; value: true }
200 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
202 duration: UbuntuAnimation.BriskDuration }
203 PropertyAction { target: sessionContainer.surfaceContainer
204 property: "visible"; value: false }
205 ScriptAction { script: { if (sessionContainer.session) { sessionContainer.session.release(); } } }
209 from: "screenshot"; to: "surface"
210 SequentialAnimation {
211 PropertyAction { target: sessionContainer.surfaceContainer
212 property: "visible"; value: true }
213 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
215 duration: UbuntuAnimation.BriskDuration }
216 PropertyAction { target: screenshotImage; property: "visible"; value: false }
217 PropertyAction { target: screenshotImage; property: "source"; value: "" }
221 from: "surface"; to: "void"
222 SequentialAnimation {
223 PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: false }
224 ScriptAction { script: { if (sessionContainer.session) { sessionContainer.session.release(); } } }
228 from: "void"; to: "surface"
229 SequentialAnimation {
230 PropertyAction { target: sessionContainer.surfaceContainer; property: "opacity"; value: 0.0 }
231 PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: true }
232 UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
234 duration: UbuntuAnimation.BriskDuration }