2 * Copyright 2014-2016 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.3
19 import Unity.Application 0.1
23 implicitWidth: sessionContainer.implicitWidth
24 implicitHeight: sessionContainer.implicitHeight
26 // to be read from outside
27 property alias interactive: sessionContainer.interactive
28 property bool orientationChangesEnabled: d.supportsSurfaceResize ? d.surfaceOldEnoughToBeResized : true
29 readonly property string title: sessionContainer.surface && sessionContainer.surface.name !== "" ?
30 sessionContainer.surface.name : d.name
32 // overridable from outside
33 property bool fullscreen: application ? application.fullscreen : false
35 // to be set from outside
36 property QtObject application
37 property int surfaceOrientationAngle
38 property alias resizeSurface: sessionContainer.resizeSurface
39 property int requestedWidth: -1
40 property int requestedHeight: -1
42 function switchToKeymap(keymap) {
43 sessionContainer.surfaceContainer.switchToKeymap(keymap);
46 readonly property int minimumWidth: sessionContainer.surface ? sessionContainer.surface.minimumWidth : 0
47 readonly property int minimumHeight: sessionContainer.surface ? sessionContainer.surface.minimumHeight : 0
48 readonly property int maximumWidth: sessionContainer.surface ? sessionContainer.surface.maximumWidth : 0
49 readonly property int maximumHeight: sessionContainer.surface ? sessionContainer.surface.maximumHeight : 0
50 readonly property int widthIncrement: sessionContainer.surface ? sessionContainer.surface.widthIncrement : 0
51 readonly property int heightIncrement: sessionContainer.surface ? sessionContainer.surface.heightIncrement : 0
56 // helpers so that we don't have to check for the existence of an application everywhere
57 // (in order to avoid breaking qml binding due to a javascript exception)
58 readonly property string name: root.application ? root.application.name : ""
59 readonly property url icon: root.application ? root.application.icon : ""
60 readonly property int applicationState: root.application ? root.application.state : -1
61 readonly property string splashTitle: root.application ? root.application.splashTitle : ""
62 readonly property url splashImage: root.application ? root.application.splashImage : ""
63 readonly property bool splashShowHeader: root.application ? root.application.splashShowHeader : true
64 readonly property color splashColor: root.application ? root.application.splashColor : "#00000000"
65 readonly property color splashColorHeader: root.application ? root.application.splashColorHeader : "#00000000"
66 readonly property color splashColorFooter: root.application ? root.application.splashColorFooter : "#00000000"
68 // Whether the Application had a surface before but lost it.
69 property bool hadSurface: sessionContainer.surfaceContainer.hadSurface
71 readonly property bool needToTakeScreenshot:
72 ((sessionContainer.surface && d.surfaceInitialized) || d.hadSurface)
73 && screenshotImage.status === Image.Null
74 && d.applicationState === ApplicationInfoInterface.Stopped
75 onNeedToTakeScreenshotChanged: {
76 if (needToTakeScreenshot) {
77 screenshotImage.take();
81 //FIXME - this is a hack to avoid the first few rendered frames as they
82 // might show the UI accommodating due to surface resizes on startup.
83 // Remove this when possible
84 property bool surfaceInitialized: false
86 readonly property bool supportsSurfaceResize:
88 ((application.supportedOrientations & Qt.PortraitOrientation)
89 || (application.supportedOrientations & Qt.InvertedPortraitOrientation))
91 ((application.supportedOrientations & Qt.LandscapeOrientation)
92 || (application.supportedOrientations & Qt.InvertedLandscapeOrientation))
94 property bool surfaceOldEnoughToBeResized: false
98 target: root.application
99 property: "initialSurfaceSize"
100 value: Qt.size(root.requestedWidth, root.requestedHeight)
106 onTriggered: { if (sessionContainer.surface) {d.surfaceInitialized = true;} }
110 id: surfaceIsOldTimer
112 onTriggered: { if (stateGroup.state === "surface") { d.surfaceOldEnoughToBeResized = true; } }
117 objectName: "screenshotImage"
119 antialiasing: !root.interactive
122 // Save memory by using a half-resolution (thus quarter size) screenshot.
123 // Do not make this a binding, we can only take the screenshot once!
124 sourceSize.width = root.width / 2;
125 sourceSize.height = root.height / 2;
127 // Format: "image://application/$APP_ID/$CURRENT_TIME_MS"
128 // eg: "image://application/calculator-app/123456"
129 var timeMs = new Date().getTime();
130 source = "image://application/" + root.application.appId + "/" + timeMs;
139 sourceComponent: Component {
142 title: d.splashTitle ? d.splashTitle : d.name
143 imageSource: d.splashImage
145 showHeader: d.splashShowHeader
146 backgroundColor: d.splashColor
147 headerColor: d.splashColorHeader
148 footerColor: d.splashColorFooter
155 // A fake application might not even have a session property.
156 session: application && application.session ? application.session : null
158 requestedWidth: root.requestedWidth
159 requestedHeight: root.requestedHeight
161 surfaceOrientationAngle: application && application.rotatesWindowContents ? root.surfaceOrientationAngle : 0
164 if (sessionContainer.surface) {
165 surfaceInitTimer.start();
167 d.surfaceInitialized = false;
174 // SessionContainer size drives ApplicationWindow size
176 target: root; property: "width"
177 value: stateGroup.state === "surface" ? sessionContainer.width : root.requestedWidth
178 when: root.requestedWidth >= 0
181 target: root; property: "height"
182 value: stateGroup.state === "surface" ? sessionContainer.height : root.requestedHeight
183 when: root.requestedHeight >= 0
186 // ApplicationWindow size drives SessionContainer size
188 target: sessionContainer; property: "width"; value: root.width
189 when: root.requestedWidth < 0
192 target: sessionContainer; property: "height"; value: root.height
193 when: root.requestedHeight < 0
198 objectName: "applicationWindowStateGroup"
203 d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
205 screenshotImage.status !== Image.Ready
210 !d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
212 screenshotImage.status !== Image.Ready
217 (sessionContainer.surface && d.surfaceInitialized)
219 (d.applicationState !== ApplicationInfoInterface.Stopped
220 || screenshotImage.status !== Image.Ready)
225 screenshotImage.status === Image.Ready
227 (d.applicationState === ApplicationInfoInterface.Stopped
228 || !sessionContainer.surface || !d.surfaceInitialized)
234 from: ""; to: "splashScreen"
235 PropertyAction { target: splashLoader; property: "active"; value: true }
236 PropertyAction { target: sessionContainer.surfaceContainer
237 property: "visible"; value: false }
240 from: "splashScreen"; to: "surface"
241 SequentialAnimation {
242 PropertyAction { target: sessionContainer.surfaceContainer
243 property: "opacity"; value: 0.0 }
244 PropertyAction { target: sessionContainer.surfaceContainer
245 property: "visible"; value: true }
246 UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
248 duration: UbuntuAnimation.BriskDuration }
249 ScriptAction { script: {
250 splashLoader.active = false;
251 surfaceIsOldTimer.start();
256 from: "surface"; to: "splashScreen"
257 SequentialAnimation {
258 ScriptAction { script: {
259 surfaceIsOldTimer.stop();
260 d.surfaceOldEnoughToBeResized = false;
261 splashLoader.active = true;
262 sessionContainer.surfaceContainer.visible = true;
264 UbuntuNumberAnimation { target: splashLoader; property: "opacity";
266 duration: UbuntuAnimation.BriskDuration }
267 PropertyAction { target: sessionContainer.surfaceContainer
268 property: "visible"; value: false }
272 from: "surface"; to: "screenshot"
273 SequentialAnimation {
274 ScriptAction { script: {
275 surfaceIsOldTimer.stop();
276 d.surfaceOldEnoughToBeResized = false;
277 screenshotImage.visible = true;
279 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
281 duration: UbuntuAnimation.BriskDuration }
282 ScriptAction { script: {
283 sessionContainer.surfaceContainer.visible = false;
284 if (sessionContainer.session) { sessionContainer.session.release(); }
289 from: "screenshot"; to: "surface"
290 SequentialAnimation {
291 PropertyAction { target: sessionContainer.surfaceContainer
292 property: "visible"; value: true }
293 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
295 duration: UbuntuAnimation.BriskDuration }
296 ScriptAction { script: {
297 screenshotImage.visible = false;
298 screenshotImage.source = "";
299 surfaceIsOldTimer.start();
304 from: "splashScreen"; to: "screenshot"
305 SequentialAnimation {
306 PropertyAction { target: screenshotImage
307 property: "visible"; value: true }
308 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
310 duration: UbuntuAnimation.BriskDuration }
311 PropertyAction { target: splashLoader; property: "active"; value: false }
315 from: "surface"; to: "void"
316 ScriptAction { script: {
317 surfaceIsOldTimer.stop();
318 d.surfaceOldEnoughToBeResized = false;
319 sessionContainer.surfaceContainer.visible = false;
320 if (sessionContainer.session) { sessionContainer.session.release(); }
324 from: "void"; to: "surface"
325 SequentialAnimation {
326 PropertyAction { target: sessionContainer.surfaceContainer; property: "opacity"; value: 0.0 }
327 PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: true }
328 UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
330 duration: UbuntuAnimation.BriskDuration }
331 ScriptAction { script: {
332 surfaceIsOldTimer.start();