diff options
author | Johan Klokkhammer Helsing <johan.helsing@theqtcompany.com> | 2016-03-19 15:32:11 +0100 |
---|---|---|
committer | Giulio Camuffo <giulio.camuffo@kdab.com> | 2016-04-11 06:20:41 +0000 |
commit | 0b16a83b9d292d98d0ef6d2541af0eb58a8504f2 (patch) | |
tree | e7d0af6e4ec0fa5f1ab5fd131033938d259588a3 | |
parent | f430e84e0642b5eec0b6069dadd8317d880932cc (diff) |
Create a fallback shellSurface in wl_shell::get_shell_surface
This makes QWaylandShellPrivate::shell_get_shell_surface behave
similarly to QWaylandCompositorPrivate::compositor_create_surface.
First, a signal is emitted letting a compositor implementation create
its own subclass of QWaylandShellSurface if desired. If it's not
created, a plain QWaylandShellSurface is created instead.
It also makes the API more consistent, as the creation of shell surfaces
now mimick the creation of surfaces and xdg surfaces.
qwindow-compositor has been updated to take advantage of the new API
Change-Id: I7c7262dd253dc37843e8e471a4ead5f6e87b0ced
Reviewed-by: Giulio Camuffo <giulio.camuffo@kdab.com>
4 files changed, 28 insertions, 16 deletions
diff --git a/examples/wayland/qwindow-compositor/windowcompositor.cpp b/examples/wayland/qwindow-compositor/windowcompositor.cpp index a8504b517..5b3b69059 100644 --- a/examples/wayland/qwindow-compositor/windowcompositor.cpp +++ b/examples/wayland/qwindow-compositor/windowcompositor.cpp @@ -111,8 +111,8 @@ WindowCompositor::WindowCompositor(QWindow *window) , m_wlShell(new QWaylandWlShell(this)) , m_xdgShell(new QWaylandXdgShell(this)) { - connect(m_wlShell, &QWaylandWlShell::createShellSurface, this, &WindowCompositor::onCreateWlShellSurface); - connect(m_xdgShell, &QWaylandXdgShell::createXdgSurface, this, &WindowCompositor::onCreateXdgSurface); + connect(m_wlShell, &QWaylandWlShell::shellSurfaceCreated, this, &WindowCompositor::onWlShellSurfaceCreated); + connect(m_xdgShell, &QWaylandXdgShell::xdgSurfaceCreated, this, &WindowCompositor::onXdgSurfaceCreated); connect(m_xdgShell, &QWaylandXdgShell::createXdgPopup, this, &WindowCompositor::onCreateXdgPopup); } @@ -189,29 +189,27 @@ WindowCompositorView * WindowCompositor::findView(const QWaylandSurface *s) cons return Q_NULLPTR; } -void WindowCompositor::onCreateWlShellSurface(QWaylandSurface *s, const QWaylandResource &res) +void WindowCompositor::onWlShellSurfaceCreated(QWaylandWlShellSurface *wlShellSurface) { - QWaylandSurface *surface = s; - - QWaylandWlShellSurface *wlShellSurface = new QWaylandWlShellSurface(m_wlShell, surface, res); connect(wlShellSurface, &QWaylandWlShellSurface::startMove, this, &WindowCompositor::onStartMove); connect(wlShellSurface, &QWaylandWlShellSurface::startResize, this, &WindowCompositor::onWlStartResize); connect(wlShellSurface, &QWaylandWlShellSurface::setTransient, this, &WindowCompositor::onSetTransient); connect(wlShellSurface, &QWaylandWlShellSurface::setPopup, this, &WindowCompositor::onSetPopup); - WindowCompositorView *view = findView(s); + + WindowCompositorView *view = findView(wlShellSurface->surface()); Q_ASSERT(view); view->m_wlShellSurface = wlShellSurface; } -void WindowCompositor::onCreateXdgSurface(QWaylandSurface *surface, const QWaylandResource &res) +void WindowCompositor::onXdgSurfaceCreated(QWaylandXdgSurface *xdgSurface) { - QWaylandXdgSurface *xdgSurface = new QWaylandXdgSurface(m_xdgShell, surface, res); connect(xdgSurface, &QWaylandXdgSurface::startMove, this, &WindowCompositor::onStartMove); connect(xdgSurface, &QWaylandXdgSurface::startResize, this, &WindowCompositor::onXdgStartResize); - WindowCompositorView *view = findView(surface); + WindowCompositorView *view = findView(xdgSurface->surface()); Q_ASSERT(view); view->m_xdgSurface = xdgSurface; + connect(xdgSurface, &QWaylandXdgSurface::setMaximized, view, &WindowCompositorView::onXdgSetMaximized); connect(xdgSurface, &QWaylandXdgSurface::setFullscreen, view, &WindowCompositorView::onXdgSetFullscreen); connect(xdgSurface, &QWaylandXdgSurface::unsetMaximized, view, &WindowCompositorView::onXdgUnsetMaximized); diff --git a/examples/wayland/qwindow-compositor/windowcompositor.h b/examples/wayland/qwindow-compositor/windowcompositor.h index 63068d1ae..c8b796ee9 100644 --- a/examples/wayland/qwindow-compositor/windowcompositor.h +++ b/examples/wayland/qwindow-compositor/windowcompositor.h @@ -127,8 +127,8 @@ private slots: void triggerRender(); void onSurfaceCreated(QWaylandSurface *surface); - void onCreateWlShellSurface(QWaylandSurface *s, const QWaylandResource &resource); - void onCreateXdgSurface(QWaylandSurface *surface, const QWaylandResource &resource); + void onWlShellSurfaceCreated(QWaylandWlShellSurface *wlShellSurface); + void onXdgSurfaceCreated(QWaylandXdgSurface *xdgSurface); void onCreateXdgPopup(QWaylandSurface *surface, QWaylandSurface *parent, QWaylandInputDevice *inputDevice, const QPoint &position, const QWaylandResource &resource); void onSetTransient(QWaylandSurface *parentSurface, const QPoint &relativeToParent, QWaylandWlShellSurface::FocusPolicy focusPolicy); diff --git a/src/compositor/extensions/qwaylandwlshell.cpp b/src/compositor/extensions/qwaylandwlshell.cpp index c6d13b392..817a01b9e 100644 --- a/src/compositor/extensions/qwaylandwlshell.cpp +++ b/src/compositor/extensions/qwaylandwlshell.cpp @@ -61,8 +61,9 @@ void QWaylandWlShellPrivate::shell_get_shell_surface(Resource *resource, uint32_ Q_Q(QWaylandWlShell); QWaylandSurface *surface = QWaylandSurface::fromResource(surface_res); - wl_resource *res = wl_resource_create(resource->client(), &wl_shell_surface_interface, - wl_resource_get_version(resource->handle), id); + QWaylandResource shellSurfaceResource(wl_resource_create(resource->client(), &wl_shell_surface_interface, + wl_resource_get_version(resource->handle), id)); + // XXX FIXME // The role concept was formalized in wayland 1.7, so that release adds one error // code for each interface that implements a role, and we are supposed to pass here @@ -71,8 +72,19 @@ void QWaylandWlShellPrivate::shell_get_shell_surface(Resource *resource, uint32_ // However we're still using wayland 1.4, which doesn't have interface specific role // errors, so the best we can do is to use wl_display's object_id error. wl_resource *displayRes = wl_client_get_object(resource->client(), 1); - if (surface->setRole(QWaylandWlShellSurface::role(), displayRes, WL_DISPLAY_ERROR_INVALID_OBJECT)) - emit q->createShellSurface(surface, QWaylandResource(res)); + if (!surface->setRole(QWaylandWlShellSurface::role(), displayRes, WL_DISPLAY_ERROR_INVALID_OBJECT)) + return; + + emit q->createShellSurface(surface, shellSurfaceResource); + + QWaylandWlShellSurface *shellSurface = QWaylandWlShellSurface::fromResource(shellSurfaceResource.resource()); + if (!shellSurface) { + // A QWaylandShellSurface was not created in response to the createShellSurface signal + // we create one as fallback here instead. + shellSurface = new QWaylandWlShellSurface(q, surface, shellSurfaceResource); + } + + emit q->shellSurfaceCreated(shellSurface); } QWaylandWlShellSurfacePrivate::QWaylandWlShellSurfacePrivate() diff --git a/src/compositor/extensions/qwaylandwlshell.h b/src/compositor/extensions/qwaylandwlshell.h index 2420f4cd0..12905549e 100644 --- a/src/compositor/extensions/qwaylandwlshell.h +++ b/src/compositor/extensions/qwaylandwlshell.h @@ -51,6 +51,7 @@ class QWaylandClient; class QWaylandInputDevice; class QWaylandOutput; class QWaylandSurfaceRole; +class QWaylandWlShellSurface; class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandWlShell : public QWaylandExtensionTemplate<QWaylandWlShell> { @@ -67,6 +68,7 @@ public: Q_SIGNALS: void createShellSurface(QWaylandSurface *surface, const QWaylandResource &resource); + void shellSurfaceCreated(QWaylandWlShellSurface *shellSurface); }; class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandWlShellSurface : public QWaylandExtensionTemplate<QWaylandWlShellSurface> |