2 * Copyright (C) 2016 The Qt Company Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <QtCore/QDebug>
18 #include <QtCore/QCommandLineParser>
19 #include <QtCore/QUrlQuery>
20 #include <QtGui/QGuiApplication>
21 #include <QtQml/QQmlApplicationEngine>
22 #include <QtQml/QQmlContext>
23 #include <QtQuick/QQuickWindow>
25 #ifdef HAVE_LIBHOMESCREEN
26 #include <libhomescreen.hpp>
28 #ifdef HAVE_QLIBWINDOWMANAGER
29 #include <qlibwindowmanager.h>
32 int main(int argc, char *argv[])
34 QString myname = QString("HVAC");
36 QGuiApplication app(argc, argv);
37 app.setApplicationVersion(QStringLiteral("0.1.0"));
38 app.setOrganizationDomain(QStringLiteral("automotivelinux.org"));
39 app.setOrganizationName(QStringLiteral("AutomotiveGradeLinux"));
41 QCommandLineParser parser;
42 parser.addPositionalArgument("port", app.translate("main", "port for binding"));
43 parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
44 parser.addHelpOption();
45 parser.addVersionOption();
47 QStringList positionalArguments = parser.positionalArguments();
49 QQmlApplicationEngine engine;
50 QQmlContext *context = engine.rootContext();
53 if (positionalArguments.length() == 2) {
54 int port = positionalArguments.takeFirst().toInt();
55 QString secret = positionalArguments.takeFirst();
56 bindingAddress.setScheme(QStringLiteral("ws"));
57 bindingAddress.setHost(QStringLiteral("localhost"));
58 bindingAddress.setPort(port);
59 bindingAddress.setPath(QStringLiteral("/api"));
61 query.addQueryItem(QStringLiteral("token"), secret);
62 bindingAddress.setQuery(query);
64 context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
65 #ifdef HAVE_QLIBWINDOWMANAGER
66 QLibWindowmanager* qwm = new QLibWindowmanager();
69 if(qwm->init(port,secret) != 0){
72 // Request a surface as described in layers.json windowmanager’s file
73 if (qwm->requestSurface(myname) != 0) {
76 // Create an event callbnewack against an event type. Here a lambda is called when SyncDraw event occurs
77 qwm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [qwm, myname](json_object *object) {
78 fprintf(stderr, "Surface got syncDraw!\n");
83 #ifdef HAVE_LIBHOMESCREEN
84 LibHomeScreen* hs = new LibHomeScreen();
87 std::string token = secret.toStdString();
88 hs->init(port, token.c_str());
89 // Set the event handler for Event_TapShortcut which will activate the surface for windowmanager
90 hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [qwm, myname](json_object *object){
91 json_object *appnameJ = nullptr;
92 if(json_object_object_get_ex(object, "application_name", &appnameJ))
94 const char *appname = json_object_get_string(appnameJ);
97 qDebug("Surface %s got tapShortcut\n", appname);
98 qwm->activateSurface(myname);
104 engine.load(QUrl(QStringLiteral("qrc:/HVAC.qml")));
105 QObject *root = engine.rootObjects().first();
106 QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
107 #ifdef HAVE_QLIBWINDOWMANAGER
108 QObject::connect(window, SIGNAL(frameSwapped()), qwm, SLOT(slotActivateSurface()));
110 window->resize(1080, 1920 - 218 - 215);
111 window->setVisible(true);