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:
parent
c50ebcd83d
commit
279406aa20
@ -72,7 +72,7 @@ QWaylandWindow::QWaylandWindow(QWindow *window, QWaylandDisplay *display)
|
|||||||
|
|
||||||
QWaylandWindow::~QWaylandWindow()
|
QWaylandWindow::~QWaylandWindow()
|
||||||
{
|
{
|
||||||
delete mWindowDecoration;
|
mWindowDecoration.reset();
|
||||||
|
|
||||||
if (mSurface)
|
if (mSurface)
|
||||||
reset();
|
reset();
|
||||||
@ -1064,8 +1064,7 @@ bool QWaylandWindow::createDecoration()
|
|||||||
if (decoration && !decorationPluginFailed) {
|
if (decoration && !decorationPluginFailed) {
|
||||||
if (!mWindowDecorationEnabled) {
|
if (!mWindowDecorationEnabled) {
|
||||||
if (mWindowDecoration) {
|
if (mWindowDecoration) {
|
||||||
delete mWindowDecoration;
|
mWindowDecoration.reset();
|
||||||
mWindowDecoration = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList decorations = QWaylandDecorationFactory::keys();
|
QStringList decorations = QWaylandDecorationFactory::keys();
|
||||||
@ -1104,8 +1103,7 @@ bool QWaylandWindow::createDecoration()
|
|||||||
if (targetKey.isEmpty())
|
if (targetKey.isEmpty())
|
||||||
targetKey = decorations.first(); // first come, first served.
|
targetKey = decorations.first(); // first come, first served.
|
||||||
|
|
||||||
|
mWindowDecoration.reset(QWaylandDecorationFactory::create(targetKey, QStringList()));
|
||||||
mWindowDecoration = QWaylandDecorationFactory::create(targetKey, QStringList());
|
|
||||||
if (!mWindowDecoration) {
|
if (!mWindowDecoration) {
|
||||||
qWarning() << "Could not create decoration from factory! Running with no decorations.";
|
qWarning() << "Could not create decoration from factory! Running with no decorations.";
|
||||||
decorationPluginFailed = true;
|
decorationPluginFailed = true;
|
||||||
@ -1137,12 +1135,12 @@ bool QWaylandWindow::createDecoration()
|
|||||||
window()->requestUpdate();
|
window()->requestUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
return mWindowDecoration;
|
return mWindowDecoration.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
QWaylandAbstractDecoration *QWaylandWindow::decoration() const
|
QWaylandAbstractDecoration *QWaylandWindow::decoration() const
|
||||||
{
|
{
|
||||||
return mWindowDecorationEnabled ? mWindowDecoration : nullptr;
|
return mWindowDecorationEnabled ? mWindowDecoration.get() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QWaylandWindow *closestShellSurfaceWindow(QWindow *window)
|
static QWaylandWindow *closestShellSurfaceWindow(QWindow *window)
|
||||||
|
@ -270,7 +270,7 @@ protected:
|
|||||||
QWaylandSubSurface *mSubSurfaceWindow = nullptr;
|
QWaylandSubSurface *mSubSurfaceWindow = nullptr;
|
||||||
QList<QWaylandSubSurface *> mChildren;
|
QList<QWaylandSubSurface *> mChildren;
|
||||||
|
|
||||||
QWaylandAbstractDecoration *mWindowDecoration = nullptr;
|
std::unique_ptr<QWaylandAbstractDecoration> mWindowDecoration;
|
||||||
bool mWindowDecorationEnabled = false;
|
bool mWindowDecorationEnabled = false;
|
||||||
bool mMouseEventsInContentArea = false;
|
bool mMouseEventsInContentArea = false;
|
||||||
Qt::MouseButtons mMousePressedInContentArea = Qt::NoButton;
|
Qt::MouseButtons mMousePressedInContentArea = Qt::NoButton;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user