summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPaul Olav Tvete <paul.tvete@qt.io>2018-03-01 15:12:02 +0100
committerPaul Olav Tvete <paul.tvete@qt.io>2018-03-21 11:36:00 +0000
commitd29cbc2a0604f1b9a35f480a63a2472ca9e54661 (patch)
tree6469dc2d16802345b6ac733130bbdba73726ec29 /examples
parent942958a870dd01ebe1f4b03b70d7dda1ed9f67ab (diff)
downloadqtwayland-d29cbc2a0604f1b9a35f480a63a2472ca9e54661.tar.gz
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 <johan.helsing@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/wayland/minimal-cpp/README3
-rw-r--r--examples/wayland/minimal-cpp/compositor.cpp19
-rw-r--r--examples/wayland/minimal-cpp/compositor.h10
-rw-r--r--examples/wayland/minimal-cpp/window.cpp13
4 files changed, 23 insertions, 22 deletions
diff --git a/examples/wayland/minimal-cpp/README b/examples/wayland/minimal-cpp/README
index 3a9a4b1b..87c389c3 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 d32d8e88..e19fb0d6 100644
--- a/examples/wayland/minimal-cpp/compositor.cpp
+++ b/examples/wayland/minimal-cpp/compositor.cpp
@@ -52,6 +52,8 @@
#include "window.h"
#include <QtWaylandCompositor/qwaylandoutput.h>
+#include <QtWaylandCompositor/qwaylandiviapplication.h>
+#include <QtWaylandCompositor/qwaylandivisurface.h>
#include <QOpenGLFunctions>
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 984deebd..e804ac02 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<View*> m_views;
};
diff --git a/examples/wayland/minimal-cpp/window.cpp b/examples/wayland/minimal-cpp/window.cpp
index b8480647..c43255df 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