diff options
author | Kazumasa Mitsunari <knimitz@witz-inc.co.jp> | 2017-10-23 20:48:26 +0900 |
---|---|---|
committer | Kazumasa Mitsunari <knimitz@witz-inc.co.jp> | 2017-10-23 21:44:36 +0900 |
commit | 283a0f1ddd10cfd96d488f0701537b83b4ebe889 (patch) | |
tree | cd69bda1f8431af4c96c5f1ceb275104739a5946 | |
parent | c46a56ac144e7399f2172e56a7a22d46d580c830 (diff) |
Adopt window manager feature to activate surface
Adopt windowmanager feature to get rendering right and show up from application
Please refer to the sequence :
https://wiki.automotivelinux.org/_media/agl-hmi-fw_windowmanager_spec_v0.1.0.pdf
page: 5
qlibwindowmanager will be removed when qlibwindowmanager repository is created
Change-Id: I486aabdedb0414cdf0d3f43db35534e6b109bcd9
Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
-rw-r--r-- | app/app.pro | 7 | ||||
-rw-r--r-- | app/main.cpp | 43 | ||||
-rw-r--r-- | app/qlibwindowmanager.cpp | 71 | ||||
-rw-r--r-- | app/qlibwindowmanager.h | 71 | ||||
-rw-r--r-- | package/config.xml | 1 |
5 files changed, 176 insertions, 17 deletions
diff --git a/app/app.pro b/app/app.pro index e0a927e..fd777a3 100644 --- a/app/app.pro +++ b/app/app.pro @@ -1,8 +1,11 @@ TARGET = radio QT = quickcontrols2 -HEADERS = PresetDataObject.h -SOURCES = main.cpp PresetDataObject.cpp +HEADERS = PresetDataObject.h qlibwindowmanager.h +SOURCES = main.cpp PresetDataObject.cpp qlibwindowmanager.cpp + +CONFIG += link_pkgconfig +PKGCONFIG += windowmanager RESOURCES += \ radio.qrc \ diff --git a/app/main.cpp b/app/main.cpp index e430099..23966ca 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -1,6 +1,7 @@ /* * Copyright (C) 2016 The Qt Company Ltd. * Copyright (C) 2016, 2017 Konsulko Group + * Copyright (C) 2016, 2017 Toyota Motor Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,25 +24,15 @@ #include <QtQml/QQmlApplicationEngine> #include <QtQml/QQmlContext> #include <QtQuickControls2/QQuickStyle> -#include <stdlib.h> +#include <QQuickWindow> #include "PresetDataObject.h" +#include "qlibwindowmanager.h" - -#ifdef HAVE_LIBHOMESCREEN -#include <libhomescreen.hpp> -#endif +static QLibWindowmanager* qwm; +static std::string myname = std::string("Radio"); int main(int argc, char *argv[]) { -#ifdef HAVE_LIBHOMESCREEN - LibHomeScreen libHomeScreen; - - if (!libHomeScreen.renderAppToAreaAllowed(0, 1)) { - qWarning() << "renderAppToAreaAllowed is denied"; - return -1; - } -#endif - QGuiApplication app(argc, argv); QQuickStyle::setStyle("AGL"); @@ -98,8 +89,30 @@ int main(int argc, char *argv[]) query.addQueryItem(QStringLiteral("token"), secret); bindingAddress.setQuery(query); context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress); + + qwm = new QLibWindowmanager(); + // WindowManager + if(qwm->init(port,secret) != 0){ + exit(EXIT_FAILURE); + } + if (qwm->requestSurface(myname.c_str()) != 0) { + exit(EXIT_FAILURE); + } + qwm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [qwm](json_object *object) { + fprintf(stderr, "Surface got syncDraw!\n"); + qwm->endDraw(myname.c_str()); + }); + qwm->set_event_handler(QLibWindowmanager::Event_FlushDraw, [](json_object *object) { + fprintf(stderr, "Surface got flushDraw!\n");; + }); + + // Loading QML File + engine.load(QUrl(QStringLiteral("qrc:/Radio.qml"))); + QObject *root = engine.rootObjects().first(); + QQuickWindow *window = qobject_cast<QQuickWindow *>(root); + QObject::connect(window, SIGNAL(frameSwapped()), + qwm, SLOT(slotActivateSurface())); // This should be disconnected, but when... } - engine.load(QUrl(QStringLiteral("qrc:/Radio.qml"))); return app.exec(); } diff --git a/app/qlibwindowmanager.cpp b/app/qlibwindowmanager.cpp new file mode 100644 index 0000000..7380bc8 --- /dev/null +++ b/app/qlibwindowmanager.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2017 TOYOTA MOTOR CORPORATION + * + * 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 "qlibwindowmanager.h" +#include <unistd.h> + +int QLibWindowmanager::init(int port, const QString &token) { + std::string ctoken = token.toStdString(); + return this->wm->init(port, ctoken.c_str()); +} + +int QLibWindowmanager::requestSurface(const char *label) { + applabel = label; + json_object *obj = json_object_new_object(); + json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(label)); + return this->wm->requestSurface(obj); +} + +int QLibWindowmanager::activateSurface(const char *label) { + json_object *obj = json_object_new_object(); + json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(label)); + json_object_object_add(obj, wm->kKeyDrawingArea, json_object_new_string("normal.full")); + return this->wm->activateSurface(obj); +} + +int QLibWindowmanager::deactivateSurface(const char *label) { + json_object *obj = json_object_new_object(); + json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(label)); + return this->wm->deactivateSurface(obj); +} + +int QLibWindowmanager::endDraw(const char *label) { + json_object *obj = json_object_new_object(); + json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(label)); + return this->wm->endDraw(obj); + } + +void QLibWindowmanager::set_event_handler(enum QEventType et, + handler_fun f) { + LibWindowmanager::EventType wet = (LibWindowmanager::EventType)et; + return this->wm->set_event_handler(wet, std::move(f)); +} + +void QLibWindowmanager::slotActivateSurface(){ + if(!isActive){ + qDebug("Let's show radio"); + isActive = true; + this->activateSurface(applabel.c_str()); + } +} + +QLibWindowmanager::QLibWindowmanager(QObject *parent) + :QObject(parent), isActive(false) +{ + wm = new LibWindowmanager(); +} + +QLibWindowmanager::~QLibWindowmanager() { } diff --git a/app/qlibwindowmanager.h b/app/qlibwindowmanager.h new file mode 100644 index 0000000..dd0694e --- /dev/null +++ b/app/qlibwindowmanager.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2017 TOYOTA MOTOR CORPORATION + * + * 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 QLIBWINDOWMANAGER_H +#define QLIBWINDOWMANAGER_H +#include <libwindowmanager.h> +#include <functional> + #include <QObject> + #include <QUrl> + #include <QVariant> + #include <string> + #include <vector> + +class QLibWindowmanager : public QObject{ +Q_OBJECT +public: + explicit QLibWindowmanager(QObject *parent = nullptr); + ~QLibWindowmanager(); + + QLibWindowmanager(const QLibWindowmanager &) = delete; + QLibWindowmanager &operator=(const QLibWindowmanager &) = delete; + +public: + using handler_fun = std::function<void(json_object *object)>; + + enum QEventType { + Event_Active = 0, + Event_Inactive, + + Event_Visible, + Event_Invisible, + + Event_SyncDraw, + Event_FlushDraw, + }; + + static QLibWindowmanager &instance(); + + int init(int port, const QString &token); + + // WM API + int requestSurface(const char *label); + int activateSurface(const char *label); + int deactivateSurface(const char *label); + int endDraw(const char *label); + void set_event_handler(enum QEventType et, handler_fun f); + +public slots: + void slotActivateSurface(); + +private: + LibWindowmanager* wm; + std::string applabel; + std::vector<int> surfaceIDs; + bool isActive; + +}; +#endif // LIBWINDOWMANAGER_H diff --git a/package/config.xml b/package/config.xml index 9d59089..698598c 100644 --- a/package/config.xml +++ b/package/config.xml @@ -7,6 +7,7 @@ <author>Qt</author> <license>APL 2.0</license> <feature name="urn:AGL:widget:required-api"> + <param name="windowmanager" value="ws" /> <param name="radio" value="ws" /> </feature> <feature name="urn:AGL:widget:required-permission"> |