forked from quickshell/quickshell
service/tray: rework tray image providers
This commit is contained in:
parent
aa9f8cd001
commit
7cc1b54587
10 changed files with 163 additions and 82 deletions
|
@ -27,7 +27,6 @@ qt_add_dbus_interface(DBUS_INTERFACES
|
|||
|
||||
qt_add_library(quickshell-service-statusnotifier STATIC
|
||||
qml.cpp
|
||||
trayimageprovider.cpp
|
||||
|
||||
watcher.cpp
|
||||
host.cpp
|
||||
|
@ -36,8 +35,6 @@ qt_add_library(quickshell-service-statusnotifier STATIC
|
|||
${DBUS_INTERFACES}
|
||||
)
|
||||
|
||||
add_library(quickshell-service-statusnotifier-init OBJECT init.cpp)
|
||||
|
||||
# dbus headers
|
||||
target_include_directories(quickshell-service-statusnotifier PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
|
@ -47,9 +44,7 @@ qt_add_qml_module(quickshell-service-statusnotifier
|
|||
)
|
||||
|
||||
target_link_libraries(quickshell-service-statusnotifier PRIVATE ${QT_DEPS} quickshell-dbus)
|
||||
target_link_libraries(quickshell-service-statusnotifier-init PRIVATE ${QT_DEPS})
|
||||
target_link_libraries(quickshell PRIVATE quickshell-service-statusnotifierplugin quickshell-service-statusnotifier-init)
|
||||
target_link_libraries(quickshell PRIVATE quickshell-service-statusnotifierplugin)
|
||||
|
||||
qs_pch(quickshell-service-statusnotifier)
|
||||
qs_pch(quickshell-service-statusnotifierplugin)
|
||||
qs_pch(quickshell-service-statusnotifier-init)
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
#include "../../core/generation.hpp"
|
||||
#include "../../core/plugin.hpp"
|
||||
#include "trayimageprovider.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
class SniPlugin: public QuickshellPlugin {
|
||||
void constructGeneration(EngineGeneration& generation) override {
|
||||
generation.engine->addImageProvider("service.sni", new qs::service::sni::TrayImageProvider());
|
||||
}
|
||||
};
|
||||
|
||||
QS_REGISTER_PLUGIN(SniPlugin);
|
||||
|
||||
} // namespace
|
|
@ -11,12 +11,15 @@
|
|||
#include <qobject.h>
|
||||
#include <qpainter.h>
|
||||
#include <qpixmap.h>
|
||||
#include <qqmlengine.h>
|
||||
#include <qrect.h>
|
||||
#include <qsize.h>
|
||||
#include <qstring.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "../../core/iconimageprovider.hpp"
|
||||
#include "../../core/imageprovider.hpp"
|
||||
#include "../../dbus/properties.hpp"
|
||||
#include "dbus_item.h"
|
||||
#include "dbus_item_types.hpp"
|
||||
|
@ -94,7 +97,7 @@ QString StatusNotifierItem::iconId() const {
|
|||
return IconImageProvider::requestString(name, this->iconThemePath.get());
|
||||
}
|
||||
|
||||
return QString("image://service.sni/") + this->watcherId + "/" + QString::number(this->iconIndex);
|
||||
return this->imageHandle.url() + "/" + QString::number(this->iconIndex);
|
||||
}
|
||||
|
||||
QPixmap StatusNotifierItem::createPixmap(const QSize& size) const {
|
||||
|
@ -230,4 +233,22 @@ void StatusNotifierItem::onGetAllFinished() {
|
|||
emit this->ready();
|
||||
}
|
||||
|
||||
TrayImageHandle::TrayImageHandle(StatusNotifierItem* item)
|
||||
: QsImageHandle(QQmlImageProviderBase::Pixmap, item)
|
||||
, item(item) {}
|
||||
|
||||
QPixmap
|
||||
TrayImageHandle::requestPixmap(const QString& /*unused*/, QSize* size, const QSize& requestedSize) {
|
||||
auto targetSize = requestedSize.isValid() ? requestedSize : QSize(100, 100);
|
||||
if (targetSize.width() == 0 || targetSize.height() == 0) targetSize = QSize(2, 2);
|
||||
|
||||
auto pixmap = this->item->createPixmap(targetSize);
|
||||
if (pixmap.isNull()) {
|
||||
pixmap = IconImageProvider::missingPixmap(targetSize);
|
||||
}
|
||||
|
||||
if (size != nullptr) *size = pixmap.size();
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
} // namespace qs::service::sni
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "../../core/imageprovider.hpp"
|
||||
#include "../../dbus/properties.hpp"
|
||||
#include "dbus_item.h"
|
||||
#include "dbus_item_types.hpp"
|
||||
|
@ -17,6 +18,18 @@ Q_DECLARE_LOGGING_CATEGORY(logStatusNotifierItem);
|
|||
|
||||
namespace qs::service::sni {
|
||||
|
||||
class StatusNotifierItem;
|
||||
|
||||
class TrayImageHandle: public QsImageHandle {
|
||||
public:
|
||||
explicit TrayImageHandle(StatusNotifierItem* item);
|
||||
|
||||
QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;
|
||||
|
||||
public:
|
||||
StatusNotifierItem* item;
|
||||
};
|
||||
|
||||
class StatusNotifierItem: public QObject {
|
||||
Q_OBJECT;
|
||||
|
||||
|
@ -62,6 +75,7 @@ private slots:
|
|||
|
||||
private:
|
||||
DBusStatusNotifierItem* item = nullptr;
|
||||
TrayImageHandle imageHandle {this};
|
||||
bool mReady = false;
|
||||
|
||||
// bumped to inhibit caching
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
#include "trayimageprovider.hpp"
|
||||
|
||||
#include <qlogging.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qpixmap.h>
|
||||
#include <qsize.h>
|
||||
#include <qstring.h>
|
||||
|
||||
#include "../../core/iconimageprovider.hpp"
|
||||
#include "host.hpp"
|
||||
|
||||
namespace qs::service::sni {
|
||||
|
||||
QPixmap
|
||||
TrayImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) {
|
||||
QPixmap pixmap;
|
||||
|
||||
auto targetSize = requestedSize.isValid() ? requestedSize : QSize(100, 100);
|
||||
if (targetSize.width() == 0 || targetSize.height() == 0) targetSize = QSize(2, 2);
|
||||
|
||||
auto lastSplit = id.lastIndexOf('/');
|
||||
if (lastSplit == -1) {
|
||||
qCWarning(logStatusNotifierHost) << "Invalid image request:" << id;
|
||||
} else {
|
||||
auto path = id.sliced(0, lastSplit);
|
||||
|
||||
auto* item = StatusNotifierHost::instance()->itemByService(path);
|
||||
|
||||
if (item == nullptr) {
|
||||
qCWarning(logStatusNotifierHost) << "Image requested for nonexistant service" << path;
|
||||
} else {
|
||||
pixmap = item->createPixmap(targetSize);
|
||||
}
|
||||
}
|
||||
|
||||
if (pixmap.isNull()) {
|
||||
pixmap = IconImageProvider::missingPixmap(targetSize);
|
||||
}
|
||||
|
||||
if (size != nullptr) *size = pixmap.size();
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
} // namespace qs::service::sni
|
|
@ -1,16 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <qpixmap.h>
|
||||
#include <qquickimageprovider.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
namespace qs::service::sni {
|
||||
|
||||
class TrayImageProvider: public QQuickImageProvider {
|
||||
public:
|
||||
explicit TrayImageProvider(): QQuickImageProvider(QQuickImageProvider::Pixmap) {}
|
||||
|
||||
QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;
|
||||
};
|
||||
|
||||
} // namespace qs::service::sni
|
Loading…
Add table
Add a link
Reference in a new issue