diff --git a/src/plugins/platforms/wayland/qwaylanddisplay.cpp b/src/plugins/platforms/wayland/qwaylanddisplay.cpp index 1c2b47da522..0199e169d73 100644 --- a/src/plugins/platforms/wayland/qwaylanddisplay.cpp +++ b/src/plugins/platforms/wayland/qwaylanddisplay.cpp @@ -238,7 +238,6 @@ void QWaylandDisplay::registry_global(uint32_t id, const QString &interface, uin mScreens.append(screen); // We need to get the output events before creating surfaces forceRoundTrip(); - screen->init(); mWaylandIntegration->screenAdded(screen); } else if (interface == QStringLiteral("wl_compositor")) { mCompositorVersion = qMin((int)version, 3); diff --git a/src/plugins/platforms/wayland/qwaylandscreen.cpp b/src/plugins/platforms/wayland/qwaylandscreen.cpp index 38d97a91dfb..37fe5f3234b 100644 --- a/src/plugins/platforms/wayland/qwaylandscreen.cpp +++ b/src/plugins/platforms/wayland/qwaylandscreen.cpp @@ -60,20 +60,6 @@ QWaylandScreen::QWaylandScreen(QWaylandDisplay *waylandDisplay, int version, uin { } -QWaylandScreen::~QWaylandScreen() -{ -#if QT_CONFIG(cursor) - delete mWaylandCursor; -#endif -} - -void QWaylandScreen::init() -{ -#if QT_CONFIG(cursor) - mWaylandCursor = new QWaylandCursor(this); -#endif -} - QWaylandDisplay * QWaylandScreen::display() const { return mWaylandDisplay; @@ -165,11 +151,20 @@ qreal QWaylandScreen::refreshRate() const } #if QT_CONFIG(cursor) + QPlatformCursor *QWaylandScreen::cursor() const { - return mWaylandCursor; + return const_cast(this)->waylandCursor(); } -#endif + +QWaylandCursor *QWaylandScreen::waylandCursor() +{ + if (!mWaylandCursor) + mWaylandCursor.reset(new QWaylandCursor(this)); + return mWaylandCursor.data(); +} + +#endif // QT_CONFIG(cursor) QWaylandScreen * QWaylandScreen::waylandScreenFromWindow(QWindow *window) { diff --git a/src/plugins/platforms/wayland/qwaylandscreen_p.h b/src/plugins/platforms/wayland/qwaylandscreen_p.h index 9df55d60340..39b72bc2443 100644 --- a/src/plugins/platforms/wayland/qwaylandscreen_p.h +++ b/src/plugins/platforms/wayland/qwaylandscreen_p.h @@ -67,9 +67,7 @@ class Q_WAYLAND_CLIENT_EXPORT QWaylandScreen : public QPlatformScreen, QtWayland { public: QWaylandScreen(QWaylandDisplay *waylandDisplay, int version, uint32_t id); - ~QWaylandScreen() override; - void init(); QWaylandDisplay *display() const; QString manufacturer() const override; @@ -95,7 +93,7 @@ public: #if QT_CONFIG(cursor) QPlatformCursor *cursor() const override; - QWaylandCursor *waylandCursor() const { return mWaylandCursor; } + QWaylandCursor *waylandCursor(); #endif uint32_t outputId() const { return m_outputId; } @@ -130,7 +128,7 @@ private: Qt::ScreenOrientation m_orientation = Qt::PrimaryOrientation; #if QT_CONFIG(cursor) - QWaylandCursor *mWaylandCursor = nullptr; + QScopedPointer mWaylandCursor; #endif };