diff --git a/autotests/integration/dont_crash_aurorae_destroy_deco.cpp b/autotests/integration/dont_crash_aurorae_destroy_deco.cpp index 32e4828d11..8119bc944e 100644 --- a/autotests/integration/dont_crash_aurorae_destroy_deco.cpp +++ b/autotests/integration/dont_crash_aurorae_destroy_deco.cpp @@ -105,7 +105,7 @@ void DontCrashAuroraeDestroyDecoTest::testBorderlessMaximizedWindows() // verify that the deco is Aurorae QCOMPARE(qstrcmp(window->decoration()->metaObject()->className(), "Aurorae::Decoration"), 0); // find the maximize button - QQuickItem *item = window->decoration()->findChild("maximizeButton"); + QQuickItem *item = window->decoration()->property("item").value()->findChild("maximizeButton"); QVERIFY(item); const QPointF scenePoint = item->mapToScene(QPoint(0, 0)); diff --git a/src/plugins/kdecorations/aurorae/src/aurorae.cpp b/src/plugins/kdecorations/aurorae/src/aurorae.cpp index a2da422732..39d228e7e1 100644 --- a/src/plugins/kdecorations/aurorae/src/aurorae.cpp +++ b/src/plugins/kdecorations/aurorae/src/aurorae.cpp @@ -256,8 +256,9 @@ Decoration::Decoration(QObject *parent, const QVariantList &args) Decoration::~Decoration() { - delete m_qmlContext; - delete m_view; + m_item.reset(); + m_qmlContext.reset(); + m_view.reset(); Helper::instance().unref(); } @@ -268,7 +269,7 @@ void Decoration::init() auto s = settings(); connect(s.data(), &KDecoration2::DecorationSettings::reconfigured, this, &Decoration::configChanged); - m_qmlContext = new QQmlContext(Helper::instance().rootContext(), this); + m_qmlContext = std::make_unique(Helper::instance().rootContext()); m_qmlContext->setContextProperty(QStringLiteral("decoration"), this); auto component = Helper::instance().component(m_themeName); if (!component) { @@ -295,7 +296,7 @@ void Decoration::init() // m_theme->setTabDragMimeType(tabDragMimeType()); m_qmlContext->setContextProperty(QStringLiteral("auroraeTheme"), theme); } - m_item = qobject_cast(component->create(m_qmlContext)); + m_item.reset(qobject_cast(component->create(m_qmlContext.get()))); if (!m_item) { if (component->isError()) { const auto errors = component->errors(); @@ -306,27 +307,25 @@ void Decoration::init() return; } - m_item->setParent(m_qmlContext); - QVariant visualParent = property("visualParent"); if (visualParent.isValid()) { m_item->setParentItem(visualParent.value()); visualParent.value()->setProperty("drawBackground", false); } else { - m_view = new KWin::OffscreenQuickView(this, KWin::OffscreenQuickView::ExportMode::Image); + m_view = std::make_unique(this, KWin::OffscreenQuickView::ExportMode::Image); m_item->setParentItem(m_view->contentItem()); auto updateSize = [this]() { m_item->setSize(m_view->contentItem()->size()); }; updateSize(); - connect(m_view->contentItem(), &QQuickItem::widthChanged, m_item, updateSize); - connect(m_view->contentItem(), &QQuickItem::heightChanged, m_item, updateSize); - connect(m_view, &KWin::OffscreenQuickView::repaintNeeded, this, &Decoration::updateBuffer); + connect(m_view->contentItem(), &QQuickItem::widthChanged, m_item.get(), updateSize); + connect(m_view->contentItem(), &QQuickItem::heightChanged, m_item.get(), updateSize); + connect(m_view.get(), &KWin::OffscreenQuickView::repaintNeeded, this, &Decoration::updateBuffer); } m_supportsMask = m_item->property("supportsMask").toBool(); - setupBorders(m_item); + setupBorders(m_item.get()); // TODO: Is there a more efficient way to react to border changes? auto trackBorders = [this](KWin::Borders *borders) { @@ -619,6 +618,11 @@ KDecoration2::DecoratedClient *Decoration::clientPointer() const return client().toStrongRef().data(); } +QQuickItem *Decoration::item() const +{ + return m_item.get(); +} + ThemeProvider::ThemeProvider(QObject *parent, const KPluginMetaData &data, const QVariantList &args) : KDecoration2::DecorationThemeProvider(parent, data, args) , m_data(data) diff --git a/src/plugins/kdecorations/aurorae/src/aurorae.h b/src/plugins/kdecorations/aurorae/src/aurorae.h index 4980c13cbf..51cd342725 100644 --- a/src/plugins/kdecorations/aurorae/src/aurorae.h +++ b/src/plugins/kdecorations/aurorae/src/aurorae.h @@ -34,6 +34,7 @@ class Decoration : public KDecoration2::Decoration { Q_OBJECT Q_PROPERTY(KDecoration2::DecoratedClient *client READ clientPointer CONSTANT) + Q_PROPERTY(QQuickItem *item READ item) public: explicit Decoration(QObject *parent = nullptr, const QVariantList &args = QVariantList()); ~Decoration() override; @@ -43,6 +44,7 @@ public: Q_INVOKABLE QVariant readConfig(const QString &key, const QVariant &defaultValue = QVariant()); KDecoration2::DecoratedClient *clientPointer() const; + QQuickItem *item() const; public Q_SLOTS: void init() override; @@ -71,15 +73,15 @@ private: bool m_supportsMask{false}; QRect m_contentRect; // the geometry of the part of the buffer that is not a shadow when buffer was created. - QQuickItem *m_item = nullptr; - QQmlContext *m_qmlContext = nullptr; + std::unique_ptr m_item; + std::unique_ptr m_qmlContext; KWin::Borders *m_borders; KWin::Borders *m_maximizedBorders; KWin::Borders *m_extendedBorders; KWin::Borders *m_padding; QString m_themeName; - KWin::OffscreenQuickView *m_view; + std::unique_ptr m_view; }; class ThemeProvider : public KDecoration2::DecorationThemeProvider diff --git a/src/plugins/kdecorations/aurorae/src/lib/auroraetheme.cpp b/src/plugins/kdecorations/aurorae/src/lib/auroraetheme.cpp index a5a1ca975e..b28ef59f81 100644 --- a/src/plugins/kdecorations/aurorae/src/lib/auroraetheme.cpp +++ b/src/plugins/kdecorations/aurorae/src/lib/auroraetheme.cpp @@ -72,16 +72,13 @@ void AuroraeThemePrivate::initButtonFrame(AuroraeButtonType type) ************************************************/ AuroraeTheme::AuroraeTheme(QObject *parent) : QObject(parent) - , d(new AuroraeThemePrivate) + , d(std::make_unique()) { connect(this, &AuroraeTheme::themeChanged, this, &AuroraeTheme::borderSizesChanged); connect(this, &AuroraeTheme::buttonSizesChanged, this, &AuroraeTheme::borderSizesChanged); } -AuroraeTheme::~AuroraeTheme() -{ - delete d; -} +AuroraeTheme::~AuroraeTheme() = default; bool AuroraeTheme::isValid() const { diff --git a/src/plugins/kdecorations/aurorae/src/lib/auroraetheme.h b/src/plugins/kdecorations/aurorae/src/lib/auroraetheme.h index 5043997c2b..59a4a366a6 100644 --- a/src/plugins/kdecorations/aurorae/src/lib/auroraetheme.h +++ b/src/plugins/kdecorations/aurorae/src/lib/auroraetheme.h @@ -210,7 +210,7 @@ private: */ void padding(int &left, int &top, int &right, int &bottom) const; - AuroraeThemePrivate *const d; + const std::unique_ptr d; }; } // namespace diff --git a/src/plugins/nightcolor/nightcolormanager.cpp b/src/plugins/nightcolor/nightcolormanager.cpp index 9c75a95b2e..4864c2313b 100644 --- a/src/plugins/nightcolor/nightcolormanager.cpp +++ b/src/plugins/nightcolor/nightcolormanager.cpp @@ -313,13 +313,9 @@ void NightColorManager::resetAllTimers() void NightColorManager::cancelAllTimers() { - delete m_slowUpdateStartTimer; - delete m_slowUpdateTimer; - delete m_quickAdjustTimer; - - m_slowUpdateStartTimer = nullptr; - m_slowUpdateTimer = nullptr; - m_quickAdjustTimer = nullptr; + m_slowUpdateStartTimer.reset(); + m_slowUpdateTimer.reset(); + m_quickAdjustTimer.reset(); } void NightColorManager::resetQuickAdjustTimer(int targetTemp) @@ -328,9 +324,9 @@ void NightColorManager::resetQuickAdjustTimer(int targetTemp) // allow tolerance of one TEMPERATURE_STEP to compensate if a slow update is coincidental if (tempDiff > TEMPERATURE_STEP) { cancelAllTimers(); - m_quickAdjustTimer = new QTimer(this); + m_quickAdjustTimer = std::make_unique(); m_quickAdjustTimer->setSingleShot(false); - connect(m_quickAdjustTimer, &QTimer::timeout, this, [this, targetTemp]() { + connect(m_quickAdjustTimer.get(), &QTimer::timeout, this, [this, targetTemp]() { quickAdjust(targetTemp); }); @@ -361,16 +357,14 @@ void NightColorManager::quickAdjust(int targetTemp) if (nextTemp == targetTemp) { // stop timer, we reached the target temp - delete m_quickAdjustTimer; - m_quickAdjustTimer = nullptr; + m_quickAdjustTimer.reset(); resetSlowUpdateStartTimer(); } } void NightColorManager::resetSlowUpdateStartTimer() { - delete m_slowUpdateStartTimer; - m_slowUpdateStartTimer = nullptr; + m_slowUpdateStartTimer.reset(); if (!m_running || m_quickAdjustTimer) { // only reenable the slow update start timer when quick adjust is not active anymore @@ -384,9 +378,9 @@ void NightColorManager::resetSlowUpdateStartTimer() } // set up the next slow update - m_slowUpdateStartTimer = new QTimer(this); + m_slowUpdateStartTimer = std::make_unique(); m_slowUpdateStartTimer->setSingleShot(true); - connect(m_slowUpdateStartTimer, &QTimer::timeout, this, &NightColorManager::resetSlowUpdateStartTimer); + connect(m_slowUpdateStartTimer.get(), &QTimer::timeout, this, &NightColorManager::resetSlowUpdateStartTimer); updateTransitionTimings(false); updateTargetTemperature(); @@ -404,8 +398,7 @@ void NightColorManager::resetSlowUpdateStartTimer() void NightColorManager::resetSlowUpdateTimer() { - delete m_slowUpdateTimer; - m_slowUpdateTimer = nullptr; + m_slowUpdateTimer.reset(); const QDateTime now = QDateTime::currentDateTime(); const bool isDay = daylight(); @@ -419,14 +412,14 @@ void NightColorManager::resetSlowUpdateTimer() if (m_prev.first <= now && now <= m_prev.second) { int availTime = now.msecsTo(m_prev.second); - m_slowUpdateTimer = new QTimer(this); + m_slowUpdateTimer = std::make_unique(); m_slowUpdateTimer->setSingleShot(false); if (isDay) { - connect(m_slowUpdateTimer, &QTimer::timeout, this, [this]() { + connect(m_slowUpdateTimer.get(), &QTimer::timeout, this, [this]() { slowUpdate(m_dayTargetTemp); }); } else { - connect(m_slowUpdateTimer, &QTimer::timeout, this, [this]() { + connect(m_slowUpdateTimer.get(), &QTimer::timeout, this, [this]() { slowUpdate(m_nightTargetTemp); }); } @@ -454,8 +447,7 @@ void NightColorManager::slowUpdate(int targetTemp) commitGammaRamps(nextTemp); if (nextTemp == targetTemp) { // stop timer, we reached the target temp - delete m_slowUpdateTimer; - m_slowUpdateTimer = nullptr; + m_slowUpdateTimer.reset(); } } @@ -463,12 +455,11 @@ void NightColorManager::preview(uint previewTemp) { resetQuickAdjustTimer((int)previewTemp); if (m_previewTimer) { - delete m_previewTimer; - m_previewTimer = nullptr; + m_previewTimer.reset(); } - m_previewTimer = new QTimer(this); + m_previewTimer = std::make_unique(); m_previewTimer->setSingleShot(true); - connect(m_previewTimer, &QTimer::timeout, this, &NightColorManager::stopPreview); + connect(m_previewTimer.get(), &QTimer::timeout, this, &NightColorManager::stopPreview); m_previewTimer->start(15000); QDBusMessage message = QDBusMessage::createMethodCall( diff --git a/src/plugins/nightcolor/nightcolormanager.h b/src/plugins/nightcolor/nightcolormanager.h index c8a8f9a533..93a253f583 100644 --- a/src/plugins/nightcolor/nightcolormanager.h +++ b/src/plugins/nightcolor/nightcolormanager.h @@ -290,10 +290,10 @@ private: double m_latFixed; double m_lngFixed; - QTimer *m_slowUpdateStartTimer = nullptr; - QTimer *m_slowUpdateTimer = nullptr; - QTimer *m_quickAdjustTimer = nullptr; - QTimer *m_previewTimer = nullptr; + std::unique_ptr m_slowUpdateStartTimer; + std::unique_ptr m_slowUpdateTimer; + std::unique_ptr m_quickAdjustTimer; + std::unique_ptr m_previewTimer; int m_currentTemp = DEFAULT_DAY_TEMPERATURE; int m_targetTemperature = DEFAULT_DAY_TEMPERATURE; diff --git a/src/plugins/screencast/screencaststream.cpp b/src/plugins/screencast/screencaststream.cpp index 0b48e09d3e..52a6b3b7de 100644 --- a/src/plugins/screencast/screencaststream.cpp +++ b/src/plugins/screencast/screencaststream.cpp @@ -578,15 +578,14 @@ void ScreenCastStream::tryEnqueue(pw_buffer *buffer) // a corrupted buffer. if (Compositor::self()->scene()->supportsNativeFence()) { Q_ASSERT_X(eglGetCurrentContext(), "tryEnqueue", "no current context"); - m_pendingFence = new EGLNativeFence(kwinApp()->outputBackend()->sceneEglDisplay()); + m_pendingFence = std::make_unique(kwinApp()->outputBackend()->sceneEglDisplay()); if (!m_pendingFence->isValid()) { qCWarning(KWIN_SCREENCAST) << "Failed to create a native EGL fence"; glFinish(); enqueue(); } else { - m_pendingNotifier = new QSocketNotifier(m_pendingFence->fileDescriptor(), - QSocketNotifier::Read, this); - connect(m_pendingNotifier, &QSocketNotifier::activated, this, &ScreenCastStream::enqueue); + m_pendingNotifier = std::make_unique(m_pendingFence->fileDescriptor(), QSocketNotifier::Read); + connect(m_pendingNotifier.get(), &QSocketNotifier::activated, this, &ScreenCastStream::enqueue); } } else { // The compositing backend doesn't support native fences. We don't have any other choice @@ -600,14 +599,12 @@ void ScreenCastStream::enqueue() { Q_ASSERT_X(m_pendingBuffer, "enqueue", "pending buffer must be valid"); - delete m_pendingFence; - delete m_pendingNotifier; + m_pendingFence.reset(); + m_pendingNotifier.reset(); pw_stream_queue_buffer(pwStream, m_pendingBuffer); m_pendingBuffer = nullptr; - m_pendingFence = nullptr; - m_pendingNotifier = nullptr; } QVector ScreenCastStream::buildFormats(bool fixate, char buffer[2048]) diff --git a/src/plugins/screencast/screencaststream.h b/src/plugins/screencast/screencaststream.h index e1e713bc0f..c6483fd8bc 100644 --- a/src/plugins/screencast/screencaststream.h +++ b/src/plugins/screencast/screencaststream.h @@ -121,8 +121,8 @@ private: QHash> m_dmabufDataForPwBuffer; pw_buffer *m_pendingBuffer = nullptr; - QSocketNotifier *m_pendingNotifier = nullptr; - EGLNativeFence *m_pendingFence = nullptr; + std::unique_ptr m_pendingNotifier; + std::unique_ptr m_pendingFence; std::optional m_start; quint64 m_sequential = 0; bool m_hasDmaBuf = false;