Client: Use std::unique_ptr to manage window decoration

There was a potential crash in the QWaylandWindow destructor. First it
deletes the window decoration (but does not unset the pointer!) and then
deletes the surface via reset(). This eventually triggers
QWaylandDisplay::handleKeyboardFocusChanged which will call
decoration->update().
Using std::unique_ptr makes it easier to manage and prevents such errors.

Change-Id: I52edcdab0d25c35dc656581fbb5c1c9b5ca481c4
Reviewed-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
This commit is contained in:
David Redondo 2024-07-16 11:57:17 +02:00
parent c50ebcd83d
commit 279406aa20
2 changed files with 6 additions and 8 deletions

View File

@ -72,7 +72,7 @@ QWaylandWindow::QWaylandWindow(QWindow *window, QWaylandDisplay *display)
QWaylandWindow::~QWaylandWindow()
{
delete mWindowDecoration;
mWindowDecoration.reset();
if (mSurface)
reset();
@ -1064,8 +1064,7 @@ bool QWaylandWindow::createDecoration()
if (decoration && !decorationPluginFailed) {
if (!mWindowDecorationEnabled) {
if (mWindowDecoration) {
delete mWindowDecoration;
mWindowDecoration = nullptr;
mWindowDecoration.reset();
}
QStringList decorations = QWaylandDecorationFactory::keys();
@ -1104,8 +1103,7 @@ bool QWaylandWindow::createDecoration()
if (targetKey.isEmpty())
targetKey = decorations.first(); // first come, first served.
mWindowDecoration = QWaylandDecorationFactory::create(targetKey, QStringList());
mWindowDecoration.reset(QWaylandDecorationFactory::create(targetKey, QStringList()));
if (!mWindowDecoration) {
qWarning() << "Could not create decoration from factory! Running with no decorations.";
decorationPluginFailed = true;
@ -1137,12 +1135,12 @@ bool QWaylandWindow::createDecoration()
window()->requestUpdate();
}
return mWindowDecoration;
return mWindowDecoration.get();
}
QWaylandAbstractDecoration *QWaylandWindow::decoration() const
{
return mWindowDecorationEnabled ? mWindowDecoration : nullptr;
return mWindowDecorationEnabled ? mWindowDecoration.get() : nullptr;
}
static QWaylandWindow *closestShellSurfaceWindow(QWindow *window)

View File

@ -270,7 +270,7 @@ protected:
QWaylandSubSurface *mSubSurfaceWindow = nullptr;
QList<QWaylandSubSurface *> mChildren;
QWaylandAbstractDecoration *mWindowDecoration = nullptr;
std::unique_ptr<QWaylandAbstractDecoration> mWindowDecoration;
bool mWindowDecorationEnabled = false;
bool mMouseEventsInContentArea = false;
Qt::MouseButtons mMousePressedInContentArea = Qt::NoButton;