[tests] Support a trasient window in the waylandclienttest

Main purpose is to reproduce a crash if the parent window gets
destroyed before the transient. For this the following key combo
can be used:
t: show transient
k: close parent window
q: quit application

This currently causes reliably a crash in Deleted::copyToDeleted for
the connect of the mainClients.
This commit is contained in:
Martin Gräßlin 2015-10-01 14:03:48 +02:00
parent 044e2a05b2
commit 48a6272916
2 changed files with 34 additions and 0 deletions

View file

@ -108,12 +108,15 @@ void WaylandClientTest::setupRegistry(Registry *registry)
[this, registry](quint32 name) {
m_compositor = registry->createCompositor(name, 1, this);
m_surface = m_compositor->createSurface(this);
m_transient.surface = m_compositor->createSurface(this);
}
);
connect(registry, &Registry::shellAnnounced, this,
[this, registry](quint32 name) {
Shell *shell = registry->createShell(name, 1, this);
m_shellSurface = shell->createSurface(m_surface, m_surface);
m_transient.shellSurface = shell->createSurface(m_transient.surface, m_transient.surface);
m_transient.shellSurface->setTransient(m_surface, QPoint(100, 100));
connect(m_shellSurface, &ShellSurface::sizeChanged, this, static_cast<void(WaylandClientTest::*)(const QSize&)>(&WaylandClientTest::render));
render(QSize(200, 200));
}
@ -156,6 +159,32 @@ void WaylandClientTest::setupRegistry(Registry *registry)
}
}
}
if (key == KEY_T && state == Keyboard::KeyState::Released) {
if (m_transient.visible) {
m_transient.surface->attachBuffer(Buffer::Ptr());
m_transient.surface->commit(Surface::CommitFlag::None);
m_transient.visible = false;
} else {
const QSize size(200, 200);
auto buffer = m_shm->getBuffer(size, size.width() * 4).toStrongRef();
buffer->setUsed(true);
QImage image(buffer->address(), size.width(), size.height(), QImage::Format_ARGB32_Premultiplied);
image.fill(s_colors[s_colorIndex]);
m_transient.surface->attachBuffer(*buffer);
m_transient.surface->damage(QRect(QPoint(0, 0), size));
m_transient.surface->commit(Surface::CommitFlag::None);
buffer->setUsed(false);
m_transient.visible = true;
}
}
if (key == KEY_K && state == Keyboard::KeyState::Released) {
delete m_shellSurface;
m_shellSurface = nullptr;
delete m_surface;
m_surface = nullptr;
m_connectionThreadObject->flush();
}
}
);
}

View file

@ -64,6 +64,11 @@ private:
KWayland::Client::ShellSurface *m_shellSurface;
QSize m_currentSize;
QTimer *m_timer;
struct {
KWayland::Client::Surface *surface = nullptr;
KWayland::Client::ShellSurface *shellSurface = nullptr;
bool visible = false;
} m_transient;
};
#endif