aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Vlad <marius.vlad@collabora.com>2020-01-10 01:51:35 +0200
committerMarius Vlad <marius.vlad@collabora.com>2020-01-22 12:24:07 +0200
commitfd5d8797728f8efc8368d4c685839e79bbf65bba (patch)
treea70211136538e1810852c9eb7b1fce1d9eba69b4
parentf3e7aacc7ea1d155fa13cc575150ed010a32501f (diff)
qml/ShortcutArea: Add support for starting apps from QML
Signed-off-by: Marius Vlad <marius.vlad@collabora.com> Change-Id: I9cb9c0566ded43a1511b7d16bbfe5344dfab45f7
-rw-r--r--homescreen/qml/ShortcutArea.qml64
1 files changed, 60 insertions, 4 deletions
diff --git a/homescreen/qml/ShortcutArea.qml b/homescreen/qml/ShortcutArea.qml
index d470231..535e6b2 100644
--- a/homescreen/qml/ShortcutArea.qml
+++ b/homescreen/qml/ShortcutArea.qml
@@ -47,7 +47,44 @@ Item {
}
}
- property int pid: -1
+ property int pid: -1
+
+ property string current_appid: ''
+ property variant current_window: {}
+
+ property variant applications: {'' : -1}
+
+ function find_app(app, apps) {
+ for (var x in apps) {
+
+ if (apps[x] == -1)
+ continue
+
+ if (x === app)
+ return true
+ }
+ return false
+ }
+
+ function set_current_window_app(appid, window) {
+ current_appid = appid
+ current_window = window
+ }
+
+
+ Timer {
+ id: timer
+ interval: 500
+ running: false
+ repeat: false
+ onTriggered: {
+ if (current_appid != '' && current_window != undefined) {
+ console.log("Timer expired, switching to " + current_appid)
+ shell.activate_app(current_window, current_appid)
+ }
+ }
+ }
+
RowLayout {
anchors.fill: parent
@@ -59,9 +96,28 @@ Item {
Layout.fillHeight: true
name: model.name
active: model.name === launcher.current
- onClicked: {
- shell.activate_app(Window.window, model.appid)
- }
+
+ onClicked: {
+ // if timer still running ignore
+ if (timer.running) {
+ console.log("Timer still running")
+ return
+ }
+
+ // find the app before trying to start
+ if (find_app(model.application, applications)) {
+ console.log("application " + model.appid + "already started. Just switching")
+ shell.activate_app(Window.window, model.appid)
+ return
+ }
+
+ pid = launcher.launch(model.application)
+ if (pid > 0) {
+ set_current_window_app(model.appid, Window.window)
+ applications[model.application] = pid
+ timer.running = true
+ }
+ }
}
}
}