summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Vlad <marius.vlad@collabora.com>2020-04-09 17:23:47 +0300
committerMarius Vlad <marius.vlad@collabora.com>2020-04-21 22:42:01 +0300
commit9e76cf1b66b40a0e502c667dbbf53164261956b5 (patch)
tree975eac2f31516b63374dd8652da04341f58bd7b7
parentd53b7647a82fb3a8e42c191e2a325767e75a9062 (diff)
onscreenapp, ontestapp: Initial conversion to agl-compositor
Add agl-shell-desktop protocol and the ability to launch apps. Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
-rw-r--r--app/eventhandler.cpp27
-rw-r--r--app/eventhandler.h7
-rw-r--r--app/main.cpp9
-rw-r--r--package/config.xml1
-rw-r--r--pws/launcher.cpp106
-rw-r--r--pws/launcher.h70
-rw-r--r--pws/pws.cpp501
-rw-r--r--pws/pws.h99
-rw-r--r--pws/pws.pri16
-rw-r--r--pws/pws.pro23
-rw-r--r--sample/app/app.pro11
-rw-r--r--sample/app/eventhandler.cpp212
-rw-r--r--sample/app/eventhandler.h19
-rw-r--r--sample/app/main.cpp12
-rw-r--r--sample/app/main.qml104
-rw-r--r--sample/app/protocol/agl-shell-desktop.xml113
-rw-r--r--sample/package/config.xml4
-rw-r--r--sample/sample.pro4
18 files changed, 1224 insertions, 114 deletions
diff --git a/app/eventhandler.cpp b/app/eventhandler.cpp
index ff8617d..9ffd6bb 100644
--- a/app/eventhandler.cpp
+++ b/app/eventhandler.cpp
@@ -39,24 +39,19 @@ void* EventHandler::myThis = 0;
EventHandler::EventHandler(QObject *parent) :
QObject(parent),
- mp_hs(nullptr),
- mp_wm(nullptr),
m_dsp_sts(false)
{
}
EventHandler::~EventHandler()
{
- if (mp_hs != nullptr) {
- delete mp_hs;
- }
- if (mp_wm != nullptr) {
- delete mp_wm;
- }
}
void EventHandler::init(int port, const char *token)
{
+ (void) port;
+ (void) token;
+#if 0
myThis = this;
mp_wm = new QLibWindowmanager();
mp_wm->init(port, token);
@@ -147,8 +142,10 @@ void EventHandler::init(int port, const char *token)
});
HMI_DEBUG(APP_ID, "LayoutHander::init() finished.");
+#endif
}
+#if 0
void EventHandler::onRep_static(struct json_object* reply_contents)
{
static_cast<EventHandler*>(EventHandler::myThis)->onRep(reply_contents);
@@ -159,15 +156,21 @@ void EventHandler::onRep(struct json_object* reply_contents)
const char* str = json_object_to_json_string(reply_contents);
HMI_DEBUG(APP_ID, "EventHandler::onReply %s", str);
}
+#endif
void EventHandler::activateWindow(const char *role, const char *area)
{
+#if 0
HMI_DEBUG(APP_ID, "EventHandler::activateWindow()");
mp_wm->activateWindow(role, area);
+#endif
+ fprintf(stdout, "EventHandler::activateWindow() role %s, area %s\n",
+ role, area);
}
void EventHandler::deactivateWindow()
{
+#if 0
HMI_DEBUG(APP_ID, "EventHandler::deactivateWindow()");
if(getDisplayStatus() == SWAPPING) {
setDisplayStatus(SHOWING);
@@ -179,10 +182,15 @@ void EventHandler::deactivateWindow()
this->setDisplayStatus(HIDING);
mp_wm->deactivateWindow(_myrole);
}
+#endif
+ int display_status = getDisplayStatus();
+ fprintf(stdout, "EventHandler::deactivateWindow(), "
+ "display_status %d\n", display_status);
}
void EventHandler::onScreenReply(const QString &ons_title, const QString &btn_name)
{
+#if 0
HMI_DEBUG(APP_ID, "ons_title=%s btn_name=%s", ons_title.toStdString().c_str(), btn_name.toStdString().c_str());
emit this->hideOnScreen();
@@ -190,4 +198,7 @@ void EventHandler::onScreenReply(const QString &ons_title, const QString &btn_na
json_object_object_add(j_param, _onscreen_title, json_object_new_string(ons_title.toStdString().c_str()));
json_object_object_add(j_param, _button_name, json_object_new_string(btn_name.toStdString().c_str()));
mp_hs->replyShowWindow(m_dsp.first.toStdString().c_str(), j_param);
+#endif
+ fprintf(stdout, "EventHandler::onScreenReply with ons_title %s, btn_name %s\n",
+ ons_title.toStdString().c_str(), btn_name.toStdString().c_str());
}
diff --git a/app/eventhandler.h b/app/eventhandler.h
index bb75d9b..1fe910b 100644
--- a/app/eventhandler.h
+++ b/app/eventhandler.h
@@ -21,8 +21,6 @@
#include <string>
#include <QVariant>
#include <QPair>
-#include <libhomescreen.hpp>
-#include <qlibwindowmanager.h>
#include "hmi-debug.h"
#define APP_ID "onscreenapp"
@@ -35,14 +33,13 @@ class EventHandler : public QObject
public:
explicit EventHandler(QObject *parent = 0);
~EventHandler();
+
EventHandler(const EventHandler&) = delete;
EventHandler& operator=(const EventHandler&) = delete;
void init(int port, const char* token);
- void onRep(struct json_object* reply_contents);
static void* myThis;
- static void onRep_static(struct json_object* reply_contents);
Q_INVOKABLE void deactivateWindow();
Q_INVOKABLE void onScreenReply(const QString &ons_title, const QString &btn_name);
@@ -63,8 +60,6 @@ private:
void setDisplayStatus(int sts) {m_dsp_sts = sts;}
void activateWindow(const char *role, const char *area = "normal.full");
- LibHomeScreen *mp_hs;
- QLibWindowmanager* mp_wm;
QPair<QString, QString> m_req, m_dsp;
int m_dsp_sts = HIDING;
};
diff --git a/app/main.cpp b/app/main.cpp
index 007711c..381b9a2 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -31,12 +31,18 @@ int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
+#if 0
QCoreApplication::setOrganizationDomain("LinuxFoundation");
QCoreApplication::setOrganizationName("AutomotiveGradeLinux");
QCoreApplication::setApplicationName("Onscreenapp");
QCoreApplication::setApplicationVersion("0.1.0");
+#endif
- QQuickStyle::setStyle("AGL");
+ // this is necessary to identify app, setApplicationName is only for the
+ // title
+ app.setDesktopFileName(APP_ID);
+
+ //QQuickStyle::setStyle("AGL");
QCommandLineParser parser;
parser.addPositionalArgument("port", app.translate("main", "port for binding"));
@@ -69,6 +75,7 @@ int main(int argc, char *argv[])
QObject *root = engine.rootObjects().first();
QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
+
QObject::connect(eventHandler, SIGNAL(updateModel(QVariant)), window, SLOT(setOnScreenModel(QVariant)));
QObject::connect(eventHandler, SIGNAL(showOnScreen()), window, SLOT(showOnScreen()));
QObject::connect(eventHandler, SIGNAL(hideOnScreen()), window, SLOT(hideOnScreen()));
diff --git a/package/config.xml b/package/config.xml
index 7b151a3..962507e 100644
--- a/package/config.xml
+++ b/package/config.xml
@@ -13,5 +13,6 @@
<feature name="urn:AGL:widget:required-permission">
<param name="urn:AGL:permission::public:no-htdocs" value="required" />
<param name="urn:AGL:permission::system:run-by-default" value="required"/>
+ <param name="urn:AGL:permission::public:display" value="required" />
</feature>
</widget>
diff --git a/pws/launcher.cpp b/pws/launcher.cpp
new file mode 100644
index 0000000..bbd86df
--- /dev/null
+++ b/pws/launcher.cpp
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2020 Collabora Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <json-c/json.h>
+
+#include "launcher.h"
+#include "pws.h"
+
+int
+Launcher::setup_pws_connection(void)
+{
+ pws = pws_data_source_init(afm_sock_name.toStdString().c_str());
+ if (!pws)
+ return -1;
+
+ connection_set = true;
+ return 0;
+}
+
+bool
+Launcher::connection_is_set(void)
+{
+ return connection_set;
+}
+
+int
+Launcher::start(const QString &app)
+{
+ int rid = -1;
+
+ if (!connection_set)
+ return rid;
+
+ rid = pws_start_process(pws, app.toStdString().c_str());
+ if (rid > 0)
+ applications.insert(app, rid);
+
+ return rid;
+}
+
+bool
+Launcher::terminate(const QString &app)
+{
+ if (!connection_set)
+ return -1;
+
+ if (pws_stop_process(pws, app.toStdString().c_str()))
+ return true;
+
+ return false;
+}
+
+bool
+Launcher::is_running(const QString &app)
+{
+ int rid = -1;
+
+ if (!connection_set)
+ return false;
+
+ rid = pws_check_process_is_running(pws, app.toStdString().c_str());
+ /* remove it from QHash if it was there and current no longer shows up */
+ if (rid > 0) {
+ return true;
+ } else {
+ if (applications.contains(app))
+ applications.remove(app);
+ }
+
+ return false;
+}
+
+size_t
+Launcher::get_list_runnables(QString *qstr)
+{
+ size_t items = 0;
+ struct json_object *json;
+
+ if (!connection_set)
+ return false;
+
+ items = pws_get_list_runnables(pws, &json);
+ if (json)
+ *qstr = QString(json_object_to_json_string(json));
+ else
+ *qstr = nullptr;
+
+ /* necessary as pws_get_list_runnables won't free() the json reply on
+ * its own */
+ pws_data_source_reply_destroy(pws);
+
+ return items;
+}
diff --git a/pws/launcher.h b/pws/launcher.h
new file mode 100644
index 0000000..62f5040
--- /dev/null
+++ b/pws/launcher.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2020 Collabora Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LAUNCHER_H
+#define LAUNCHER_H
+
+#include <QObject>
+#include <QString>
+#include <QScreen>
+#include <QWindow>
+#include <QHash>
+
+#include <memory>
+
+#include "pws.h"
+
+class Launcher : public QObject
+{
+ Q_OBJECT
+
+public:
+ Launcher(const QString &sock_name, QObject *parent = nullptr) :
+ QObject(parent), afm_sock_name(sock_name)
+ {
+ pws = nullptr;
+ connection_set = false;
+ }
+
+ ~Launcher()
+ {
+ destroy();
+ }
+
+ // call this before to any start-up
+ int setup_pws_connection(void);
+ bool connection_is_set(void);
+
+public slots:
+ int start(const QString &app);
+ bool terminate(const QString &app);
+ bool is_running(const QString &app);
+ size_t get_list_runnables(QString *data);
+
+private:
+ struct pws_data_source *pws;
+ bool connection_set;
+ QString afm_sock_name;
+
+ QHash<QString, int> applications; // stores the apps started
+
+ void destroy(void)
+ {
+ pws_data_source_destroy(pws);
+ }
+};
+
+#endif // LAUNCHER_H
diff --git a/pws/pws.cpp b/pws/pws.cpp
new file mode 100644
index 0000000..78796cb
--- /dev/null
+++ b/pws/pws.cpp
@@ -0,0 +1,501 @@
+/*
+ * Copyright (c) 2020 Collabora Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <cstdio>
+#include <cstdlib>
+
+#include <systemd/sd-event.h>
+#include <json-c/json.h>
+#include <assert.h>
+#include "pws.h"
+
+#if !defined(JSON_C_TO_STRING_NOSLASHESCAPE)
+#define JSON_C_TO_STRING_NOSLASHESCAPE 0
+#endif
+
+#define PWS_DEBUG
+
+static void
+idle(struct pws_data_source *pws_d_source)
+{
+ struct sd_event *loop = pws_d_source->loop;
+
+ for (;;) {
+ if (!pws_d_source->callcount)
+ break;
+
+ sd_event_run(loop, TIMEOUT_SD_LOOP);
+ }
+}
+
+static void
+dec_callcount(struct pws_data_source *pws_d_source)
+{
+ if (!pws_d_source)
+ return;
+
+ pws_d_source->callcount--;
+}
+
+static void
+inc_callcount(struct pws_data_source *pws_d_source)
+{
+ if (!pws_d_source)
+ return;
+
+ pws_d_source->callcount++;
+}
+
+static void
+on_pws_reply(void *closure, void *request, struct json_object *result,
+ const char *error, const char *info)
+{
+ struct pws_data_source *pws_d_source =
+ static_cast<struct pws_data_source *>(closure);
+
+ assert(pws_d_source != NULL);
+
+#ifdef PWS_DEBUG
+ fprintf(stdout, "ON-REPLY %s: %s %s\n%s\n", (char*) request, error,
+ info ?: "",
+ json_object_to_json_string_ext(result,
+ JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_NOSLASHESCAPE));
+
+ fflush(stdout);
+#endif
+
+ /* in case of an error do not set the reply */
+ if (!info && !error) {
+ /* should be cleaned-up after a proper request */
+ assert(pws_d_source->reply_valid == false);
+
+ pws_d_source->reply = result;
+ pws_d_source->reply_valid = true;
+ } else {
+ fprintf(stdout, "ON-REPLY: err: %s, request: %s, info %s\n",
+ error, (char *) request, info);
+ }
+
+ /* necessary when getting the reply to exit idle() */
+ dec_callcount(pws_d_source);
+}
+
+static void
+on_pws_event_create(void *closure, uint16_t event_id, const char *event_name)
+{
+ struct pws_data_source *pws_d_source =
+ static_cast<struct pws_data_source *>(closure);
+ (void) pws_d_source;
+
+#ifdef PWS_DEBUG
+ fprintf(stdout, "ON-EVENT-CREATE: [%d:%s]\n", event_id, event_name);
+ fflush(stdout);
+#endif
+}
+
+static void
+on_pws_event_remove(void *closure, uint16_t event_id)
+{
+ struct pws_data_source *pws_d_source =
+ static_cast<struct pws_data_source *>(closure);
+
+ (void) pws_d_source;
+#ifdef PWS_DEBUG
+ fprintf(stdout, "ON-EVENT-REMOVE: [%d]\n", event_id);
+ fflush(stdout);
+#endif
+}
+
+static void
+on_pws_event_subscribe(void *closure, void *request, uint16_t event_id)
+{
+ struct pws_data_source *pws_d_source =
+ static_cast<struct pws_data_source *>(closure);
+
+ (void) pws_d_source;
+#ifdef PWS_DEBUG
+ fprintf(stdout, "ON-EVENT-SUBSCRIBE %s: [%d]\n", (char*)request, event_id);
+ fflush(stdout);
+#endif
+}
+
+static void
+on_pws_event_unsubscribe(void *closure, void *request, uint16_t event_id)
+{
+ struct pws_data_source *pws_d_source =
+ static_cast<struct pws_data_source *>(closure);
+
+ (void) pws_d_source;
+#ifdef PWS_DEBUG
+ fprintf(stdout, "ON-EVENT-UNSUBSCRIBE %s: [%d]\n", (char*)request, event_id);
+ fflush(stdout);
+#endif
+}
+
+static void
+on_pws_event_push(void *closure, uint16_t event_id, struct json_object *data)
+{
+ struct pws_data_source *pws_d_source =
+ static_cast<struct pws_data_source *>(closure);
+
+ (void) pws_d_source;
+#ifdef PWS_DEBUG
+ fprintf(stdout, "ON-EVENT-PUSH: [%d]\n%s\n",
+ event_id,
+ json_object_to_json_string_ext(data, JSON_C_TO_STRING_NOSLASHESCAPE));
+ fprintf(stdout, "ON-EVENT-PUSH: [%d]\n%s\n",
+ event_id,
+ json_object_to_json_string_ext(data, JSON_C_TO_STRING_PRETTY |
+ JSON_C_TO_STRING_NOSLASHESCAPE));
+
+ fflush(stdout);
+#endif
+}
+
+static void
+on_pws_event_broadcast(void *closure, const char *event_name,
+ struct json_object *data,
+ const afb_proto_ws_uuid_t uuid, uint8_t hop)
+{
+ struct pws_data_source *pws_d_source =
+ static_cast<struct pws_data_source *>(closure);
+
+ (void) pws_d_source;
+ (void) uuid;
+ (void) hop;
+
+#ifdef PWS_DEBUG
+ fprintf(stdout, "ON-EVENT-BROADCAST: [%s]\n%s\n",
+ event_name,
+ json_object_to_json_string_ext(data, JSON_C_TO_STRING_NOSLASHESCAPE));
+ fprintf(stdout, "ON-EVENT-BROADCAST: [%s]\n%s\n",
+ event_name,
+ json_object_to_json_string_ext(data, JSON_C_TO_STRING_PRETTY |
+ JSON_C_TO_STRING_NOSLASHESCAPE));
+ fflush(stdout);
+#endif
+}
+
+/* called when pws hangsup */
+static void
+on_pws_hangup(void *closure)
+{
+ struct pws_data_source *pws_d_source =
+ static_cast<struct pws_data_source *>(closure);
+
+ (void) pws_d_source;
+#ifdef PWS_DEBUG
+ printf("ON-HANGUP\n");
+ fflush(stdout);
+#endif
+
+ exit(EXIT_FAILURE);
+}
+
+/* makes a call */
+static int
+pws_call(const char *verb, const char *object,
+ struct pws_data_source *pws_d_source)
+{
+ char *key;
+ struct json_object *o;
+ enum json_tokener_error jerr;
+
+ struct afb_proto_ws *pws = pws_d_source->pws;
+ int rc;
+
+ assert(pws != NULL);
+
+ /* allocates an id for the request */
+ rc = asprintf(&key, "%d:%s", ++pws_d_source->num_id, verb);
+ if (rc < 0)
+ return -1;
+
+ /* echo the command if asked */
+ fprintf(stdout, "SEND-CALL: %s %s\n", verb, object?:"null");
+
+ inc_callcount(pws_d_source);
+
+ if (object == NULL || object[0] == 0) {
+ o = NULL;
+ } else {
+ o = json_tokener_parse_verbose(object, &jerr);
+ if (jerr != json_tokener_success)
+ o = json_object_new_string(object);
+ }
+
+ /* send the request */
+ rc = afb_proto_ws_client_call(pws, verb, o, 0, 0, key, NULL);
+ json_object_put(o);
+ if (rc < 0) {
+ fprintf(stderr, "calling %s(%s) failed: %m\n", verb, object ?: "");
+ dec_callcount(pws_d_source);
+ free(key);
+ return -1;
+ }
+
+ free(key);
+ return 0;
+}
+
+/* the callback interface for pws */
+static struct afb_proto_ws_client_itf pws_itf = {
+ .on_reply = on_pws_reply,
+ .on_event_create = on_pws_event_create,
+ .on_event_remove = on_pws_event_remove,
+ .on_event_subscribe = on_pws_event_subscribe,
+ .on_event_unsubscribe = on_pws_event_unsubscribe,
+ .on_event_push = on_pws_event_push,
+ .on_event_broadcast = on_pws_event_broadcast,
+};
+
+struct pws_data_source *
+pws_data_source_init(const char *connect_to)
+{
+ struct afb_proto_ws *pws;
+ struct sd_event *sd_loop;
+ struct pws_data_source *pws_d_source = nullptr;
+
+ if (!connect_to) {
+ fprintf(stderr, "Failed to get a connect_to\n");
+ return nullptr;
+ }
+
+ if (sd_event_default(&sd_loop) < 0) {
+ fprintf(stderr, "Failed to get a default event\n");
+ return nullptr;
+ }
+
+ pws_d_source =
+ static_cast<struct pws_data_source *>(calloc(1, sizeof(struct pws_data_source)));
+
+ if (!pws_d_source) {
+ fprintf(stderr, "Failed to allocate memory\n");
+ return nullptr;
+ }
+
+ pws = afb_ws_client_connect_api(sd_loop, connect_to,
+ &pws_itf, pws_d_source);
+ if (!pws) {
+ fprintf(stderr, "Failed to create a afb_proto_ws\n");
+ return nullptr;
+ }
+
+ afb_proto_ws_on_hangup(pws, on_pws_hangup);
+
+ pws_d_source->pws = pws;
+ pws_d_source->loop = sd_loop;
+ pws_d_source->callcount = 0;
+ pws_d_source->num_id = 0;
+
+ pws_d_source->reply = nullptr;
+ pws_d_source->reply_valid = false;
+
+ return pws_d_source;
+}
+
+static int
+pws_do_call(struct pws_data_source *pws_d_source,
+ const char *verb, const char *object)
+{
+ if (!verb || !object || !pws_d_source)
+ return -1;
+
+ if (pws_call(verb, object, pws_d_source) < 0)
+ return -1;
+
+ idle(pws_d_source);
+
+ return 0;
+}
+
+void
+pws_data_source_destroy(struct pws_data_source *pws_d_source)
+{
+ assert(pws_d_source != nullptr);
+
+ sd_event_unref(pws_d_source->loop);
+ free(pws_d_source);
+}
+
+void
+pws_data_source_reply_destroy(struct pws_data_source *pws)
+{
+ assert(pws->reply_valid == true);
+ pws->reply_valid = false;
+ free(pws->reply);
+}
+
+
+int
+pws_start_process(struct pws_data_source *pws, const char *afm_name)
+{
+ int rid = -1;
+
+ fprintf(stdout, "pws_start_process() with afm_name %s\n", afm_name);
+ if (pws_do_call(pws, "start", afm_name) < 0)
+ return -1;
+
+ if (pws->reply_valid) {
+ struct json_object *result = pws->reply;
+
+ rid = json_object_get_int(result);
+ fprintf(stdout, "ON-REPLY %s\n",
+ json_object_to_json_string_ext(result,
+ JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_NOSLASHESCAPE));
+
+ pws_data_source_reply_destroy(pws);
+ }
+
+ return rid;
+}
+
+bool
+pws_stop_process(struct pws_data_source *pws, const char *afm_name)
+{
+ bool term = false;
+ if (pws_do_call(pws, "terminate", afm_name) < 0)
+ return term;
+
+ if (pws->reply_valid) {
+ struct json_object *result = pws->reply;
+
+ term = json_object_get_boolean(result);
+#ifdef PWS_DEBUG
+ fprintf(stdout, "ON-REPLY %s\n",
+ json_object_to_json_string_ext(result,
+ JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_NOSLASHESCAPE));
+#endif
+ pws_data_source_reply_destroy(pws);
+ }
+
+ return term;
+}
+
+
+int
+pws_check_process_is_running(struct pws_data_source *pws, const char *afm_name)
+{
+ int rid = -1;
+
+ if (pws_do_call(pws, "state", afm_name) < 0)
+ return rid;
+
+ if (pws->reply_valid) {
+ struct json_object *result = pws->reply;
+ struct json_object *obj;
+
+ json_object_object_get_ex(result, "runid", &obj);
+ if (obj) {
+ rid = json_object_get_int(obj);
+ fprintf(stdout, "Found rid %d\n", rid);
+ }
+#ifdef PWS_DEBUG
+ fprintf(stdout, "ON-REPLY: %s\n",
+ json_object_to_json_string_ext(result,
+ JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_NOSLASHESCAPE));
+#endif
+ pws_data_source_reply_destroy(pws);
+ }
+
+ return rid;
+}
+
+size_t
+pws_list_runners(struct pws_data_source *pws)
+{
+ size_t items = 0;
+ if (pws_do_call(pws, "runners", "true") < 0)
+ return items;
+
+ if (pws->reply_valid) {
+ struct json_object *result = pws->reply;
+
+ /* at least one is running */
+ items = json_object_array_length(result);
+
+#ifdef PWS_DEBUG
+ fprintf(stdout, "found %ld items\n", items);
+ fprintf(stdout, "ON-REPLY: %s\n",
+ json_object_to_json_string_ext(result,
+ JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_NOSLASHESCAPE));
+#endif
+ pws_data_source_reply_destroy(pws);
+ }
+
+ return items;
+}
+
+size_t
+pws_list_runnables(struct pws_data_source *pws)
+{
+ size_t items = 0;
+ if (pws_do_call(pws, "runnables", "true") < 0)
+ return items;
+
+ if (pws->reply_valid) {
+ struct json_object *result = pws->reply;
+
+ items = json_object_array_length(result);
+#ifdef PWS_DEBUG
+ fprintf(stdout, "found %ld items\n", items);
+ fprintf(stdout, "ON-REPLY: %s\n",
+ json_object_to_json_string_ext(result,
+ JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_NOSLASHESCAPE));
+#endif
+ pws_data_source_reply_destroy(pws);
+ }
+
+ return items;
+}
+
+/*
+ * need to free(json_string) once you're done with it
+ *
+ * call pws_data_source_reply_destroy(pws) once you're done with it.
+ */
+size_t
+pws_get_list_runnables(struct pws_data_source *pws, struct json_object **json)
+{
+ size_t items = 0;
+ if (pws_do_call(pws, "runnables", "true") < 0)
+ return items;
+
+ fprintf(stdout, "pws_get_list_runnables()\n");
+
+ if (pws->reply_valid) {
+ struct json_object *result = pws->reply;
+
+ items = json_object_array_length(result);
+#ifdef PWS_DEBUG
+ fprintf(stdout, "found %ld items\n", items);
+ fprintf(stdout, "ON-REPLY: %s\n",
+ json_object_to_json_string_ext(result,
+ JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_NOSLASHESCAPE));
+#endif
+ if (items == 0) {
+ fprintf(stdout, "pws_get_list_runnables() turn items %ld, bails sooner\n", items);
+ *json = NULL;
+ return items;
+ }
+
+ fprintf(stdout, "pws_get_list_runnables() json reply is set\n");
+ *json = result;
+ }
+
+ fprintf(stdout, "pws_get_list_runnables() turn items %ld\n", items);
+ return items;
+}
diff --git a/pws/pws.h b/pws/pws.h
new file mode 100644
index 0000000..ed5a1f5
--- /dev/null
+++ b/pws/pws.h
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2020 Collabora Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PWS_HEADER_H
+#define PWS_HEADER_H
+
+#include <systemd/sd-event.h>
+
+/* linker will complain it can't find them and given they're only for C */
+extern "C" {
+#include "afb/afb-ws-client.h"
+#include "afb/afb-proto-ws.h"
+}
+
+#define TIMEOUT_SD_LOOP 30000000
+
+struct pws_data_source_json_reply;
+
+struct pws_data_source {
+ struct sd_event *loop;
+ struct afb_proto_ws *pws;
+ int callcount;
+ int num_id; /* key id */
+
+ struct json_object *reply;
+ bool reply_valid;
+};
+
+void
+pws_data_source_reply_destroy(struct pws_data_source *pws);
+
+/* inits a connection to connect_to
+ *
+ */
+struct pws_data_source *
+pws_data_source_init(const char *connect_to);
+
+/* destroys connection init'ed by pws_data_source_init
+ */
+void
+pws_data_source_destroy(struct pws_data_source *pws);
+
+
+/*
+ * starts the app by @afm_name
+ *
+ * returns 0 in case of success, negative in case of failure
+ *
+ */
+int
+pws_start_process(struct pws_data_source *pws, const char *afm_name);
+
+/*
+ * terminates the app by @afm_name
+ *
+ * returns true case of success, false in case of failure
+ */
+bool
+pws_stop_process(struct pws_data_source *pws, const char *afm_name);
+
+/* returns pid or -1 in case the @afm_name is not running
+ *
+ */
+int
+pws_check_process_is_running(struct pws_data_source *pws, const char *afm_name);
+
+/* returns #no of (current) active, running applications
+ *
+ * (prints) as well
+ */
+size_t
+pws_list_runners(struct pws_data_source *pws);
+
+/* returns #no of (all) applications
+ *
+ * (prints) as well
+ */
+size_t
+pws_list_runnables(struct pws_data_source *pws);
+
+/*
+ */
+size_t
+pws_get_list_runnables(struct pws_data_source *pws, struct json_object **json_obj);
+
+#endif
diff --git a/pws/pws.pri b/pws/pws.pri
new file mode 100644
index 0000000..7a60101
--- /dev/null
+++ b/pws/pws.pri
@@ -0,0 +1,16 @@
+# Copyright (C) 2019 Collabora Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+INCLUDEPATH += $$PWD $$OUT_PWD/../../pws/
+LIBS += -L$$OUT_PWD/../../pws/ -lpws -lafbwsc -lsystemd -ljson-c
diff --git a/pws/pws.pro b/pws/pws.pro
new file mode 100644
index 0000000..e661adb
--- /dev/null
+++ b/pws/pws.pro
@@ -0,0 +1,23 @@
+# Copyright (C) 2019 Collabora Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+TEMPLATE = lib
+TARGET = pws
+CONFIG += staticlib
+PKGCONFIG += libafbwsc
+
+HEADERS += pws.h launcher.h
+
+SOURCES += pws.cpp launcher.cpp
+
diff --git a/sample/app/app.pro b/sample/app/app.pro
index c72fd28..f6f5b82 100644
--- a/sample/app/app.pro
+++ b/sample/app/app.pro
@@ -14,12 +14,15 @@
# limitations under the License.
TARGET = onstestapp
-QT = quick quickcontrols2 qml
+QT = quick quickcontrols2 qml gui-private
-CONFIG += c++11 link_pkgconfig
-PKGCONFIG += qlibwindowmanager qlibhomescreen
+CONFIG += c++11 link_pkgconfig wayland-scanner pkgdatadir
+#PKGCONFIG += qlibwindowmanager qlibhomescreen
+PKGCONFIG += wayland-client
DESTDIR = $${OUT_PWD}/../package/root/bin
+include(../../pws/pws.pri)
+
SOURCES = main.cpp \
eventhandler.cpp
@@ -31,3 +34,5 @@ HEADERS += \
LIBS += -ljson-c
+WAYLANDCLIENTSOURCES += \
+ protocol/agl-shell-desktop.xml
diff --git a/sample/app/eventhandler.cpp b/sample/app/eventhandler.cpp
index 4e55619..113b424 100644
--- a/sample/app/eventhandler.cpp
+++ b/sample/app/eventhandler.cpp
@@ -16,102 +16,188 @@
#include <functional>
#include <QUrl>
+#include <QGuiApplication>
#include <QJsonDocument>
#include <QJsonObject>
#include <QQuickWindow>
-//#include <QtQml/QQmlContext>
+#include <QtQml/QQmlContext>
#include <QQmlContext>
#include <QtQml/QQmlApplicationEngine>
+#include <qpa/qplatformnativeinterface.h>
+
#include "eventhandler.h"
+static struct wl_output *
+getWlOutput(QScreen *screen)
+{
+ QPlatformNativeInterface *native = qApp->platformNativeInterface();
+ void *output = native->nativeResourceForScreen("output", screen);
+ return static_cast<struct ::wl_output*>(output);
+}
+
+static void
+global_add(void *data, struct wl_registry *reg, uint32_t name,
+ const char *interface, uint32_t version)
+{
+ struct agl_shell_desktop **shell =
+ static_cast<struct agl_shell_desktop **>(data);
+
+ if (strcmp(interface, agl_shell_desktop_interface.name) == 0) {
+ *shell = static_cast<struct agl_shell_desktop *>(
+ wl_registry_bind(reg, name, &agl_shell_desktop_interface, version)
+ );
+ }
+}
+
+static void global_remove(void *data, struct wl_registry *reg, uint32_t id)
+{
+ (void) data;
+ (void) reg;
+ (void) id;
+}
+
+static const struct wl_registry_listener registry_listener = {
+ global_add,
+ global_remove,
+};
+
+static void
+application_id_event(void *data, struct agl_shell_desktop *agl_shell_desktop,
+ const char *app_id)
+{
+ EventHandler *ev_handler = static_cast<EventHandler *>(data);
+ (void) agl_shell_desktop;
+
+ // should probably add here to a list the application or trigger emit
+ // for QML code, also note that we get here our own application
+ if (strcmp(app_id, APP_ID) == 0)
+ return;
+
+ qInfo() << "app_id: " << app_id;
+}
+
+static void
+application_state_event(void *data, struct agl_shell_desktop *agl_shell_desktop,
+ const char *app_id, const char *app_data, uint32_t app_state, uint32_t app_role)
+{
+ /* unused */
+ (void) data;
+ (void) app_id;
+ (void) app_data;
+ (void) app_role;
+ (void) app_state;
+ (void) agl_shell_desktop;
+}
+
+static const struct agl_shell_desktop_listener agl_shell_desk_listener = {
+ application_id_event,
+ application_state_event,
+};
+
+static struct agl_shell_desktop *
+register_agl_shell_desktop(void)
+{
+ struct wl_display *wl;
+ struct wl_registry *registry;
+ struct agl_shell_desktop *shell = nullptr;
+
+ QPlatformNativeInterface *native = qApp->platformNativeInterface();
+
+ wl = static_cast<struct wl_display *>(native->nativeResourceForIntegration("display"));
+ registry = wl_display_get_registry(wl);
+
+ wl_registry_add_listener(registry, &registry_listener, &shell);
+ // Roundtrip to get all globals advertised by the compositor
+ wl_display_roundtrip(wl);
+ wl_registry_destroy(registry);
+
+ return shell;
+}
+
+
void* EventHandler::myThis = 0;
const char _drawing_name[] = "drawing_name";
EventHandler::EventHandler(QObject *parent) :
- QObject(parent),
- mp_hs(NULL),
- mp_wm(NULL),
- mp_qw(NULL)
+ QObject(parent), mp_qw(NULL)
{
}
EventHandler::~EventHandler()
{
- if (mp_hs != NULL) {
- delete mp_hs;
- }
- if (mp_wm != NULL) {
- delete mp_wm;
- }
+ if (shell_desktop)
+ agl_shell_desktop_destroy(shell_desktop);
}
void EventHandler::init(int port, const char *token)
{
- myThis = this;
- mp_wm = new QLibWindowmanager();
- mp_wm->init(port, token);
-
- mp_hs = new QLibHomeScreen();
- mp_hs->init(port, token);
-
- mp_hs->set_event_handler(QLibHomeScreen::Event_ShowWindow, [this](json_object *object){
- this->mp_wm->activateWindow(ROLE_NAME, "normal");
- HMI_DEBUG(APP_ID, "received showWindow event, end!, line=%d", __LINE__);
- });
-
- mp_hs->set_event_handler(QLibHomeScreen::Event_ReplyShowWindow, [this](json_object *object){
- HMI_DEBUG(APP_ID, "got Event_ReplyShowWindow!\n");
- const char* msg = json_object_to_json_string(object);
- emit this->signalOnReplyShowWindow(msg);
- });
-
- if (mp_wm->requestSurface(ROLE_NAME) != 0) {
- HMI_DEBUG(APP_ID, "!!!!LayoutHandler requestSurface Failed!!!!!");
- exit(EXIT_FAILURE);
- }
-
- // Create an event callback against an event type. Here a lambda is called when SyncDraw event occurs
- mp_wm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [this](json_object *object) {
- HMI_DEBUG(APP_ID, "Surface got syncDraw!");
- this->mp_wm->endDraw(ROLE_NAME);
- });
-
- mp_wm->set_event_handler(QLibWindowmanager::Event_Visible, [this](json_object *object) {
- struct json_object *value;
- json_object_object_get_ex(object, _drawing_name, &value);
- const char *name = json_object_get_string(value);
-
- HMI_DEBUG(APP_ID, "Event_Active kKeyDrawingName = %s", name);
- });
-
- mp_wm->set_event_handler(QLibWindowmanager::Event_Invisible, [this](json_object *object) {
- struct json_object *value;
- json_object_object_get_ex(object, _drawing_name, &value);
- const char *name = json_object_get_string(value);
-
- HMI_DEBUG(APP_ID, "Event_Inactive kKeyDrawingName = %s", name);
- });
-
- HMI_DEBUG(APP_ID, "LayoutHander::init() finished.");
+ (void) port;
+ (void) token;
+
+ shell_desktop = register_agl_shell_desktop();
+ if (shell_desktop)
+ agl_shell_desktop_add_listener(shell_desktop, &agl_shell_desk_listener, this);
+
+
+ m_launcher = new Launcher(DEFAULT_AFM_UNIX_SOCK, nullptr);
+ if (m_launcher->setup_pws_connection() != 0)
+ HMI_DEBUG("onscreen", "EventHandler::init failed to set-up connection to afm-system-daemon");
}
void EventHandler::setQuickWindow(QQuickWindow *qw)
{
mp_qw = qw;
- QObject::connect(mp_qw, SIGNAL(frameSwapped()), mp_wm, SLOT(slotActivateSurface()));
}
void EventHandler::showWindow(QString id, QString json)
{
- if(json.isNull())
- mp_hs->tapShortcut(id);
- else
- mp_hs->showWindow(id.toStdString().c_str(), json_tokener_parse(json.toStdString().c_str()));
+ if (shell_desktop) {
+ struct wl_output *output = getWlOutput(qApp->screens().first());
+ qInfo() << "sending activate_app";
+ agl_shell_desktop_activate_app(shell_desktop,
+ id.toStdString().c_str(),
+ json.toStdString().c_str(),
+ output);
+ }
+
+ qInfo() << "data from json: " << json.toStdString().c_str();
}
void EventHandler::hideWindow(QString id)
{
- mp_hs->hideWindow(id.toStdString().c_str());
+ if (shell_desktop)
+ agl_shell_desktop_deactivate_app(shell_desktop, id.toStdString().c_str());
+}
+
+int
+EventHandler::start(const QString &app_id)
+{
+ int pid = -1;
+
+ if (m_launcher && m_launcher->connection_is_set())
+ pid = m_launcher->start(app_id);
+
+ return pid;
+}
+
+bool
+EventHandler::is_running(const QString &app_id)
+{
+ if (m_launcher && m_launcher->connection_is_set())
+ return m_launcher->is_running(app_id);
+
+ return false;
+}
+
+void
+EventHandler::set_window_popup(const QString &app_id, int x, int y)
+{
+ struct wl_output *output = getWlOutput(qApp->screens().first());
+
+ if (shell_desktop)
+ agl_shell_desktop_set_app_property(shell_desktop,
+ app_id.toStdString().c_str(),
+ AGL_SHELL_DESKTOP_APP_ROLE_POPUP, x, y, output);
}
diff --git a/sample/app/eventhandler.h b/sample/app/eventhandler.h
index af66644..3a26b42 100644
--- a/sample/app/eventhandler.h
+++ b/sample/app/eventhandler.h
@@ -21,8 +21,14 @@
#include <string>
#include <QVariant>
-#include <qlibhomescreen.h>
-#include <qlibwindowmanager.h>
+#include <wayland-client.h>
+#include "wayland-agl-shell-desktop-client-protocol.h"
+
+#ifndef DEFAULT_AFM_UNIX_SOCK
+#define DEFAULT_AFM_UNIX_SOCK "unix:/run/platform/apis/ws/afm-main"
+#endif
+
+#include "launcher.h"
#include "hmi-debug.h"
#define ROLE_NAME "onstestapp"
@@ -46,14 +52,17 @@ public:
Q_INVOKABLE void showWindow(QString id, QString json);
Q_INVOKABLE void hideWindow(QString id);
+ Q_INVOKABLE int start(const QString &app_id);
+ Q_INVOKABLE bool is_running(const QString &app_id);
+ Q_INVOKABLE void set_window_popup(const QString &app_id, int x, int y);
signals:
void signalOnReplyShowWindow(QVariant val);
private:
- QLibHomeScreen *mp_hs;
- QLibWindowmanager* mp_wm;
- QQuickWindow *mp_qw;
+ struct agl_shell_desktop *shell_desktop = nullptr;
+ Launcher *m_launcher = nullptr;
+ QQuickWindow *mp_qw;
};
#endif // EVENTHANDLER_H
diff --git a/sample/app/main.cpp b/sample/app/main.cpp
index c47c869..f3bd99c 100644
--- a/sample/app/main.cpp
+++ b/sample/app/main.cpp
@@ -28,12 +28,14 @@
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
- app.setApplicationName("onstestapp");
- app.setApplicationVersion(QStringLiteral("3.99.3"));
- app.setOrganizationDomain(QStringLiteral("automotivelinux.org"));
- app.setOrganizationName(QStringLiteral("AutomotiveGradeLinux"));
- QQuickStyle::setStyle("AGL");
+ //app.setApplicationName("onstestapp");
+ //app.setApplicationVersion(QStringLiteral("3.99.3"));
+ //app.setOrganizationDomain(QStringLiteral("automotivelinux.org"));
+ //app.setOrganizationName(QStringLiteral("AutomotiveGradeLinux"));
+
+ //QQuickStyle::setStyle("AGL");
+ app.setDesktopFileName("onstestapp");
QCommandLineParser parser;
parser.addPositionalArgument("port", app.translate("main", "port for binding"));
diff --git a/sample/app/main.qml b/sample/app/main.qml
index b9f415b..b545c53 100644
--- a/sample/app/main.qml
+++ b/sample/app/main.qml
@@ -7,8 +7,8 @@ import AGL.Demo.Controls 1.0
ApplicationWindow {
id: root
visible: true
- width: 1080
- height: 1487
+ width: Screen.width
+ height: Screen.height
property string onsId: qsTr("onscreenapp")
property string onsTitle: qsTr("One Button title")
@@ -19,6 +19,15 @@ ApplicationWindow {
property string onsButton3: qsTr("")
property string postmsg: qsTr("")
property string btndata: qsTr("")
+ property int pid: -1
+ property bool onscreen_role_set: false
+
+ property string mapp_id: ''
+ property string mapp_data_msg: ''
+
+ // position of the pop-up
+ property int x: 200
+ property int y: 200
Label {
id: title
@@ -37,24 +46,24 @@ ApplicationWindow {
anchors.horizontalCenter: title.horizontalCenter
// show received reply information area
- Flickable {
- id: flickable
- width: 800
- height: 320
- Layout.alignment: Qt.AlignCenter
- flickableDirection: Flickable.VerticalFlick
- boundsBehavior: Flickable.StopAtBounds
-
- TextArea.flickable: TextArea {
- id: output
- text: "show received reply information area\n...\n...\n...\n...\n"
- font.pixelSize: 24
- wrapMode: TextArea.Wrap
- color: '#00ADDC'
- }
-
- ScrollBar.vertical: ScrollBar { }
- }
+ //Flickable {
+ // id: flickable
+ // width: 400
+ // height: 220
+ // Layout.alignment: Qt.AlignCenter
+ // flickableDirection: Flickable.VerticalFlick
+ // boundsBehavior: Flickable.StopAtBounds
+
+ // TextArea.flickable: TextArea {
+ // id: output
+ // text: "show received reply information area\n...\n...\n...\n...\n"
+ // font.pixelSize: 12
+ // wrapMode: TextArea.Wrap
+ // color: '#00ADDC'
+ // }
+
+ // ScrollBar.vertical: ScrollBar { }
+ // }
// select onscreen type area
GroupBox {
@@ -316,6 +325,26 @@ ApplicationWindow {
onsButton3 = qsTr("")
}
+ Timer {
+ id: activate_timer
+ interval: 500
+ running: false
+ repeat: false
+ onTriggered: {
+ console.log("calling eventHandler.showWindow for " + mapp_id + " and data msg " + mapp_data_msg)
+ eventHandler.showWindow(mapp_id, mapp_data_msg)
+ mapp_id = ''
+ mapp_data_msg = ''
+ }
+ }
+
+
+ function armTimer(app_id, msg) {
+ mapp_id = app_id
+ mapp_data_msg = msg
+ activate_timer.running = true
+ }
+
function postMessage() {
console.log("poster pressed")
btndata = ""
@@ -339,11 +368,42 @@ ApplicationWindow {
else
postmsg += "}"
- eventHandler.showWindow(onsId, postmsg);
+ if (!onscreen_role_set) {
+ console.log("onscreen_role_set is not set")
+ eventHandler.set_window_popup(onsId, x, y)
+ console.log("setting for popup for " + onsId)
+ onscreen_role_set = true
+ }
+
+ // if the application is not already started, start it
+ if (pid === -1) {
+ // if the application is not started, then the first time
+ // we start we also display it using the default policy engine
+ pid = eventHandler.start(onsId, postmsg)
+ console.log("calling eventHandler.start for " + onsId + " with pid " + pid)
+
+ // this is necessary jus the first time as we don't queue the
+ // 'activate_app' event and pass it over once onscreenapp is
+ // started. It is implementation detail in case it is required
+ console.log("calling armTimer for " + onsId)
+ armTimer(onsId, postmsg)
+ } else {
+ // onscreenapp is already start we just need to activate + pass the data
+ if (!eventHandler.is_running(onsId) && pid > 0) {
+ // this is mostly for testing, in case onscreenapp died
+ // unexpectedly
+ eventHandler.set_window_popup(onsId, x, y)
+ pid = eventHandler.start(onsId, postmsg)
+ armTimer(onsId, postmsg)
+ } else {
+ eventHandler.showWindow(onsId, postmsg)
+ }
+ }
+
}
function qmlOnReplyShowWindow(text) {
console.log("onstestapp received:",text);
- output.text = text;
+ //output.text = text;
}
}
diff --git a/sample/app/protocol/agl-shell-desktop.xml b/sample/app/protocol/agl-shell-desktop.xml
new file mode 100644
index 0000000..05a3725
--- /dev/null
+++ b/sample/app/protocol/agl-shell-desktop.xml
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="agl_shell_desktop">
+ <copyright>
+ Copyright © 2020 Collabora, Ltd.
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice (including the next
+ paragraph) shall be included in all copies or substantial portions of the
+ Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+ </copyright>
+ <interface name="agl_shell_desktop" version="1">
+ <description summary="Private extension to allow applications activate other apps">
+ This extension can be used by regular application to instruct to compositor
+ to activate or switch to other running (regular) applications. The client
+ is responsbile for filtering their own app_id when receiving application id.
+
+ Note that other (regular) applications can bind to this interface and there is
+ no mechanism to place to restrict or limit that.
+ </description>
+
+ <enum name="app_role">
+ <entry name="popup" value="0"/>
+ <entry name="fullscreen" value="1"/>
+ </enum>
+
+ <enum name="app_state">
+ <entry name="activated" value="0"/>
+ <entry name="deactivated" value="1"/>
+ </enum>
+
+ <event name="application">
+ <description summary="advertise application id">
+ The compositor may choose to advertise one or more application ids which
+ can be used to activate/switch to.
+
+ When this global is bound, the compositor will send all application ids
+ available for activation, but may send additional application id at any
+ time (when they've been mapped in the compositor).
+ </description>
+ <arg name="app_id" type="string"/>
+ </event>
+
+ <request name="activate_app">
+ <description summary="make client current window">
+ Ask the compositor to make a toplevel to become the current/focused
+ window for window management purposes.
+
+ See xdg_toplevel.set_app_id from the xdg-shell protocol for a
+ description of app_id.
+ </description>
+ <arg name="app_id" type="string"/>
+ <arg name="app_data" type="string" allow-null="true"/>
+ <arg name="output" type="object" interface="wl_output"/>
+ </request>
+
+ <request name="set_app_property">
+ <description summary="set properties for a client identified by app_id">
+ Ask the compositor to make a toplevel obey the app_role and, depending
+ on the role, to use the the x and y values as initial positional values.
+ The x and y values would only make sense for certain roles.
+
+ See xdg_toplevel.set_app_id from the xdg-shell protocol for a
+ description of app_id.
+ </description>
+ <arg name="app_id" type="string"/>
+ <arg name="role" type="uint" enum="app_role"/>
+ <arg name="x" type="int"/>
+ <arg name="y" type="int"/>
+ <arg name="output" type="object" interface="wl_output"/>
+ </request>
+
+ <request name="deactivate_app">
+ <description summary="de-activate/hide window identified by app_id">
+ Ask the compositor to hide the toplevel window for window
+ management purposes. Depending on the window role, this request
+ will either display the previously active window (or the background
+ in case there's no previously activate surface) or temporarly (or
+ until a 'activate_app' is called upon) hide the surface. All
+ the surfaces are identifiable by using the app_id, and no actions are
+ taken in case the app_id is not/was not present.
+
+ See xdg_toplevel.set_app_id from the xdg-shell protocol for a
+ description of app_id.
+ </description>
+ <arg name="app_id" type="string"/>
+ </request>
+
+ <event name="state_app">
+ <description summary="event sent when application has suffered state modification">
+ Notifies application(s) when other application have suffered state modifications.
+ </description>
+ <arg name="app_id" type="string"/>
+ <arg name="app_data" type="string" allow-null="true"/>
+ <arg name="state" type="uint" enum="app_state"/>
+ <arg name="role" type="uint" enum="app_role"/>
+ </event>
+
+ </interface>
+</protocol>
diff --git a/sample/package/config.xml b/sample/package/config.xml
index 2d9a5a1..38ec308 100644
--- a/sample/package/config.xml
+++ b/sample/package/config.xml
@@ -12,6 +12,10 @@
</feature>
<feature name="urn:AGL:widget:required-permission">
<param name="urn:AGL:permission::public:no-htdocs" value="required"/>
+ <param name="urn:AGL:permission::public:display" value="required" />
+ <param name="urn:AGL:permission:afm:system:widget:start" value="required" />
+ <param name="urn:AGL:permission:afm:system:widget" value="required" />
+ <param name="urn:AGL:permission:afm:system:runner" value="required" />
</feature>
</widget>
diff --git a/sample/sample.pro b/sample/sample.pro
index f49af69..e4e613b 100644
--- a/sample/sample.pro
+++ b/sample/sample.pro
@@ -14,5 +14,7 @@
# limitations under the License.
TEMPLATE = subdirs
-SUBDIRS = app package
+SUBDIRS = ../pws app package
+
+onstestapp.depends = ../pws
package.depends += app