summaryrefslogtreecommitdiffstats
path: root/examples/wayland/qwindow-compositor/compositor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/wayland/qwindow-compositor/compositor.cpp')
-rw-r--r--examples/wayland/qwindow-compositor/compositor.cpp79
1 files changed, 74 insertions, 5 deletions
diff --git a/examples/wayland/qwindow-compositor/compositor.cpp b/examples/wayland/qwindow-compositor/compositor.cpp
index 4878c373e..8d0db5258 100644
--- a/examples/wayland/qwindow-compositor/compositor.cpp
+++ b/examples/wayland/qwindow-compositor/compositor.cpp
@@ -56,13 +56,15 @@
#define GL_TEXTURE_EXTERNAL_OES 0x8D65
#endif
-View::View()
- : m_textureTarget(GL_TEXTURE_2D)
+View::View(Compositor *compositor)
+ : m_compositor(compositor)
+ , m_textureTarget(GL_TEXTURE_2D)
, m_texture(0)
, m_wlShellSurface(nullptr)
, m_xdgSurface(nullptr)
, m_xdgPopup(nullptr)
, m_parentView(nullptr)
+ , m_animationFactor(1.0)
{}
QOpenGLTexture *View::getTexture()
@@ -70,16 +72,33 @@ QOpenGLTexture *View::getTexture()
if (advance()) {
QWaylandBufferRef buf = currentBuffer();
m_texture = buf.toOpenGLTexture();
+ if (surface()) {
+ m_size = surface()->size();
+ m_origin = buf.origin() == QWaylandSurface::OriginTopLeft
+ ? QOpenGLTextureBlitter::OriginTopLeft
+ : QOpenGLTextureBlitter::OriginBottomLeft;
+ }
}
return m_texture;
}
+QOpenGLTextureBlitter::Origin View::textureOrigin() const
+{
+ return m_origin;
+}
+
+QSize View::size() const
+{
+ return surface() ? surface()->size() : m_size;
+}
+
bool View::isCursor() const
{
- return surface()->isCursorSurface();
+ return surface() && surface()->isCursorSurface();
}
+
void View::onXdgSetMaximized()
{
m_xdgSurface->sendMaximized(output()->geometry().size());
@@ -117,6 +136,44 @@ void View::onOffsetForNextFrame(const QPoint &offset)
setPosition(position() + offset);
}
+
+void View::timerEvent(QTimerEvent *event)
+{
+ if (event->timerId() != m_animationTimer.timerId())
+ return;
+
+ m_compositor->triggerRender();
+
+ if (m_animationCountUp) {
+ m_animationFactor += .08;
+ if (m_animationFactor > 1.0) {
+ m_animationFactor = 1.0;
+ m_animationTimer.stop();
+ emit animationDone();
+ }
+ } else {
+ m_animationFactor -= .08;
+ if (m_animationFactor < 0.01) {
+ m_animationFactor = 0.01;
+ m_animationTimer.stop();
+ emit animationDone();
+ }
+ }
+}
+
+void View::startAnimation(bool countUp)
+{
+ m_animationCountUp = countUp;
+ m_animationFactor = countUp ? .1 : 1.0;
+ m_animationTimer.start(20, this);
+}
+
+void View::cancelAnimation()
+{
+ m_animationFactor = 1.0;
+ m_animationTimer.stop();
+}
+
void View::onXdgUnsetFullscreen()
{
onXdgUnsetMaximized();
@@ -159,8 +216,7 @@ void Compositor::onSurfaceCreated(QWaylandSurface *surface)
connect(surface, &QWaylandSurface::redraw, this, &Compositor::triggerRender);
connect(surface, &QWaylandSurface::subsurfacePositionChanged, this, &Compositor::onSubsurfacePositionChanged);
-
- View *view = new View;
+ View *view = new View(this);
view->setSurface(surface);
view->setOutput(outputFor(m_window));
m_views << view;
@@ -189,10 +245,20 @@ void Compositor::surfaceDestroyed()
void Compositor::viewSurfaceDestroyed()
{
View *view = qobject_cast<View*>(sender());
+ view->setBufferLocked(true);
+ view->startAnimation(false);
+ connect(view, &View::animationDone, this, &Compositor::viewAnimationDone);
+}
+
+
+void Compositor::viewAnimationDone()
+{
+ View *view = qobject_cast<View*>(sender());
m_views.removeAll(view);
delete view;
}
+
View * Compositor::findView(const QWaylandSurface *s) const
{
Q_FOREACH (View* view, m_views) {
@@ -212,6 +278,7 @@ void Compositor::onWlShellSurfaceCreated(QWaylandWlShellSurface *wlShellSurface)
View *view = findView(wlShellSurface->surface());
Q_ASSERT(view);
view->m_wlShellSurface = wlShellSurface;
+ view->startAnimation(true);
}
void Compositor::onXdgSurfaceCreated(QWaylandXdgSurfaceV5 *xdgSurface)
@@ -227,6 +294,7 @@ void Compositor::onXdgSurfaceCreated(QWaylandXdgSurfaceV5 *xdgSurface)
connect(xdgSurface, &QWaylandXdgSurfaceV5::setFullscreen, view, &View::onXdgSetFullscreen);
connect(xdgSurface, &QWaylandXdgSurfaceV5::unsetMaximized, view, &View::onXdgUnsetMaximized);
connect(xdgSurface, &QWaylandXdgSurfaceV5::unsetFullscreen, view, &View::onXdgUnsetFullscreen);
+ view->startAnimation(true);
}
void Compositor::onXdgPopupRequested(QWaylandSurface *surface, QWaylandSurface *parent,
@@ -291,6 +359,7 @@ void Compositor::onSetPopup(QWaylandSeat *seat, QWaylandSurface *parent, const Q
View *parentView = findView(parent);
if (parentView)
view->setPosition(parentView->position() + relativeToParent);
+ view->cancelAnimation();
}
}