From eabeace2839cd0ef6755a95fd459f9f7391b2471 Mon Sep 17 00:00:00 2001 From: reionwong Date: Tue, 29 Mar 2022 22:31:27 +0800 Subject: [PATCH] fix: optimize memory --- qml/main.qml | 12 +++++------ src/backgroundhelper.cpp | 24 +++++++++++++++++++++ src/backgroundhelper.h | 6 ++++++ src/systemtray/statusnotifieritemsource.cpp | 1 + src/systemtray/systemtraymodel.cpp | 4 +++- 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/qml/main.qml b/qml/main.qml index fb841cc..e6f59e0 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -79,12 +79,12 @@ Item { // color: FishUI.Theme.darkMode ? "#4D4D4D" : "#FFFFFF" // opacity: windowHelper.compositing ? FishUI.Theme.darkMode ? 0.5 : 0.7 : 1.0 - Behavior on color { - ColorAnimation { - duration: 100 - easing.type: Easing.Linear - } - } +// Behavior on color { +// ColorAnimation { +// duration: 100 +// easing.type: Easing.Linear +// } +// } } FishUI.WindowHelper { diff --git a/src/backgroundhelper.cpp b/src/backgroundhelper.cpp index aebe521..1e7eb7b 100644 --- a/src/backgroundhelper.cpp +++ b/src/backgroundhelper.cpp @@ -22,22 +22,29 @@ #include #include #include +#include #include #include BackgroundHelper::BackgroundHelper(QObject *parent) : QObject(parent) , m_statusBarHeight(25 / qApp->devicePixelRatio()) + , m_type(0) { } void BackgroundHelper::setColor(QColor c) { + m_color = c; + m_type = 1; emit newColor(c, c.lightness()); } void BackgroundHelper::setBackgound(const QString &fileName) { + m_wallpaper = fileName; + m_type = 0; + QImage img(fileName); QSize screenSize = qApp->primaryScreen()->geometry().size(); @@ -68,4 +75,21 @@ void BackgroundHelper::setBackgound(const QString &fileName) QColor c = QColor(sumR, sumG, sumB); emit newColor(c, c.lightness()); + + // clear cache. + QPixmapCache::clear(); +} + +void BackgroundHelper::onChanged() +{ + switch (m_type) { + case 0: + setBackgound(m_wallpaper); + break; + case 1: + setColor(m_color); + break; + default: + break; + } } diff --git a/src/backgroundhelper.h b/src/backgroundhelper.h index 8a93f2f..bb0344c 100644 --- a/src/backgroundhelper.h +++ b/src/backgroundhelper.h @@ -33,11 +33,17 @@ public: Q_INVOKABLE void setColor(QColor c); Q_INVOKABLE void setBackgound(const QString &fileName); +private slots: + void onChanged(); + signals: void newColor(QColor color, int lightness); private: int m_statusBarHeight; + int m_type; + QColor m_color; + QString m_wallpaper; }; #endif // BACKGROUNDHELPER_H diff --git a/src/systemtray/statusnotifieritemsource.cpp b/src/systemtray/statusnotifieritemsource.cpp index 8302759..59a03bc 100644 --- a/src/systemtray/statusnotifieritemsource.cpp +++ b/src/systemtray/statusnotifieritemsource.cpp @@ -273,6 +273,7 @@ void StatusNotifierItemSource::refreshCallback(QDBusPendingCallWatcher *call) m_iconName = id; } m_appId = id; + // qDebug() << m_appId; // Reion: For icon theme path QString iconThemePath = properties[QStringLiteral("IconThemePath")].toString(); diff --git a/src/systemtray/systemtraymodel.cpp b/src/systemtray/systemtraymodel.cpp index 1c54258..3d51177 100644 --- a/src/systemtray/systemtraymodel.cpp +++ b/src/systemtray/systemtraymodel.cpp @@ -27,7 +27,9 @@ static QStringList noColorOverlayList = { "netease-cloud-music", - "chrome_status_icon_1" + "chrome_status_icon_1", + "35682", // obs studio + "lark_status_icon_1" }; SystemTrayModel::SystemTrayModel(QObject *parent)