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: surfaceContainer.implicitWidth
24 implicitHeight: surfaceContainer.implicitHeight
26 // to be read from outside
27 property alias interactive: surfaceContainer.interactive
28 property bool orientationChangesEnabled: d.supportsSurfaceResize ? d.surfaceOldEnoughToBeResized : true
29 readonly property string title: surface && surface.name !== "" ? surface.name : d.name
31 // overridable from outside
32 property bool fullscreen: {
34 return surface.state === Mir.FullscreenState;
35 } else if (application) {
36 return application.fullscreen;
42 // to be set from outside
43 property QtObject surface
44 property QtObject application
45 property int surfaceOrientationAngle
46 property alias resizeSurface: surfaceContainer.resizeSurface
47 property int requestedWidth: -1
48 property int requestedHeight: -1
50 readonly property int minimumWidth: surface ? surface.minimumWidth : 0
51 readonly property int minimumHeight: surface ? surface.minimumHeight : 0
52 readonly property int maximumWidth: surface ? surface.maximumWidth : 0
53 readonly property int maximumHeight: surface ? surface.maximumHeight : 0
54 readonly property int widthIncrement: surface ? surface.widthIncrement : 0
55 readonly property int heightIncrement: surface ? surface.heightIncrement : 0
58 // The order in which the instructions are executed here matters, to that the correct state
59 // transitions in stateGroup take place.
60 // More specifically, the moment surfaceContainer.surface gets updated relative to the
61 // other instructions.
63 surfaceContainer.surface = surface;
64 d.liveSurface = surface.live;
66 surfaceInitTimer.start();
68 if (d.surfaceInitialized) {
71 d.surfaceInitialized = false;
72 surfaceContainer.surface = null;
79 property bool liveSurface: false;
80 property var con: Connections {
82 onLiveChanged: d.liveSurface = root.surface.live
84 // using liveSurface instead of root.surface.live because with the latter
85 // this expression is not reevaluated when root.surface changes
86 readonly property bool needToTakeScreenshot: root.surface && d.surfaceInitialized && !d.liveSurface
87 && applicationState !== ApplicationInfoInterface.Running
88 onNeedToTakeScreenshotChanged: {
89 if (needToTakeScreenshot && screenshotImage.status === Image.Null) {
90 screenshotImage.take();
94 // helpers so that we don't have to check for the existence of an application everywhere
95 // (in order to avoid breaking qml binding due to a javascript exception)
96 readonly property string name: root.application ? root.application.name : ""
97 readonly property url icon: root.application ? root.application.icon : ""
98 readonly property int applicationState: root.application ? root.application.state : -1
99 readonly property string splashTitle: root.application ? root.application.splashTitle : ""
100 readonly property url splashImage: root.application ? root.application.splashImage : ""
101 readonly property bool splashShowHeader: root.application ? root.application.splashShowHeader : true
102 readonly property color splashColor: root.application ? root.application.splashColor : "#00000000"
103 readonly property color splashColorHeader: root.application ? root.application.splashColorHeader : "#00000000"
104 readonly property color splashColorFooter: root.application ? root.application.splashColorFooter : "#00000000"
106 // Whether the Application had a surface before but lost it.
107 property bool hadSurface: false
109 //FIXME - this is a hack to avoid the first few rendered frames as they
110 // might show the UI accommodating due to surface resizes on startup.
111 // Remove this when possible
112 property bool surfaceInitialized: false
114 readonly property bool supportsSurfaceResize:
116 ((application.supportedOrientations & Qt.PortraitOrientation)
117 || (application.supportedOrientations & Qt.InvertedPortraitOrientation))
119 ((application.supportedOrientations & Qt.LandscapeOrientation)
120 || (application.supportedOrientations & Qt.InvertedLandscapeOrientation))
122 property bool surfaceOldEnoughToBeResized: false
124 property Item focusedSurface: promptSurfacesRepeater.count === 0 ? surfaceContainer
125 : promptSurfacesRepeater.first
126 onFocusedSurfaceChanged: {
127 if (focusedSurface) {
128 focusedSurface.focus = true;
134 target: root.application
135 property: "initialSurfaceSize"
136 value: Qt.size(root.requestedWidth, root.requestedHeight)
143 if (root.surface && root.surface.live) {d.surfaceInitialized = true;}
148 id: surfaceIsOldTimer
150 onTriggered: { if (stateGroup.state === "surface") { d.surfaceOldEnoughToBeResized = true; } }
155 objectName: "screenshotImage"
157 antialiasing: !root.interactive
161 // Save memory by using a half-resolution (thus quarter size) screenshot.
162 // Do not make this a binding, we can only take the screenshot once!
163 surfaceContainer.grabToImage(
165 screenshotImage.source = result.url;
167 Qt.size(root.width / 2, root.height / 2));
176 z: screenshotImage.z + 1
177 sourceComponent: Component {
180 title: d.splashTitle ? d.splashTitle : d.name
181 imageSource: d.splashImage
183 showHeader: d.splashShowHeader
184 backgroundColor: d.splashColor
185 headerColor: d.splashColorHeader
186 footerColor: d.splashColorFooter
193 z: splashLoader.z + 1
194 requestedWidth: root.requestedWidth
195 requestedHeight: root.requestedHeight
196 surfaceOrientationAngle: application && application.rotatesWindowContents ? root.surfaceOrientationAngle : 0
200 id: promptSurfacesRepeater
201 objectName: "promptSurfacesRepeater"
202 // show only along with the top-most application surface
204 if (root.application && root.surface === root.application.surfaceList.first) {
205 return root.application.promptSurfaceList;
210 delegate: SurfaceContainer {
211 id: promptSurfaceContainer
212 interactive: index === 0 && root.interactive
213 surface: model.surface
216 isPromptSurface: true
217 z: surfaceContainer.z + (promptSurfacesRepeater.count - index)
218 property int index: model.index
219 onIndexChanged: updateFirst()
220 Component.onCompleted: updateFirst()
221 function updateFirst() {
223 promptSurfacesRepeater.first = promptSurfaceContainer;
232 property Item first: null
235 // SurfaceContainer size drives ApplicationWindow size
237 target: root; property: "width"
238 value: stateGroup.state === "surface" ? surfaceContainer.width : root.requestedWidth
239 when: root.requestedWidth >= 0
242 target: root; property: "height"
243 value: stateGroup.state === "surface" ? surfaceContainer.height : root.requestedHeight
244 when: root.requestedHeight >= 0
247 // ApplicationWindow size drives SurfaceContainer size
249 target: surfaceContainer; property: "width"; value: root.width
250 when: root.requestedWidth < 0
253 target: surfaceContainer; property: "height"; value: root.height
254 when: root.requestedHeight < 0
259 objectName: "applicationWindowStateGroup"
264 d.hadSurface && (!root.surface || !d.surfaceInitialized)
266 screenshotImage.status !== Image.Ready
271 !d.hadSurface && (!root.surface || !d.surfaceInitialized)
273 screenshotImage.status !== Image.Ready
278 (root.surface && d.surfaceInitialized)
281 (d.applicationState !== ApplicationInfoInterface.Running
282 && screenshotImage.status !== Image.Ready))
287 screenshotImage.status === Image.Ready
289 (d.applicationState !== ApplicationInfoInterface.Running
290 || !root.surface || !d.surfaceInitialized)
293 // This is a dead end. From here we expect the surface to be removed from the model
294 // shortly after we stop referencing to it in our SurfaceContainer.
297 // The surface died while the application is running. It must have been closed
298 // by the shell or the application decided to destroy it by itself
299 root.surface && d.surfaceInitialized && !d.liveSurface
300 && d.applicationState === ApplicationInfoInterface.Running
306 from: ""; to: "splashScreen"
307 PropertyAction { target: splashLoader; property: "active"; value: true }
308 PropertyAction { target: surfaceContainer
309 property: "visible"; value: false }
312 from: "splashScreen"; to: "surface"
313 SequentialAnimation {
314 PropertyAction { target: surfaceContainer
315 property: "opacity"; value: 0.0 }
316 PropertyAction { target: surfaceContainer
317 property: "visible"; value: true }
318 UbuntuNumberAnimation { target: surfaceContainer; property: "opacity";
320 duration: UbuntuAnimation.BriskDuration }
321 ScriptAction { script: {
322 splashLoader.active = false;
323 surfaceIsOldTimer.start();
328 from: "surface"; to: "splashScreen"
329 SequentialAnimation {
330 ScriptAction { script: {
331 surfaceIsOldTimer.stop();
332 d.surfaceOldEnoughToBeResized = false;
333 splashLoader.active = true;
334 surfaceContainer.visible = true;
336 UbuntuNumberAnimation { target: splashLoader; property: "opacity";
338 duration: UbuntuAnimation.BriskDuration }
339 PropertyAction { target: surfaceContainer
340 property: "visible"; value: false }
344 from: "surface"; to: "screenshot"
345 SequentialAnimation {
346 ScriptAction { script: {
347 surfaceIsOldTimer.stop();
348 d.surfaceOldEnoughToBeResized = false;
349 screenshotImage.visible = true;
351 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
353 duration: UbuntuAnimation.BriskDuration }
354 ScriptAction { script: {
355 surfaceContainer.visible = false;
356 surfaceContainer.surface = null;
362 from: "screenshot"; to: "surface"
363 SequentialAnimation {
364 PropertyAction { target: surfaceContainer
365 property: "visible"; value: true }
366 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
368 duration: UbuntuAnimation.BriskDuration }
369 ScriptAction { script: {
370 screenshotImage.visible = false;
371 screenshotImage.source = "";
372 surfaceIsOldTimer.start();
377 from: "splashScreen"; to: "screenshot"
378 SequentialAnimation {
379 PropertyAction { target: screenshotImage
380 property: "visible"; value: true }
381 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
383 duration: UbuntuAnimation.BriskDuration }
384 PropertyAction { target: splashLoader; property: "active"; value: false }
388 from: "surface"; to: "void"
389 ScriptAction { script: {
390 surfaceIsOldTimer.stop();
391 d.surfaceOldEnoughToBeResized = false;
392 surfaceContainer.visible = false;
396 from: "void"; to: "surface"
397 SequentialAnimation {
398 PropertyAction { target: surfaceContainer; property: "opacity"; value: 0.0 }
399 PropertyAction { target: surfaceContainer; property: "visible"; value: true }
400 UbuntuNumberAnimation { target: surfaceContainer; property: "opacity";
402 duration: UbuntuAnimation.BriskDuration }
403 ScriptAction { script: {
404 surfaceIsOldTimer.start();
410 SequentialAnimation {
411 ScriptAction { script: {
412 surfaceContainer.visible = false;
413 surfaceContainer.surface = null;