I'm interested in trying to get a QWaylandCompositor-based project up and running.
Qt 6.3 provides several QML-based examples of working Wayland compositors. I condensed one down to the following:
import QtQuick
import QtWayland.Compositor
import QtWayland.Compositor.XdgShell
WaylandCompositor{
id:waylandCompositor
WaylandOutput{
id:output
compositor:waylandCompositor
property ListModel shellSurfaces:ListModel{}
function handleShellSurface(shellSurface){shellSurfaces.append({shellSurface:shellSurface});}
sizeFollowsWindow:true
window:Window{
width:1024
height:760
visible:true
Repeater{
model:output.shellSurfaces
ShellSurfaceItem{
shellSurface:modelData
onSurfaceDestroyed:output.shellSurfaces.remove(index)
}
}
}
}
XdgShell{onToplevelCreated:{output.handleShellSurface(xdgSurface)}
}
This produces a very basic but working compositor that is capable of running other Qt apps inside it.
So I have written the C++ equivalent which works the same, except that the application windows are not visually updated. They do respond to mouse clicks (for example popup menus work). Programs that show animated content (for example projectM-pulseaudio) only display the initial rendered frame.
The QML example above handles it without problems, but obfuscates the lower-level working of the compositor.
I don't think there's any need to list the full source code (but feel free to ask if you think it's necessary), I just need to know how to handle the signal
QWaylandXdgShell::topLevelCreated(QWaylandXdgToplevel*,QWaylandXdgSurface*)
which is fired whenever an application creates a window in the compositor.
Currently my slot which it connects to looks like this:
void Compositor::toplevelCreatedSlot(QWaylandXdgToplevel *toplevel,QWaylandXdgSurface *surface)
{
QWaylandQuickShellSurfaceItem *item=new QWaylandQuickShellSurfaceItem(m_rootWindow->contentItem());
item->setShellSurface(surface);
}
.. but I don't know what else I need to do to make applications work properly.
I have been stuck on this for several days now and I'm really trying to make sense of Qt's documentation (or Wayland in general). I would hugely appreciate it if somebody could help me out.