summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJørgen Lind <jorgen.lind@theqtcompany.com>2015-08-12 16:15:12 +0200
committerJørgen Lind <jorgen.lind@theqtcompany.com>2015-08-28 13:10:33 +0200
commit00c626d77d5bebf4ab5b09c82207faaa5c0ff7a7 (patch)
tree3bd48572b7b53904352f9a4b6b1f3f3b840421b1 /examples
parent3b2206d8495286ad3427edc7ec99b1d5efb2f370 (diff)
downloadqtwayland-00c626d77d5bebf4ab5b09c82207faaa5c0ff7a7.tar.gz
Fix up that QWindowCompositor didn't send onScreenVisibillity
This actually works as an excellent example for how to integrate with extension and signals and slots. Change-Id: Ib4ab8f2ebefcc48940c83f38c5f2219a19902c15
Diffstat (limited to 'examples')
-rw-r--r--examples/wayland/qwindow-compositor/qwindowcompositor.cpp62
-rw-r--r--examples/wayland/qwindow-compositor/qwindowcompositor.h7
2 files changed, 49 insertions, 20 deletions
diff --git a/examples/wayland/qwindow-compositor/qwindowcompositor.cpp b/examples/wayland/qwindow-compositor/qwindowcompositor.cpp
index 812398e1..abd76cd3 100644
--- a/examples/wayland/qwindow-compositor/qwindowcompositor.cpp
+++ b/examples/wayland/qwindow-compositor/qwindowcompositor.cpp
@@ -65,6 +65,19 @@
QT_BEGIN_NAMESPACE
+class Surface : public QWaylandSurface
+{
+public:
+ Surface(QWaylandClient *client, quint32 id, int version, QWaylandCompositor *compositor)
+ : QWaylandSurface(client, id, version, compositor)
+ , extSurface(Q_NULLPTR)
+ , hasSentOnScreen(false)
+ { }
+
+ QtWayland::ExtendedSurface *extSurface;
+ bool hasSentOnScreen;
+};
+
class SurfaceView : public QWaylandView
{
public:
@@ -136,10 +149,13 @@ void QWindowCompositor::create()
primaryOutputSpace()->addOutputWindow(m_window, "", "");
m_renderScheduler.setSingleShot(true);
- connect(&m_renderScheduler,SIGNAL(timeout()),this,SLOT(render()));
+ connect(&m_renderScheduler, &QTimer::timeout, this, &QWindowCompositor::render);
connect(this, &QWaylandCompositor::surfaceCreated, this, &QWindowCompositor::onSurfaceCreated);
connect(this, &QWaylandCompositor::currentCurserSurfaceRequest, this, &QWindowCompositor::adjustCursorSurface);
+ QtWayland::SurfaceExtensionGlobal *extSurfGlob = QtWayland::SurfaceExtensionGlobal::findIn(this);
+ connect(extSurfGlob, &QtWayland::SurfaceExtensionGlobal::extendedSurfaceReady, this, &QWindowCompositor::extendedSurfaceCreated);
+
m_window->installEventFilter(this);
setRetainedSelectionEnabled(true);
@@ -228,7 +244,7 @@ void QWindowCompositor::surfaceUnmapped(QWaylandSurface *surface)
m_renderScheduler.start(0);
}
-void QWindowCompositor::surfaceCommitted()
+void QWindowCompositor::surfaceCommittedSlot()
{
QWaylandSurface *surface = qobject_cast<QWaylandSurface *>(sender());
surfaceCommitted(surface);
@@ -247,10 +263,9 @@ void QWindowCompositor::surfaceCommitted(QWaylandSurface *surface)
void QWindowCompositor::onSurfaceCreated(QWaylandSurface *surface)
{
- connect(surface, SIGNAL(surfaceDestroyed()), this, SLOT(surfaceDestroyed()));
- connect(surface, SIGNAL(mappedChanged()), this, SLOT(surfaceMappedChanged()));
- connect(surface, SIGNAL(redraw()), this, SLOT(surfaceCommitted()));
- connect(surface, SIGNAL(extendedSurfaceReady()), this, SLOT(sendExpose()));
+ connect(surface, &QWaylandSurface::surfaceDestroyed, this, &QWindowCompositor::surfaceDestroyed);
+ connect(surface, &QWaylandSurface::mappedChanged, this, &QWindowCompositor::surfaceMappedChanged);
+ connect(surface, &QWaylandSurface::redraw, this, &QWindowCompositor::surfaceCommittedSlot);
}
void QWindowCompositor::onShellSurfaceCreated(QWaylandSurface *surface, QtWayland::ShellSurface *shellSurface)
@@ -262,12 +277,11 @@ void QWindowCompositor::onShellSurfaceCreated(QWaylandSurface *surface, QtWaylan
m_renderScheduler.start(0);
}
-void QWindowCompositor::sendExpose()
+void QWindowCompositor::extendedSurfaceCreated(QtWayland::ExtendedSurface *extendedSurface, QWaylandSurface *surface)
{
- QWaylandSurface *surface = qobject_cast<QWaylandSurface *>(sender());
- QtWayland::ExtendedSurface *extendedSurface = QtWayland::ExtendedSurface::findIn(surface);
- if (extendedSurface)
- extendedSurface->sendOnScreenVisibilityChange(true);
+ Surface *s = static_cast<Surface *>(surface);
+ Q_ASSERT(!s->extSurface);
+ s->extSurface = extendedSurface;
}
void QWindowCompositor::updateCursor(bool hasBuffer)
@@ -309,6 +323,11 @@ void QWindowCompositor::adjustCursorSurface(QWaylandSurface *surface, int hotspo
m_cursorHotspotY = hotspotY;
}
+QWaylandSurface *QWindowCompositor::createSurface(QWaylandClient *client, quint32 id, int version)
+{
+ return new Surface(client, id, version, this);
+}
+
QWaylandView *QWindowCompositor::viewAt(const QPointF &point, QPointF *local)
{
for (int i = m_surfaces.size() - 1; i >= 0; --i) {
@@ -355,19 +374,28 @@ void QWindowCompositor::render()
m_window->swapBuffers();
}
-void QWindowCompositor::drawSubSurface(const QPoint &offset, QWaylandSurface *surface)
+void QWindowCompositor::drawSubSurface(const QPoint &offset, QWaylandSurface *s)
{
+ Surface *surface = static_cast<Surface *>(s);
SurfaceView *view = static_cast<SurfaceView *>(surface->views().first());
GLuint texture = view->updateTextureToCurrentBuffer();
bool invert_y = view->currentBuffer().origin() == QWaylandSurface::OriginTopLeft;
QPoint pos = view->pos().toPoint() + offset;
QRect geo(pos, surface->size());
- m_textureBlitter->drawTexture(texture, geo, m_window->size(), 0, false, invert_y);
+ bool onscreen = (QRect(QPoint(0, 0), m_window->size()).contains(pos));
+ if (surface->extSurface && onscreen != surface->hasSentOnScreen) {
+ surface->extSurface->sendOnScreenVisibilityChange(onscreen);
+ surface->hasSentOnScreen = onscreen;
+ }
+
+ if (onscreen) {
+ m_textureBlitter->drawTexture(texture, geo, m_window->size(), 0, false, invert_y);
- QtWayland::SubSurface *subSurface = QtWayland::SubSurface::findIn(surface);
- if (subSurface) {
- foreach (QWaylandSurface *child, subSurface->subSurfaces()) {
- drawSubSurface(pos, child);
+ QtWayland::SubSurface *subSurface = QtWayland::SubSurface::findIn(surface);
+ if (subSurface) {
+ foreach (QWaylandSurface *child, subSurface->subSurfaces()) {
+ drawSubSurface(pos, child);
+ }
}
}
}
diff --git a/examples/wayland/qwindow-compositor/qwindowcompositor.h b/examples/wayland/qwindow-compositor/qwindowcompositor.h
index 2ac302f2..b08c8a62 100644
--- a/examples/wayland/qwindow-compositor/qwindowcompositor.h
+++ b/examples/wayland/qwindow-compositor/qwindowcompositor.h
@@ -56,6 +56,7 @@ QT_BEGIN_NAMESPACE
namespace QtWayland {
class Shell;
class ShellSurface;
+ class ExtendedSurface;
}
class QWaylandView;
@@ -72,14 +73,14 @@ public:
private slots:
void surfaceMappedChanged();
void surfaceDestroyed();
- void surfaceCommitted();
+ void surfaceCommittedSlot();
void surfacePosChanged();
void render();
void onSurfaceCreated(QWaylandSurface *surface);
void onShellSurfaceCreated(QWaylandSurface *surface, QtWayland::ShellSurface *shellSurface);
protected:
- QWaylandView *createView() Q_DECL_OVERRIDE;
+ QWaylandSurface *createSurface(QWaylandClient *client, quint32 id, int version) Q_DECL_OVERRIDE;
void surfaceCommitted(QWaylandSurface *surface);
QWaylandView* viewAt(const QPointF &point, QPointF *local = 0);
@@ -93,7 +94,7 @@ protected:
QImage makeBackgroundImage(const QString &fileName);
private slots:
- void sendExpose();
+ void extendedSurfaceCreated(QtWayland::ExtendedSurface *extSurface, QWaylandSurface *surface);
void updateCursor(bool hasBuffer);
private: