From 04c7651e4fa3d1bd804f0b3114d07fb19dd4eeee Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Wed, 20 May 2020 23:19:03 +0300 Subject: Removal of windowmanager depedency Signed-off-by: Marius Vlad --- app/app.pro | 15 +++-- app/main.cpp | 124 +++++++++++++++++++++++++++++-------- app/protocol/agl-shell-desktop.xml | 116 ++++++++++++++++++++++++++++++++++ app/qml/Main.qml | 6 +- app/shell-desktop.cpp | 50 +++++++++++++++ app/shell-desktop.h | 90 +++++++++++++++++++++++++++ package/config.xml | 3 - 7 files changed, 367 insertions(+), 37 deletions(-) create mode 100644 app/protocol/agl-shell-desktop.xml create mode 100644 app/shell-desktop.cpp create mode 100644 app/shell-desktop.h diff --git a/app/app.pro b/app/app.pro index eec6528..87db1db 100644 --- a/app/app.pro +++ b/app/app.pro @@ -1,10 +1,10 @@ TARGET = tbtnavi TEMPLATE = app -QT = qml network quick positioning location widgets websockets -PKGCONFIG += qlibhomescreen qlibwindowmanager qtappfw-navigation qtappfw-signal-composer +QT = qml network quick positioning location widgets websockets gui-private +PKGCONFIG += qlibhomescreen qtappfw-navigation qtappfw-signal-composer wayland-client -CONFIG += c++1z link_pkgconfig +CONFIG += c++1z link_pkgconfig wayland-scanner include(app.pri) @@ -12,12 +12,14 @@ SOURCES += \ main.cpp \ navigation_client.cpp \ qcheapruler.cpp \ - file_operation.cpp + file_operation.cpp \ + shell-desktop.cpp HEADERS += \ qcheapruler.hpp \ navigation_client.h \ - file_operation.h + file_operation.h \ + shell-desktop.h INCLUDEPATH += \ ../include @@ -28,3 +30,6 @@ OTHER_FILES += \ RESOURCES += \ images/images.qrc \ app.qrc + +WAYLANDCLIENTSOURCES += \ + protocol/agl-shell-desktop.xml diff --git a/app/main.cpp b/app/main.cpp index eb00109..fc097f0 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -7,24 +7,98 @@ #include #include #include -#include #include #include #include +#include #include "navigation_client.h" #include "qcheapruler.hpp" #include "file_operation.h" +#include "shell-desktop.h" + +#include +#include + +#include "wayland-agl-shell-desktop-client-protocol.h" + +#define OUTPUT_ID "remoting" + +static void +global_add(void *data, struct wl_registry *reg, uint32_t name, + const char *interface, uint32_t) +{ + struct agl_shell_desktop **shell = static_cast(data); + + if (strcmp(interface, agl_shell_desktop_interface.name) == 0) { + *shell = static_cast( + wl_registry_bind(reg, name, &agl_shell_desktop_interface, 1) + ); + } +} + +static void +global_remove(void *data, struct wl_registry *reg, uint32_t id) +{ + /* Don't care */ + (void) data; + (void) reg; + (void) id; +} + +static const struct wl_registry_listener registry_listener = { + global_add, + global_remove, +}; + +static struct agl_shell_desktop * +register_agl_shell_desktop(QPlatformNativeInterface *native) +{ + struct wl_display *wl; + struct wl_registry *registry; + struct agl_shell_desktop *shell = nullptr; + + wl = static_cast(native->nativeResourceForIntegration("display")); + registry = wl_display_get_registry(wl); + + wl_registry_add_listener(registry, ®istry_listener, &shell); + + /* Roundtrip to get all globals advertised by the compositor */ + wl_display_roundtrip(wl); + wl_registry_destroy(registry); + + return shell; +} + + +static QScreen * +find_qscreen(const char *screen_name) +{ + QList screens = qApp->screens(); + QScreen *found = nullptr; + QString qstr_name = QString::fromUtf8(screen_name, -1); + + for (QScreen *xscreen : screens) { + if (qstr_name == xscreen->name()) { + found = xscreen; + break; + } + } + + return found; +} int main(int argc, char *argv[]) { QString graphic_role = QString("tbtnavi"); + struct agl_shell_desktop *agl_shell_desktop = nullptr; QGuiApplication app(argc, argv); QCoreApplication::setOrganizationDomain("automotivelinux.org"); QCoreApplication::setOrganizationName("AutomotiveGradeLinux"); QCoreApplication::setApplicationName(graphic_role); QCoreApplication::setApplicationVersion("0.1.0"); + app.setDesktopFileName(graphic_role); QCommandLineParser parser; parser.addPositionalArgument("port", app.translate("main", "port for binding")); @@ -35,6 +109,16 @@ int main(int argc, char *argv[]) QStringList positionalArguments = parser.positionalArguments(); QUrl bindingAddress; + QPlatformNativeInterface *native = qApp->platformNativeInterface(); + agl_shell_desktop = register_agl_shell_desktop(native); + if (!agl_shell_desktop) { + qDebug() << "Could not find agl_shell_desktop extension. Is agl-compositor running?"; + exit(EXIT_FAILURE); + } + + std::shared_ptr shell{agl_shell_desktop, agl_shell_desktop_destroy}; + Shell *aglShell = new Shell(shell, nullptr); + int port = 0; QString token; if (positionalArguments.length() == 2) { @@ -53,30 +137,19 @@ int main(int argc, char *argv[]) port, token.toStdString().c_str()); - // QLibWM - QLibWindowmanager* qwmHandler = new QLibWindowmanager(); - int res; - if((res = qwmHandler->init(port,token)) != 0){ - fprintf(stderr, "[tbtnavi] init qlibwm err(%d)\n", res); - return -1; - } - if((res = qwmHandler->requestSurface(graphic_role)) != 0) { - fprintf(stderr, "[tbtnavi] request surface err(%d)\n", res); - return -1; + /* inform the compositor that the window be placed on a different + * output */ + QScreen *screen_to_put = find_qscreen(OUTPUT_ID); + if (screen_to_put) { + qDebug() << "Found screen to put " << screen_to_put->name(); + aglShell->set_window_on_screen(screen_to_put, graphic_role); + } else { + qDebug() << "Couldn't find screen to put " << OUTPUT_ID; + qDebug() << "Available screens: "; + for (auto &ss: qApp->screens()) { + qDebug() << "screen: " << ss->name(); + } } - 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_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; @@ -97,8 +170,5 @@ int main(int argc, char *argv[]) QObject *root = engine.rootObjects().first(); new navigation_client(navigation, root->findChild("mapwindow")); - QQuickWindow *window = qobject_cast(root); - QObject::connect(window, SIGNAL(frameSwapped()), qwmHandler, SLOT(slotActivateWindow())); - return app.exec(); } diff --git a/app/protocol/agl-shell-desktop.xml b/app/protocol/agl-shell-desktop.xml new file mode 100644 index 0000000..4f942f5 --- /dev/null +++ b/app/protocol/agl-shell-desktop.xml @@ -0,0 +1,116 @@ + + + + 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. + + + + 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. + + + + + + + + + + + + + + + + + + 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). + + + + + + + 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. + + + + + + + + + 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. + + + + + + + + + + + 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. + + + + + + + Notifies application(s) when other application have suffered state modifications. + + + + + + + + + diff --git a/app/qml/Main.qml b/app/qml/Main.qml index 7c83f37..188fa86 100644 --- a/app/qml/Main.qml +++ b/app/qml/Main.qml @@ -1,14 +1,16 @@ import QtQuick 2.0 import QtQuick.Controls 2.2 +import QtQuick.Window 2.11 + import "qrc:/qml" ApplicationWindow { id: tbtnavi title: "Turn By Turn Navigation Demo" - height: 720 - width: 640 + height: Window.height + width: Window.width visible: true property double vehicleSpeed: 0 diff --git a/app/shell-desktop.cpp b/app/shell-desktop.cpp new file mode 100644 index 0000000..f0a54e5 --- /dev/null +++ b/app/shell-desktop.cpp @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#include +#include +#include "shell-desktop.h" +#include +#include + +static struct wl_output * +getWlOutput(QScreen *screen) +{ + QPlatformNativeInterface *native = qApp->platformNativeInterface(); + void *output = native->nativeResourceForScreen("output", screen); + return static_cast(output); +} + +void +Shell::set_window_on_screen(QScreen *screen, const QString &app_id) +{ + struct wl_output *output; + output = getWlOutput(screen); + agl_shell_desktop_set_app_property(this->shell.get(), + app_id.toStdString().c_str(), + AGL_SHELL_DESKTOP_APP_ROLE_REMOTE, + 0, 0, output); + +} diff --git a/app/shell-desktop.h b/app/shell-desktop.h new file mode 100644 index 0000000..7c3c36b --- /dev/null +++ b/app/shell-desktop.h @@ -0,0 +1,90 @@ +/* + * 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. + */ + +#ifndef SHELLDESKTOP_H +#define SHELLDESKTOP_H + +#include +#include +#include +#include +#include +#include + +#include "wayland-agl-shell-desktop-client-protocol.h" + +static void +application_id_event(void *data, struct agl_shell_desktop *agl_shell_desktop, + const char *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); + +static const struct agl_shell_desktop_listener agl_shell_desktop_listener = { + application_id_event, + application_state_event, +}; + +class Shell : public QObject +{ +Q_OBJECT + +public: + std::shared_ptr shell; + Shell(std::shared_ptr shell, QObject *parent = nullptr) : + QObject(parent), shell(shell) + { + struct agl_shell_desktop *agl_shell_desktop = shell.get(); + agl_shell_desktop_add_listener(agl_shell_desktop, + &agl_shell_desktop_listener, this); + } + +public slots: // calls out of qml into CPP + void set_window_on_screen(QScreen *screen, const QString &app_id); +}; + +static void +application_id_event(void *data, struct agl_shell_desktop *agl_shell_desktop, + const char *app_id) +{ + Shell *aglShell = static_cast(data); + (void) agl_shell_desktop; +} + +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) +{ + (void) data; + (void) agl_shell_desktop; + (void) app_id; + (void) app_data; + (void) app_state; + (void) app_role; +} + +#endif // SHELLDESKTOP_H diff --git a/package/config.xml b/package/config.xml index 65a66c5..db361b5 100644 --- a/package/config.xml +++ b/package/config.xml @@ -7,7 +7,6 @@ TOYOTA APL 2.0 - @@ -15,8 +14,6 @@ - - -- cgit