@@ -32,6 +32,18 @@ Rectangle {
3232 property bool spreadEnabled: true // If false, animations and right edge will be disabled
3333 property real inverseProgress: 0 // This is the progress for left edge drags, in pixels.
3434 property int orientation: Qt.PortraitOrientation
35+ property QtObject applicationManager: ApplicationManager
36+ property bool focusFirstApp: true // If false, focused app will appear on right edge like other apps
37+ property bool altTabEnabled: true
38+ property real startScale: 1.1
39+ property real endScale: 0.7
40+
41+ // How far left the stage has been dragged
42+ readonly property real dragProgress: spreadRepeater.count > 0 ? -spreadRepeater.itemAt(0).xTranslate : 0
43+
44+ readonly property alias dragging: spreadDragArea.dragging
45+
46+ signal opened()
3547
3648 color: "#111111"
3749
@@ -52,30 +64,30 @@ Rectangle {
5264 if (inverseProgress == 0 && priv.oldInverseProgress > 0) {
5365 // left edge drag released. Minimum distance is given by design.
5466 if (priv.oldInverseProgress > units.gu(22)) {
55− ApplicationManager.focusApplication("unity8-dash");
67+ applicationManager.focusApplication("unity8-dash");
5668 }
5769 }
5870 priv.oldInverseProgress = inverseProgress;
5971 }
6072
6173 Connections {
62− target: ApplicationManager
74+ target: applicationManager
6375
6476 onFocusRequested: {
6577 if (spreadView.phase > 0) {
6678 spreadView.snapTo(priv.indexOf(appId));
6779 } else {
68− ApplicationManager.focusApplication(appId);
80+ applicationManager.focusApplication(appId);
6981 }
7082 }
7183
7284 onApplicationAdded: {
7385 if (spreadView.phase == 2) {
74− spreadView.snapTo(ApplicationManager.count - 1);
86+ spreadView.snapTo(applicationManager.count - 1);
7587 } else {
7688 spreadView.phase = 0;
7789 spreadView.contentX = -spreadView.shift;
78− ApplicationManager.focusApplication(appId);
90+ applicationManager.focusApplication(appId);
7991 }
8092 }
8193
@@ -90,9 +102,9 @@ Rectangle {
90102 }
91103
92104 function focusTopMostApp() {
93− if (ApplicationManager.count > 0) {
94− var topmostApp = ApplicationManager.get(0);
95− ApplicationManager.focusApplication(topmostApp.appId);
105+ if (applicationManager.count > 0) {
106+ var topmostApp = applicationManager.get(0);
107+ applicationManager.focusApplication(topmostApp.appId);
96108 }
97109 }
98110 }
@@ -100,8 +112,9 @@ Rectangle {
100112 QtObject {
101113 id: priv
102114
103− property string focusedAppId: ApplicationManager.focusedApplicationId
104− property var focusedApplication: ApplicationManager.findApplication(focusedAppId)
115+ readonly property int firstSpreadIndex: root.focusFirstApp ? 1 : 0
116+ property string focusedAppId: applicationManager.focusedApplicationId
117+ property var focusedApplication: applicationManager.findApplication(focusedAppId)
105118 property var focusedAppDelegate: null
106119
107120 property real oldInverseProgress: 0
@@ -110,8 +123,8 @@ Rectangle {
110123 onFocusedAppIdChanged: focusedAppDelegate = spreadRepeater.itemAt(0);
111124
112125 function indexOf(appId) {
113− for (var i = 0; i < ApplicationManager.count; i++) {
114− if (ApplicationManager.get(i).appId == appId) {
126+ for (var i = 0; i < applicationManager.count; i++) {
127+ if (applicationManager.get(i).appId == appId) {
115128 return i;
116129 }
117130 }
@@ -197,10 +210,17 @@ Rectangle {
197210 // Add 1 pixel to make sure we definitely hit positionMarker4 even with rounding errors of the animation.
198211 snapAnimation.targetContentX = width * positionMarker4 + 1 - shift;
199212 snapAnimation.start();
213+ root.opened();
200214 }
201215 }
202216 function snapTo(index) {
203− if (ApplicationManager.count <= index) {
217+ if (!root.altTabEnabled) {
218+ // Reset to start instead
219+ snapAnimation.targetContentX = -shift;
220+ snapAnimation.start();
221+ return;
222+ }
223+ if (applicationManager.count <= index) {
204224 // In case we're trying to snap to some non existing app, lets snap back to the first one
205225 index = 0;
206226 }
@@ -215,7 +235,7 @@ Rectangle {
215235 snapAnimation.start();
216236 }
217237
218− // In case the ApplicationManager already holds an app when starting up we're missing animations
238+ // In case the applicationManager already holds an app when starting up we're missing animations
219239 // Make sure we end up in the same state
220240 Component.onCompleted: {
221241 spreadView.contentX = -spreadView.shift
@@ -235,7 +255,7 @@ Rectangle {
235255 ScriptAction {
236256 script: {
237257 if (spreadView.selectedIndex >= 0) {
238− ApplicationManager.focusApplication(ApplicationManager.get(spreadView.selectedIndex).appId);
258+ applicationManager.focusApplication(applicationManager.get(spreadView.selectedIndex).appId);
239259
240260 spreadView.selectedIndex = -1;
241261 spreadView.phase = 0;
@@ -250,7 +270,7 @@ Rectangle {
250270 // This width controls how much the spread can be flicked left/right. It's composed of:
251271 // tileDistance * app count (with a minimum of 3 apps, in order to also allow moving 1 and 2 apps a bit)
252272 // + some constant value (still scales with the screen width) which looks good and somewhat fills the screen
253− width: Math.max(3, ApplicationManager.count) * spreadView.tileDistance + (spreadView.width - spreadView.tileDistance) * 1.5
273+ width: Math.max(3, applicationManager.count) * spreadView.tileDistance + (spreadView.width - spreadView.tileDistance) * 1.5
254274 height: parent.height
255275 Behavior on width {
256276 enabled: spreadView.closingIndex >= 0
@@ -265,20 +285,22 @@ Rectangle {
265285 x: spreadView.contentX
266286
267287 onClicked: {
268− spreadView.snapTo(0);
288+ if (root.altTabEnabled) {
289+ spreadView.snapTo(0);
290+ }
269291 }
270292
271293 Repeater {
272294 id: spreadRepeater
273295 objectName: "spreadRepeater"
274− model: ApplicationManager
296+ model: applicationManager
275297 delegate: TransformedSpreadDelegate {
276298 id: appDelegate
277299 objectName: "appDelegate" + index
278300 startAngle: 45
279301 endAngle: 5
280− startScale: 1.1
281− endScale: 0.7
302+ startScale: root.startScale
303+ endScale: root.endScale
282304 startDistance: spreadView.tileDistance
283305 endDistance: units.gu(.5)
284306 width: spreadView.width
@@ -286,11 +308,12 @@ Rectangle {
286308 selected: spreadView.selectedIndex == index
287309 otherSelected: spreadView.selectedIndex >= 0 && !selected
288310 interactive: !spreadView.interactive && spreadView.phase === 0
289− && spreadView.shiftedContentX === 0 && root.interactive && index === 0
290− swipeToCloseEnabled: spreadView.interactive && !snapAnimation.running
311+ && spreadView.shiftedContentX === 0 && root.interactive && isFocused
312+ swipeToCloseEnabled: spreadView.interactive && root.interactive && !snapAnimation.running
291313 maximizedAppTopMargin: root.maximizedAppTopMargin
292314 dropShadow: spreadView.active ||
293315 (priv.focusedAppDelegate && priv.focusedAppDelegate.x !== 0)
316+ focusFirstApp: root.focusFirstApp
294317
295318 readonly property bool isDash: model.appId == "unity8-dash"
296319
@@ -298,7 +321,7 @@ Rectangle {
298321
299322 x: {
300323 // focused app is always positioned at 0 except when following left edge drag
301− if (index == 0) {
324+ if (isFocused) {
302325 if (!isDash && root.inverseProgress > 0) {
303326 return root.inverseProgress;
304327 }
@@ -309,10 +332,10 @@ Rectangle {
309332 }
310333
311334 // Otherwise line up for the spread
312− return spreadView.width + (index - 1) * spreadView.tileDistance;
335+ return spreadView.width + spreadIndex * spreadView.tileDistance;
313336 }
314337
315− application: ApplicationManager.get(index)
338+ application: applicationManager.get(index)
316339 closeable: !isDash
317340
318341 property real behavioredIndex: index
@@ -350,7 +373,7 @@ Rectangle {
350373 progress: {
351374 var tileProgress = (spreadView.shiftedContentX - behavioredIndex * spreadView.tileDistance) / spreadView.width;
352375 // Tile 1 needs to move directly from the beginning...
353− if (behavioredIndex == 1 && spreadView.phase < 2) {
376+ if (root.focusFirstApp && behavioredIndex == 1 && spreadView.phase < 2) {
354377 tileProgress += spreadView.tileDistance / spreadView.width;
355378 }
356379 // Limiting progress to ~0 and 1.7 to avoid binding calculations when tiles are not
@@ -365,7 +388,7 @@ Rectangle {
365388
366389 // This mostly is the same as progress, just adds the snapping to phase 1 for tiles 0 and 1
367390 animatedProgress: {
368− if (spreadView.phase == 0 && index < 2) {
391+ if (spreadView.phase == 0 && index <= priv.firstSpreadIndex) {
369392 if (progress < spreadView.positionMarker1) {
370393 return progress;
371394 } else if (progress < spreadView.positionMarker1 + 0.05){
@@ -390,11 +413,11 @@ Rectangle {
390413 }
391414
392415 onClicked: {
393− if (spreadView.phase == 2) {
394− if (ApplicationManager.focusedApplicationId == ApplicationManager.get(index).appId) {
416+ if (root.altTabEnabled && spreadView.phase == 2) {
417+ if (applicationManager.focusedApplicationId == applicationManager.get(index).appId) {
395418 spreadView.snapTo(index);
396419 } else {
397− ApplicationManager.requestFocusApplication(ApplicationManager.get(index).appId);
420+ applicationManager.requestFocusApplication(applicationManager.get(index).appId);
398421 }
399422 }
400423 }
@@ -409,7 +432,7 @@ Rectangle {
409432
410433 onClosed: {
411434 spreadView.closingIndex = index;
412− ApplicationManager.stopApplication(ApplicationManager.get(index).appId);
435+ applicationManager.stopApplication(applicationManager.get(index).appId);
413436 }
414437 }
415438 }