Hi there, I've been trying to run a simple Wayland compositor in Qt C++, but I have an issue where trying to display surfaces results in nothing being displayed on the window. The code I'm using is below:
#include <QtWaylandCompositor/QWaylandCompositor>
#include <QtWaylandCompositor/QWaylandClient>
#include <QtWaylandCompositor/QWaylandSurface>
#include <QtWaylandCompositor/QWaylandXdgShell>
#include <QtWaylandCompositor/QWaylandWlShell>
#include <QtWaylandCompositor/QWaylandIviApplication>
#include <QtWaylandCompositor/QWaylandIviSurface>
#include <QtWaylandCompositor/QWaylandQuickShellSurfaceItem>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine(&app);
QQuickWindow *window = new QQuickWindow();
window->setWidth(1024);
window->setHeight(768);
QWaylandQuickShellSurfaceItem *surface_item = new QWaylandQuickShellSurfaceItem();
surface_item->setParentItem(window->contentItem());
surface_item->setSize(QSizeF(800, 480));
QList<QWaylandShellSurface*> surfaces;
QWaylandCompositor compositor;
QWaylandOutput output(&compositor, window);
output.setSizeFollowsWindow(true);
QWaylandOutputMode mode(window->size(), 60000); // 60 Hz
output.addMode(mode, true);
compositor.setDefaultOutput(&output);
QWaylandXdgShell xdgShell(&compositor);
QWaylandWlShell wlShell(&compositor);
QWaylandIviApplication iviApp(&compositor);
QObject::connect(&xdgShell, &QWaylandXdgShell::toplevelCreated,
[&surfaces, window, surface_item](QWaylandXdgToplevel *toplevel, QWaylandXdgSurface *xdgSurface) {
qDebug() << "XDG Toplevel created:" << toplevel;
qDebug() << "XDG Surface created:" << xdgSurface;
QWaylandShellSurface *shellSurface = qobject_cast<QWaylandShellSurface *>(xdgSurface);
surfaces.append(shellSurface);
surface_item->setShellSurface(shellSurface);
});
QObject::connect(&wlShell, &QWaylandWlShell::wlShellSurfaceCreated,
[&surfaces, window, surface_item](QWaylandWlShellSurface *wlShellSurface) {
QWaylandShellSurface *shellSurface = qobject_cast<QWaylandShellSurface *>(wlShellSurface);
surfaces.append(shellSurface);
surface_item->setShellSurface(shellSurface);
});
QObject::connect(&iviApp, &QWaylandIviApplication::iviSurfaceCreated,
[&surfaces, window, surface_item](QWaylandIviSurface *iviSurface) {
QWaylandShellSurface *shellSurface = qobject_cast<QWaylandShellSurface *>(iviSurface);
surfaces.append(shellSurface);
surface_item->setShellSurface(shellSurface);
});
QObject::connect(&compositor, &QWaylandCompositor::surfaceCreated,
[&engine, window](QWaylandSurface *surface) {
qDebug() << "Surface created:" << surface;
});
compositor.addExtension(&xdgShell);
compositor.addExtension(&wlShell);
compositor.addExtension(&iviApp);
compositor.create();
window->show();
return app.exec();
}
I used the minimal QML implementation as the example for the C++ code, yet it works in QML but not C++. Any hep would be appreciated!