aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2019-07-25 08:44:22 -0400
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2019-07-25 21:00:29 +0000
commit9a5b7d86347c17b22b767e5da0f79f469af5ec97 (patch)
tree4edcbb693c5b6866dee5df1236c57c9562afb555
parenta5c85dada0ec270cc17289fab569e6b6e6ab38b6 (diff)
Updated homescreen event handling logic to use the newer Event_ShowWindow event instead of Event_TapShortcut, and match what the other demo applications do. This fixes bringing the application back to the foreground after switching away, which was not working. As well, reindented main.cpp to improve readability. Bug-AGL: SPEC-2675 Signed-off-by: Scott Murray <scott.murray@konsulko.com> Change-Id: Ib183920325eb41aefd7aca1f323a8b99b9092b13
-rwxr-xr-xapp/main.cpp109
1 files changed, 50 insertions, 59 deletions
diff --git a/app/main.cpp b/app/main.cpp
index aca2f73..22872bb 100755
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 The Qt Company Ltd.
+ * Copyright (C) 2019 Konsulko Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,14 +16,14 @@
*/
#ifdef DESKTOP
-#define USE_QTAGLEXTRAS 0
+#define USE_QTAGLEXTRAS 0
#define USE_QLIBWINDOWMANAGER 0
#else
-#define USE_QTAGLEXTRAS 0
+#define USE_QTAGLEXTRAS 0
#define USE_QLIBWINDOWMANAGER 1
#endif
-#if USE_QTAGLEXTRAS
+#if USE_QTAGLEXTRAS
#include <QtAGLExtras/AGLApplication>
#elif USE_QLIBWINDOWMANAGER
#include <qlibwindowmanager.h>
@@ -48,14 +49,14 @@
int main(int argc, char *argv[])
{
- // for dbusIF
- if (!QDBusConnection::sessionBus().isConnected()) {
- qWarning("Cannot connect to the D-Bus session bus.\n"
- "Please check your system settings and try again.\n");
- return 1;
- }
+ // for dbusIF
+ if (!QDBusConnection::sessionBus().isConnected()) {
+ qWarning("Cannot connect to the D-Bus session bus.\n"
+ "Please check your system settings and try again.\n");
+ return 1;
+ }
-#if USE_QTAGLEXTRAS
+#if USE_QTAGLEXTRAS
AGLApplication app(argc, argv);
app.setApplicationName("navigation");
app.setupApplicationRole("navigation");
@@ -63,12 +64,12 @@ int main(int argc, char *argv[])
#elif USE_QLIBWINDOWMANAGER
QGuiApplication app(argc, argv);
- QString myname = QString("navigation");
+ QString graphic_role = QString("navigation");
int port = 1700;
QString token = "hello";
QCoreApplication::setOrganizationDomain("LinuxFoundation");
QCoreApplication::setOrganizationName("AutomotiveGradeLinux");
- QCoreApplication::setApplicationName(myname);
+ QCoreApplication::setApplicationName(graphic_role);
QCoreApplication::setApplicationVersion("0.1.0");
QCommandLineParser parser;
parser.addPositionalArgument("port", app.translate("main", "port for binding"));
@@ -80,86 +81,76 @@ int main(int argc, char *argv[])
if (positionalArguments.length() == 2) {
port = positionalArguments.takeFirst().toInt();
token = positionalArguments.takeFirst();
- }
- fprintf(stderr, "[navigation]app_name: %s, port: %d, token: %s.\n",
- myname.toStdString().c_str(),
- port,
- token.toStdString().c_str());
+ }
+ fprintf(stderr, "[navigation] app_name: %s, port: %d, token: %s.\n",
+ graphic_role.toStdString().c_str(),
+ port,
+ token.toStdString().c_str());
+
// QLibWM
QLibWindowmanager* qwmHandler = new QLibWindowmanager();
int res;
if((res = qwmHandler->init(port,token)) != 0){
- fprintf(stderr, "[navigation]init qlibwm err(%d)\n", res);
+ fprintf(stderr, "[navigation] init qlibwm err(%d)\n", res);
return -1;
}
- if((res = qwmHandler->requestSurface(myname)) != 0) {
- fprintf(stderr, "[navigation]request surface err(%d)\n", res);
+ if((res = qwmHandler->requestSurface(graphic_role)) != 0) {
+ fprintf(stderr, "[navigation] request surface err(%d)\n", res);
return -1;
}
- qwmHandler->set_event_handler(QLibWindowmanager::Event_SyncDraw, [qwmHandler, myname](json_object *object) {
- qwmHandler->endDraw(myname);
- });
- qwmHandler->set_event_handler(QLibWindowmanager::Event_Visible, [qwmHandler, myname](json_object *object) {
- ;
- });
- qwmHandler->set_event_handler(QLibWindowmanager::Event_Invisible, [qwmHandler, myname](json_object *object) {
- ;
- });
+ qwmHandler->set_event_handler(QLibWindowmanager::Event_SyncDraw,
+ [qwmHandler, &graphic_role](json_object *object) {
+ qwmHandler->endDraw(graphic_role);
+ });
+
// QLibHS
QLibHomeScreen* qhsHandler = new QLibHomeScreen();
qhsHandler->init(port, token.toStdString().c_str());
- qhsHandler->set_event_handler(QLibHomeScreen::Event_TapShortcut, [qwmHandler, myname](json_object *object){
- json_object *appnameJ = nullptr;
- if(json_object_object_get_ex(object, "application_name", &appnameJ))
- {
- const char *appname = json_object_get_string(appnameJ);
- if(QString::compare(myname, appname, Qt::CaseInsensitive) == 0)
- {
- qDebug("Surface %s got tapShortcut\n", appname);
- qwmHandler->activateWindow(myname);
- }
- }
- });
+ qhsHandler->set_event_handler(QLibHomeScreen::Event_ShowWindow,
+ [qwmHandler, &graphic_role](json_object *object){
+ qDebug("Surface %s got showWindow\n", graphic_role.toStdString().c_str());
+ qwmHandler->activateWindow(graphic_role);
+ });
// Load qml
QQmlApplicationEngine engine;
- MarkerModel model;
+ MarkerModel model;
engine.rootContext()->setContextProperty("markerModel", &model);
- Guidance_Module guidance;
+ Guidance_Module guidance;
engine.rootContext()->setContextProperty("guidanceModule", &guidance);
- File_Operation file;
- engine.rootContext()->setContextProperty("fileOperation", &file);
+ File_Operation file;
+ engine.rootContext()->setContextProperty("fileOperation", &file);
engine.load(QUrl(QStringLiteral("qrc:/navigation.qml")));
QObject *root = engine.rootObjects().first();
QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
QObject::connect(window, SIGNAL(frameSwapped()), qwmHandler, SLOT(slotActivateSurface()));
- QObject *map = engine.rootObjects().first()->findChild<QObject*>("map");
- DBus_Server dbus(map);
- dbus_server_navigationcore dbus_navigationcore(map);
+ QObject *map = engine.rootObjects().first()->findChild<QObject*>("map");
+ DBus_Server dbus(map);
+ dbus_server_navigationcore dbus_navigationcore(map);
#else // for only libwindowmanager
QGuiApplication app(argc, argv);
- app.setApplicationName("navigation");
+ app.setApplicationName("navigation");
// Load qml
QQmlApplicationEngine engine;
- MarkerModel model;
- engine.rootContext()->setContextProperty("markerModel", &model);
+ MarkerModel model;
+ engine.rootContext()->setContextProperty("markerModel", &model);
- Guidance_Module guidance;
- engine.rootContext()->setContextProperty("guidanceModule", &guidance);
+ Guidance_Module guidance;
+ engine.rootContext()->setContextProperty("guidanceModule", &guidance);
- File_Operation file;
- engine.rootContext()->setContextProperty("fileOperation", &file);
+ File_Operation file;
+ engine.rootContext()->setContextProperty("fileOperation", &file);
- engine.load(QUrl(QStringLiteral("qrc:/navigation.qml")));
- QObject *map = engine.rootObjects().first()->findChild<QObject*>("map");
- DBus_Server dbus(map);
- dbus_server_navigationcore dbus_navigationcore(map);
+ engine.load(QUrl(QStringLiteral("qrc:/navigation.qml")));
+ QObject *map = engine.rootObjects().first()->findChild<QObject*>("map");
+ DBus_Server dbus(map);
+ dbus_server_navigationcore dbus_navigationcore(map);
#endif