diff options
-rw-r--r-- | app/app.pro | 15 | ||||
-rw-r--r-- | app/main.cpp | 124 | ||||
-rw-r--r-- | app/protocol/agl-shell-desktop.xml | 116 | ||||
-rw-r--r-- | app/qml/Main.qml | 6 | ||||
-rw-r--r-- | app/shell-desktop.cpp | 50 | ||||
-rw-r--r-- | app/shell-desktop.h | 90 | ||||
-rw-r--r-- | package/config.xml | 3 |
7 files changed, 367 insertions, 37 deletions
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 <QtQml/QQmlApplicationEngine> #include <QtQml/QQmlContext> #include <QtQuick/QQuickWindow> -#include <qlibwindowmanager.h> #include <qlibhomescreen.h> #include <navigation.h> #include <signalcomposer.h> +#include <QScreen> #include "navigation_client.h" #include "qcheapruler.hpp" #include "file_operation.h" +#include "shell-desktop.h" + +#include <qpa/qplatformnativeinterface.h> +#include <wayland-client.h> + +#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<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, 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<struct wl_display *>(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<QScreen *> 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<struct agl_shell_desktop> 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<QObject*>("mapwindow")); - QQuickWindow *window = qobject_cast<QQuickWindow *>(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 @@ +<?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"/> + <entry name="split_vertical" value="2"/> + <entry name="split_horizontal" value="3"/> + <entry name="remote" value="4"/> + </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/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 <QGuiApplication> +#include <QDebug> +#include "shell-desktop.h" +#include <qpa/qplatformnativeinterface.h> +#include <stdio.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); +} + +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 <QObject> +#include <QString> +#include <QScreen> +#include <QWindow> +#include <QDebug> +#include <memory> + +#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<struct agl_shell_desktop> shell; + Shell(std::shared_ptr<struct agl_shell_desktop> 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<Shell *>(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 @@ <author>TOYOTA</author> <license>APL 2.0</license> <feature name="urn:AGL:widget:required-api"> - <param name="windowmanager" value="ws"/> <param name="homescreen" value="ws"/> <param name="navigation" value="ws"/> <param name="signal-composer" value="ws"/> @@ -15,8 +14,6 @@ <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::system:run-by-default" value="required"/> - <param name="urn:AGL:permission::public:hidden" value="required" /> <param name="http://tizen.org/privilege/internal/dbus" value="required"/> </feature> </widget> |