forked from quickshell/quickshell
core/icon: stop reusing image ids (dbusmenu, notifications)
Fixes issues caused by the QML engine caching old pixmaps using the same IDs as new ones, notably dbusmenu icons.
This commit is contained in:
parent
c6791cf1f2
commit
cdaff2967f
8 changed files with 75 additions and 58 deletions
|
@ -1,7 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <qdbusargument.h>
|
||||
#include <qimage.h>
|
||||
#include <qobject.h>
|
||||
|
@ -23,14 +21,22 @@ struct DBusNotificationImage {
|
|||
const QDBusArgument& operator>>(const QDBusArgument& argument, DBusNotificationImage& pixmap);
|
||||
const QDBusArgument& operator<<(QDBusArgument& argument, const DBusNotificationImage& pixmap);
|
||||
|
||||
class NotificationImage: public QsImageHandle {
|
||||
class NotificationImage: public QsIndexedImageHandle {
|
||||
public:
|
||||
explicit NotificationImage(DBusNotificationImage image, QObject* parent)
|
||||
: QsImageHandle(QQuickAsyncImageProvider::Image, parent)
|
||||
, image(std::move(image)) {}
|
||||
explicit NotificationImage(): QsIndexedImageHandle(QQuickAsyncImageProvider::Image) {}
|
||||
|
||||
[[nodiscard]] bool hasData() const { return !this->image.data.isEmpty(); }
|
||||
void clear() { this->image.data.clear(); }
|
||||
|
||||
[[nodiscard]] DBusNotificationImage& writeImage() {
|
||||
this->imageChanged();
|
||||
return this->image;
|
||||
}
|
||||
|
||||
QImage requestImage(const QString& id, QSize* size, const QSize& requestedSize) override;
|
||||
|
||||
private:
|
||||
DBusNotificationImage image;
|
||||
};
|
||||
|
||||
} // namespace qs::service::notifications
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "notification.hpp"
|
||||
#include <utility>
|
||||
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qdbusargument.h>
|
||||
|
@ -117,13 +116,12 @@ void Notification::updateProperties(
|
|||
|
||||
QString imagePath;
|
||||
|
||||
if (!imageDataName.isEmpty()) {
|
||||
if (imageDataName.isEmpty()) {
|
||||
this->mImagePixmap.clear();
|
||||
} else {
|
||||
auto value = hints.value(imageDataName).value<QDBusArgument>();
|
||||
DBusNotificationImage image;
|
||||
value >> image;
|
||||
if (this->mImagePixmap) this->mImagePixmap->deleteLater();
|
||||
this->mImagePixmap = new NotificationImage(std::move(image), this);
|
||||
imagePath = this->mImagePixmap->url();
|
||||
value >> this->mImagePixmap.writeImage();
|
||||
imagePath = this->mImagePixmap.url();
|
||||
}
|
||||
|
||||
// don't store giant byte arrays longer than necessary
|
||||
|
@ -131,7 +129,7 @@ void Notification::updateProperties(
|
|||
hints.remove("image_data");
|
||||
hints.remove("icon_data");
|
||||
|
||||
if (!this->mImagePixmap) {
|
||||
if (!this->mImagePixmap.hasData()) {
|
||||
QString imagePathName;
|
||||
if (hints.contains("image-path")) imagePathName = "image-path";
|
||||
else if (hints.contains("image_path")) imagePathName = "image_path";
|
||||
|
|
|
@ -12,11 +12,10 @@
|
|||
|
||||
#include "../../core/retainable.hpp"
|
||||
#include "../../core/util.hpp"
|
||||
#include "dbusimage.hpp"
|
||||
|
||||
namespace qs::service::notifications {
|
||||
|
||||
class NotificationImage;
|
||||
|
||||
///! The urgency level of a Notification.
|
||||
/// See @@Notification.urgency.
|
||||
class NotificationUrgency: public QObject {
|
||||
|
@ -187,7 +186,7 @@ private:
|
|||
quint32 mId;
|
||||
NotificationCloseReason::Enum mCloseReason = NotificationCloseReason::Dismissed;
|
||||
bool mLastGeneration = false;
|
||||
NotificationImage* mImagePixmap = nullptr;
|
||||
NotificationImage mImagePixmap;
|
||||
QList<NotificationAction*> mActions;
|
||||
|
||||
// clang-format off
|
||||
|
|
|
@ -282,7 +282,7 @@ void StatusNotifierItem::onGetAllFailed() const {
|
|||
}
|
||||
|
||||
TrayImageHandle::TrayImageHandle(StatusNotifierItem* item)
|
||||
: QsImageHandle(QQmlImageProviderBase::Pixmap, item)
|
||||
: QsImageHandle(QQmlImageProviderBase::Pixmap)
|
||||
, item(item) {}
|
||||
|
||||
QPixmap
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue