summaryrefslogtreecommitdiffstats
path: root/app/main.cpp
diff options
context:
space:
mode:
authorMarius Vlad <marius.vlad@collabora.com>2020-05-20 23:19:03 +0300
committerMarius Vlad <marius.vlad@collabora.com>2020-06-24 18:04:24 +0300
commit6457b9cefc7df82005fb01200b7a8c4d5415bda8 (patch)
treecf3323cee07b5a691831ad3714c0884823f20b7c /app/main.cpp
parent97fbd6401ee0720d4efe4d4e9e2e02cfc6b0c4bd (diff)
Removal of windowmanager depedency
Bug-AGL: SPEC-3447 Signed-off-by: Marius Vlad <marius.vlad@collabora.com> Change-Id: I7d7172459d38540fc7ddfac6887e68e73fd475fc
Diffstat (limited to 'app/main.cpp')
-rw-r--r--app/main.cpp124
1 files changed, 97 insertions, 27 deletions
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, &registry_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();
}