From d29cbc2a0604f1b9a35f480a63a2472ca9e54661 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Thu, 1 Mar 2018 15:12:02 +0100 Subject: Make the minimal-cpp example a real compositor Use the ivi-application protocol, since a compositor without a shell is not really a proper compositor. Use the IVI id to determine the position instead of generating a random position for each frame. Change-Id: I2ede824c656e4c2ef88117cf0f0b8d27ad80b6e2 Reviewed-by: Johan Helsing --- examples/wayland/minimal-cpp/README | 3 ++- examples/wayland/minimal-cpp/compositor.cpp | 19 ++++++++----------- examples/wayland/minimal-cpp/compositor.h | 10 +++++++--- examples/wayland/minimal-cpp/window.cpp | 13 ++++++------- 4 files changed, 23 insertions(+), 22 deletions(-) (limited to 'examples') diff --git a/examples/wayland/minimal-cpp/README b/examples/wayland/minimal-cpp/README index 3a9a4b1b2..87c389c3b 100644 --- a/examples/wayland/minimal-cpp/README +++ b/examples/wayland/minimal-cpp/README @@ -1,6 +1,7 @@ A minimal example showing what is required to get a C++ based compositor up and running. Input events are not delivered to clients, to avoid the logic -for finding the correct window and map the coordinates. +for finding the correct window and map the coordinates. This example uses the +IVI-application shell protocol, positioning windows based on the ivi_id. See the qwindow-compositor example for information on how to implement support for key and mouse events, and everything else a proper desktop diff --git a/examples/wayland/minimal-cpp/compositor.cpp b/examples/wayland/minimal-cpp/compositor.cpp index d32d8e888..e19fb0d68 100644 --- a/examples/wayland/minimal-cpp/compositor.cpp +++ b/examples/wayland/minimal-cpp/compositor.cpp @@ -52,6 +52,8 @@ #include "window.h" #include +#include +#include #include QOpenGLTexture *View::getTexture() { @@ -60,11 +62,6 @@ QOpenGLTexture *View::getTexture() { return m_texture; } -bool View::isCursor() const -{ - return surface()->isCursorSurface(); -} - Compositor::Compositor(Window *window) : m_window(window) { @@ -82,18 +79,18 @@ void Compositor::create() QWaylandCompositor::create(); output->setCurrentMode(mode); - connect(this, &QWaylandCompositor::surfaceCreated, this, &Compositor::onSurfaceCreated); + m_iviApplication = new QWaylandIviApplication(this); + connect(m_iviApplication, &QWaylandIviApplication::iviSurfaceCreated, this, &Compositor::onIviSurfaceCreated); } -void Compositor::onSurfaceCreated(QWaylandSurface *surface) +void Compositor::onIviSurfaceCreated(QWaylandIviSurface *iviSurface) { - connect(surface, &QWaylandSurface::surfaceDestroyed, this, &Compositor::onSurfaceDestroyed); - connect(surface, &QWaylandSurface::redraw, this, &Compositor::triggerRender); - View *view = new View; - view->setSurface(surface); + View *view = new View(iviSurface->iviId()); + view->setSurface(iviSurface->surface()); view->setOutput(outputFor(m_window)); m_views << view; connect(view, &QWaylandView::surfaceDestroyed, this, &Compositor::viewSurfaceDestroyed); + connect(iviSurface->surface(), &QWaylandSurface::redraw, this, &Compositor::triggerRender); } void Compositor::onSurfaceDestroyed() diff --git a/examples/wayland/minimal-cpp/compositor.h b/examples/wayland/minimal-cpp/compositor.h index 984deebdb..e804ac02f 100644 --- a/examples/wayland/minimal-cpp/compositor.h +++ b/examples/wayland/minimal-cpp/compositor.h @@ -59,17 +59,20 @@ QT_BEGIN_NAMESPACE class Window; class QOpenGLTexture; +class QWaylandIviApplication; +class QWaylandIviSurface; class View : public QWaylandView { Q_OBJECT public: - View() {} + View(int iviId) : m_iviId(iviId) {} QOpenGLTexture *getTexture(); - bool isCursor() const; + int iviId() const { return m_iviId; } private: friend class Compositor; QOpenGLTexture *m_texture = nullptr; + int m_iviId; }; class Compositor : public QWaylandCompositor @@ -86,13 +89,14 @@ public: void endRender(); private slots: - void onSurfaceCreated(QWaylandSurface *surface); + void onIviSurfaceCreated(QWaylandIviSurface *iviSurface); void onSurfaceDestroyed(); void triggerRender(); void viewSurfaceDestroyed(); private: Window *m_window = nullptr; + QWaylandIviApplication *m_iviApplication = nullptr; QList m_views; }; diff --git a/examples/wayland/minimal-cpp/window.cpp b/examples/wayland/minimal-cpp/window.cpp index b84806472..c43255dfc 100644 --- a/examples/wayland/minimal-cpp/window.cpp +++ b/examples/wayland/minimal-cpp/window.cpp @@ -70,11 +70,12 @@ void Window::initializeGL() m_textureBlitter.create(); } -static int sillyrandom(int range) +static QPoint sillyrandom(int seed, QSize screenSize, QSize surfaceSize) { - if (range <= 0) - range = 200; - return QRandomGenerator::global()->bounded(range); + QRandomGenerator rand(seed); + int xrange = qMax(screenSize.width() - surfaceSize.width(), 200); + int yrange = qMax(screenSize.height() - surfaceSize.height(), 200); + return QPoint(rand.bounded(xrange), rand.bounded(yrange)); } void Window::paintGL() @@ -91,8 +92,6 @@ void Window::paintGL() functions->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Q_FOREACH (View *view, m_compositor->views()) { - if (view->isCursor()) - continue; auto texture = view->getTexture(); if (!texture) continue; @@ -104,7 +103,7 @@ void Window::paintGL() QWaylandSurface *surface = view->surface(); if (surface && surface->hasContent()) { QSize s = surface->size(); - QPointF pos(sillyrandom(width() - s.width()), sillyrandom(height() - s.height())); + QPointF pos = sillyrandom(view->iviId(), size(), s); QRectF surfaceGeometry(pos, s); QOpenGLTextureBlitter::Origin surfaceOrigin = view->currentBuffer().origin() == QWaylandSurface::OriginTopLeft -- cgit v1.2.3