plugins: use more std::unique_ptr
This commit is contained in:
parent
738b04a364
commit
34aa734c7b
9 changed files with 52 additions and 61 deletions
|
@ -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<QQuickItem *>("maximizeButton");
|
||||
QQuickItem *item = window->decoration()->property("item").value<QQuickItem *>()->findChild<QQuickItem *>("maximizeButton");
|
||||
QVERIFY(item);
|
||||
const QPointF scenePoint = item->mapToScene(QPoint(0, 0));
|
||||
|
||||
|
|
|
@ -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<QQmlContext>(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<QQuickItem *>(component->create(m_qmlContext));
|
||||
m_item.reset(qobject_cast<QQuickItem *>(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<QQuickItem *>());
|
||||
visualParent.value<QQuickItem *>()->setProperty("drawBackground", false);
|
||||
} else {
|
||||
m_view = new KWin::OffscreenQuickView(this, KWin::OffscreenQuickView::ExportMode::Image);
|
||||
m_view = std::make_unique<KWin::OffscreenQuickView>(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)
|
||||
|
|
|
@ -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<QQuickItem> m_item;
|
||||
std::unique_ptr<QQmlContext> 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<KWin::OffscreenQuickView> m_view;
|
||||
};
|
||||
|
||||
class ThemeProvider : public KDecoration2::DecorationThemeProvider
|
||||
|
|
|
@ -72,16 +72,13 @@ void AuroraeThemePrivate::initButtonFrame(AuroraeButtonType type)
|
|||
************************************************/
|
||||
AuroraeTheme::AuroraeTheme(QObject *parent)
|
||||
: QObject(parent)
|
||||
, d(new AuroraeThemePrivate)
|
||||
, d(std::make_unique<AuroraeThemePrivate>())
|
||||
{
|
||||
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
|
||||
{
|
||||
|
|
|
@ -210,7 +210,7 @@ private:
|
|||
*/
|
||||
void padding(int &left, int &top, int &right, int &bottom) const;
|
||||
|
||||
AuroraeThemePrivate *const d;
|
||||
const std::unique_ptr<AuroraeThemePrivate> d;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -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<QTimer>();
|
||||
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<QTimer>();
|
||||
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<QTimer>();
|
||||
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<QTimer>();
|
||||
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(
|
||||
|
|
|
@ -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<QTimer> m_slowUpdateStartTimer;
|
||||
std::unique_ptr<QTimer> m_slowUpdateTimer;
|
||||
std::unique_ptr<QTimer> m_quickAdjustTimer;
|
||||
std::unique_ptr<QTimer> m_previewTimer;
|
||||
|
||||
int m_currentTemp = DEFAULT_DAY_TEMPERATURE;
|
||||
int m_targetTemperature = DEFAULT_DAY_TEMPERATURE;
|
||||
|
|
|
@ -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<EGLNativeFence>(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<QSocketNotifier>(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<const spa_pod *> ScreenCastStream::buildFormats(bool fixate, char buffer[2048])
|
||||
|
|
|
@ -121,8 +121,8 @@ private:
|
|||
QHash<struct pw_buffer *, std::shared_ptr<DmaBufTexture>> m_dmabufDataForPwBuffer;
|
||||
|
||||
pw_buffer *m_pendingBuffer = nullptr;
|
||||
QSocketNotifier *m_pendingNotifier = nullptr;
|
||||
EGLNativeFence *m_pendingFence = nullptr;
|
||||
std::unique_ptr<QSocketNotifier> m_pendingNotifier;
|
||||
std::unique_ptr<EGLNativeFence> m_pendingFence;
|
||||
std::optional<std::chrono::nanoseconds> m_start;
|
||||
quint64 m_sequential = 0;
|
||||
bool m_hasDmaBuf = false;
|
||||
|
|
Loading…
Reference in a new issue