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
30 readonly property QtObject focusedSurface: d.focusedSurface.surface
32 // overridable from outside
33 property bool fullscreen: {
35 return surface.state === Mir.FullscreenState;
36 } else if (application) {
37 return application.fullscreen;
43 // to be set from outside
44 property QtObject surface
45 property QtObject application
46 property int surfaceOrientationAngle
47 property alias resizeSurface: surfaceContainer.resizeSurface
48 property int requestedWidth: -1
49 property int requestedHeight: -1
50 property real splashRotation: 0
52 readonly property int minimumWidth: surface ? surface.minimumWidth : 0
53 readonly property int minimumHeight: surface ? surface.minimumHeight : 0
54 readonly property int maximumWidth: surface ? surface.maximumWidth : 0
55 readonly property int maximumHeight: surface ? surface.maximumHeight : 0
56 readonly property int widthIncrement: surface ? surface.widthIncrement : 0
57 readonly property int heightIncrement: surface ? surface.heightIncrement : 0
60 // The order in which the instructions are executed here matters, to that the correct state
61 // transitions in stateGroup take place.
62 // More specifically, the moment surfaceContainer.surface gets updated relative to the
63 // other instructions.
65 surfaceContainer.surface = surface;
66 d.liveSurface = surface.live;
68 surfaceInitTimer.start();
70 if (d.surfaceInitialized) {
73 d.surfaceInitialized = false;
74 surfaceContainer.surface = null;
81 property bool liveSurface: false;
82 property var con: Connections {
84 onLiveChanged: d.liveSurface = root.surface.live
86 // using liveSurface instead of root.surface.live because with the latter
87 // this expression is not reevaluated when root.surface changes
88 readonly property bool needToTakeScreenshot: root.surface && d.surfaceInitialized && !d.liveSurface
89 && applicationState !== ApplicationInfoInterface.Running
90 onNeedToTakeScreenshotChanged: {
91 if (needToTakeScreenshot && screenshotImage.status === Image.Null) {
92 screenshotImage.take();
96 // helpers so that we don't have to check for the existence of an application everywhere
97 // (in order to avoid breaking qml binding due to a javascript exception)
98 readonly property string name: root.application ? root.application.name : ""
99 readonly property url icon: root.application ? root.application.icon : ""
100 readonly property int applicationState: root.application ? root.application.state : -1
101 readonly property string splashTitle: root.application ? root.application.splashTitle : ""
102 readonly property url splashImage: root.application ? root.application.splashImage : ""
103 readonly property bool splashShowHeader: root.application ? root.application.splashShowHeader : true
104 readonly property color splashColor: root.application ? root.application.splashColor : "#00000000"
105 readonly property color splashColorHeader: root.application ? root.application.splashColorHeader : "#00000000"
106 readonly property color splashColorFooter: root.application ? root.application.splashColorFooter : "#00000000"
108 // Whether the Application had a surface before but lost it.
109 property bool hadSurface: false
111 //FIXME - this is a hack to avoid the first few rendered frames as they
112 // might show the UI accommodating due to surface resizes on startup.
113 // Remove this when possible
114 property bool surfaceInitialized: false
116 readonly property bool supportsSurfaceResize:
118 ((application.supportedOrientations & Qt.PortraitOrientation)
119 || (application.supportedOrientations & Qt.InvertedPortraitOrientation))
121 ((application.supportedOrientations & Qt.LandscapeOrientation)
122 || (application.supportedOrientations & Qt.InvertedLandscapeOrientation))
124 property bool surfaceOldEnoughToBeResized: false
126 property Item focusedSurface: promptSurfacesRepeater.count === 0 ? surfaceContainer
127 : promptSurfacesRepeater.first
128 onFocusedSurfaceChanged: {
129 if (focusedSurface) {
130 focusedSurface.focus = true;
136 target: root.application
137 property: "initialSurfaceSize"
138 value: Qt.size(root.requestedWidth, root.requestedHeight)
145 if (root.surface && root.surface.live) {d.surfaceInitialized = true;}
150 id: surfaceIsOldTimer
152 onTriggered: { if (stateGroup.state === "surface") { d.surfaceOldEnoughToBeResized = true; } }
157 objectName: "screenshotImage"
159 antialiasing: !root.interactive
163 // Save memory by using a half-resolution (thus quarter size) screenshot.
164 // Do not make this a binding, we can only take the screenshot once!
165 surfaceContainer.grabToImage(
167 screenshotImage.source = result.url;
169 Qt.size(root.width / 2, root.height / 2));
178 z: screenshotImage.z + 1
179 sourceComponent: Component {
182 title: d.splashTitle ? d.splashTitle : d.name
183 imageSource: d.splashImage
185 showHeader: d.splashShowHeader
186 backgroundColor: d.splashColor
187 headerColor: d.splashColorHeader
188 footerColor: d.splashColorFooter
190 rotation: root.splashRotation
191 anchors.centerIn: parent
192 width: rotation == 0 || rotation == 180 ? root.width : root.height
193 height: rotation == 0 || rotation == 180 ? root.height : root.width
200 z: splashLoader.z + 1
201 requestedWidth: root.requestedWidth
202 requestedHeight: root.requestedHeight
203 surfaceOrientationAngle: application && application.rotatesWindowContents ? root.surfaceOrientationAngle : 0
207 id: promptSurfacesRepeater
208 objectName: "promptSurfacesRepeater"
209 // show only along with the top-most application surface
211 if (root.application && root.surface === root.application.surfaceList.first) {
212 return root.application.promptSurfaceList;
217 delegate: SurfaceContainer {
218 id: promptSurfaceContainer
219 interactive: index === 0 && root.interactive
220 surface: model.surface
223 isPromptSurface: true
224 z: surfaceContainer.z + (promptSurfacesRepeater.count - index)
225 property int index: model.index
226 onIndexChanged: updateFirst()
227 Component.onCompleted: updateFirst()
228 function updateFirst() {
230 promptSurfacesRepeater.first = promptSurfaceContainer;
239 property Item first: null
242 // SurfaceContainer size drives ApplicationWindow size
244 target: root; property: "width"
245 value: stateGroup.state === "surface" ? surfaceContainer.width : root.requestedWidth
246 when: root.requestedWidth >= 0
249 target: root; property: "height"
250 value: stateGroup.state === "surface" ? surfaceContainer.height : root.requestedHeight
251 when: root.requestedHeight >= 0
254 // ApplicationWindow size drives SurfaceContainer size
256 target: surfaceContainer; property: "width"; value: root.width
257 when: root.requestedWidth < 0
260 target: surfaceContainer; property: "height"; value: root.height
261 when: root.requestedHeight < 0
266 objectName: "applicationWindowStateGroup"
271 d.hadSurface && (!root.surface || !d.surfaceInitialized)
273 screenshotImage.status !== Image.Ready
278 !d.hadSurface && (!root.surface || !d.surfaceInitialized)
280 screenshotImage.status !== Image.Ready
285 (root.surface && d.surfaceInitialized)
288 (d.applicationState !== ApplicationInfoInterface.Running
289 && screenshotImage.status !== Image.Ready))
294 screenshotImage.status === Image.Ready
296 (d.applicationState !== ApplicationInfoInterface.Running
297 || !root.surface || !d.surfaceInitialized)
300 // This is a dead end. From here we expect the surface to be removed from the model
301 // shortly after we stop referencing to it in our SurfaceContainer.
304 // The surface died while the application is running. It must have been closed
305 // by the shell or the application decided to destroy it by itself
306 root.surface && d.surfaceInitialized && !d.liveSurface
307 && d.applicationState === ApplicationInfoInterface.Running
313 from: ""; to: "splashScreen"
314 PropertyAction { target: splashLoader; property: "active"; value: true }
315 PropertyAction { target: surfaceContainer
316 property: "visible"; value: false }
319 from: "splashScreen"; to: "surface"
320 SequentialAnimation {
321 PropertyAction { target: surfaceContainer
322 property: "opacity"; value: 0.0 }
323 PropertyAction { target: surfaceContainer
324 property: "visible"; value: true }
325 UbuntuNumberAnimation { target: surfaceContainer; property: "opacity";
327 duration: UbuntuAnimation.BriskDuration }
328 ScriptAction { script: {
329 splashLoader.active = false;
330 surfaceIsOldTimer.start();
335 from: "surface"; to: "splashScreen"
336 SequentialAnimation {
337 ScriptAction { script: {
338 surfaceIsOldTimer.stop();
339 d.surfaceOldEnoughToBeResized = false;
340 splashLoader.active = true;
341 surfaceContainer.visible = true;
343 UbuntuNumberAnimation { target: splashLoader; property: "opacity";
345 duration: UbuntuAnimation.BriskDuration }
346 PropertyAction { target: surfaceContainer
347 property: "visible"; value: false }
351 from: "surface"; to: "screenshot"
352 SequentialAnimation {
353 ScriptAction { script: {
354 surfaceIsOldTimer.stop();
355 d.surfaceOldEnoughToBeResized = false;
356 screenshotImage.visible = true;
358 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
360 duration: UbuntuAnimation.BriskDuration }
361 ScriptAction { script: {
362 surfaceContainer.visible = false;
363 surfaceContainer.surface = null;
369 from: "screenshot"; to: "surface"
370 SequentialAnimation {
371 PropertyAction { target: surfaceContainer
372 property: "visible"; value: true }
373 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
375 duration: UbuntuAnimation.BriskDuration }
376 ScriptAction { script: {
377 screenshotImage.visible = false;
378 screenshotImage.source = "";
379 surfaceIsOldTimer.start();
384 from: "splashScreen"; to: "screenshot"
385 SequentialAnimation {
386 PropertyAction { target: screenshotImage
387 property: "visible"; value: true }
388 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
390 duration: UbuntuAnimation.BriskDuration }
391 PropertyAction { target: splashLoader; property: "active"; value: false }
395 from: "surface"; to: "void"
396 ScriptAction { script: {
397 surfaceIsOldTimer.stop();
398 d.surfaceOldEnoughToBeResized = false;
399 surfaceContainer.visible = false;
403 from: "void"; to: "surface"
404 SequentialAnimation {
405 PropertyAction { target: surfaceContainer; property: "opacity"; value: 0.0 }
406 PropertyAction { target: surfaceContainer; property: "visible"; value: true }
407 UbuntuNumberAnimation { target: surfaceContainer; property: "opacity";
409 duration: UbuntuAnimation.BriskDuration }
410 ScriptAction { script: {
411 surfaceIsOldTimer.start();
417 SequentialAnimation {
418 ScriptAction { script: {
419 surfaceContainer.visible = false;
420 surfaceContainer.surface = null;