forked from quickshell/quickshell
dbus/dbusmenu: add DBusMenu support
This commit is contained in:
parent
7cc1b54587
commit
61061644a5
13 changed files with 984 additions and 11 deletions
|
@ -43,7 +43,7 @@ qt_add_qml_module(quickshell-service-statusnotifier
|
|||
VERSION 0.1
|
||||
)
|
||||
|
||||
target_link_libraries(quickshell-service-statusnotifier PRIVATE ${QT_DEPS} quickshell-dbus)
|
||||
target_link_libraries(quickshell-service-statusnotifier PRIVATE ${QT_DEPS} quickshell-dbus quickshell-dbusmenuplugin)
|
||||
target_link_libraries(quickshell PRIVATE quickshell-service-statusnotifierplugin)
|
||||
|
||||
qs_pch(quickshell-service-statusnotifier)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "item.hpp"
|
||||
#include <utility>
|
||||
|
||||
#include <qdbusextratypes.h>
|
||||
#include <qdbusmetatype.h>
|
||||
#include <qdbuspendingcall.h>
|
||||
#include <qdbuspendingreply.h>
|
||||
|
@ -20,12 +21,14 @@
|
|||
|
||||
#include "../../core/iconimageprovider.hpp"
|
||||
#include "../../core/imageprovider.hpp"
|
||||
#include "../../dbus/dbusmenu/dbusmenu.hpp"
|
||||
#include "../../dbus/properties.hpp"
|
||||
#include "dbus_item.h"
|
||||
#include "dbus_item_types.hpp"
|
||||
#include "host.hpp"
|
||||
|
||||
using namespace qs::dbus;
|
||||
using namespace qs::dbus::dbusmenu;
|
||||
|
||||
Q_LOGGING_CATEGORY(logStatusNotifierItem, "quickshell.service.sni.item", QtWarningMsg);
|
||||
|
||||
|
@ -34,6 +37,10 @@ namespace qs::service::sni {
|
|||
StatusNotifierItem::StatusNotifierItem(const QString& address, QObject* parent)
|
||||
: QObject(parent)
|
||||
, watcherId(address) {
|
||||
qDBusRegisterMetaType<DBusSniIconPixmap>();
|
||||
qDBusRegisterMetaType<DBusSniIconPixmapList>();
|
||||
qDBusRegisterMetaType<DBusSniTooltip>();
|
||||
|
||||
// spec is unclear about what exactly an item address is, so account for both combinations
|
||||
auto splitIdx = address.indexOf('/');
|
||||
auto conn = splitIdx == -1 ? address : address.sliced(0, splitIdx);
|
||||
|
@ -46,10 +53,6 @@ StatusNotifierItem::StatusNotifierItem(const QString& address, QObject* parent)
|
|||
return;
|
||||
}
|
||||
|
||||
qDBusRegisterMetaType<DBusSniIconPixmap>();
|
||||
qDBusRegisterMetaType<DBusSniIconPixmapList>();
|
||||
qDBusRegisterMetaType<DBusSniTooltip>();
|
||||
|
||||
// clang-format off
|
||||
QObject::connect(this->item, &DBusStatusNotifierItem::NewTitle, &this->title, &AbstractDBusProperty::update);
|
||||
QObject::connect(this->item, &DBusStatusNotifierItem::NewIcon, &this->iconName, &AbstractDBusProperty::update);
|
||||
|
@ -227,6 +230,15 @@ void StatusNotifierItem::updateIcon() {
|
|||
emit this->iconChanged();
|
||||
}
|
||||
|
||||
DBusMenu* StatusNotifierItem::createMenu() const {
|
||||
auto path = this->menuPath.get().path();
|
||||
if (!path.isEmpty()) {
|
||||
return new DBusMenu(this->item->service(), this->menuPath.get().path());
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void StatusNotifierItem::onGetAllFinished() {
|
||||
if (this->mReady) return;
|
||||
this->mReady = true;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <qtypes.h>
|
||||
|
||||
#include "../../core/imageprovider.hpp"
|
||||
#include "../../dbus/dbusmenu/dbusmenu.hpp"
|
||||
#include "../../dbus/properties.hpp"
|
||||
#include "dbus_item.h"
|
||||
#include "dbus_item_types.hpp"
|
||||
|
@ -40,6 +41,7 @@ public:
|
|||
[[nodiscard]] bool isReady() const;
|
||||
[[nodiscard]] QString iconId() const;
|
||||
[[nodiscard]] QPixmap createPixmap(const QSize& size) const;
|
||||
[[nodiscard]] qs::dbus::dbusmenu::DBusMenu* createMenu() const;
|
||||
|
||||
void activate();
|
||||
void secondaryActivate();
|
||||
|
@ -77,6 +79,7 @@ private:
|
|||
DBusStatusNotifierItem* item = nullptr;
|
||||
TrayImageHandle imageHandle {this};
|
||||
bool mReady = false;
|
||||
dbus::dbusmenu::DBusMenu* mMenu = nullptr;
|
||||
|
||||
// bumped to inhibit caching
|
||||
quint32 iconIndex = 0;
|
||||
|
|
|
@ -9,11 +9,13 @@
|
|||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "../../dbus/dbusmenu/dbusmenu.hpp"
|
||||
#include "../../dbus/properties.hpp"
|
||||
#include "host.hpp"
|
||||
#include "item.hpp"
|
||||
|
||||
using namespace qs::dbus;
|
||||
using namespace qs::dbus::dbusmenu;
|
||||
using namespace qs::service::sni;
|
||||
|
||||
SystemTrayItem::SystemTrayItem(qs::service::sni::StatusNotifierItem* item, QObject* parent)
|
||||
|
@ -27,8 +29,11 @@ SystemTrayItem::SystemTrayItem(qs::service::sni::StatusNotifierItem* item, QObje
|
|||
QObject::connect(this->item, &StatusNotifierItem::iconChanged, this, &SystemTrayItem::iconChanged);
|
||||
QObject::connect(&this->item->tooltip, &AbstractDBusProperty::changed, this, &SystemTrayItem::tooltipTitleChanged);
|
||||
QObject::connect(&this->item->tooltip, &AbstractDBusProperty::changed, this, &SystemTrayItem::tooltipDescriptionChanged);
|
||||
QObject::connect(&this->item->menuPath, &AbstractDBusProperty::changed, this, &SystemTrayItem::onMenuPathChanged);
|
||||
QObject::connect(&this->item->isMenu, &AbstractDBusProperty::changed, this, &SystemTrayItem::onlyMenuChanged);
|
||||
// clang-format on
|
||||
|
||||
if (!this->item->menuPath.get().path().isEmpty()) this->onMenuPathChanged();
|
||||
}
|
||||
|
||||
QString SystemTrayItem::id() const {
|
||||
|
@ -84,11 +89,25 @@ QString SystemTrayItem::tooltipDescription() const {
|
|||
return this->item->tooltip.get().description;
|
||||
}
|
||||
|
||||
DBusMenuItem* SystemTrayItem::menu() const {
|
||||
if (this->mMenu == nullptr) return nullptr;
|
||||
return &this->mMenu->rootItem;
|
||||
}
|
||||
|
||||
bool SystemTrayItem::onlyMenu() const {
|
||||
if (this->item == nullptr) return false;
|
||||
return this->item->isMenu.get();
|
||||
}
|
||||
|
||||
void SystemTrayItem::onMenuPathChanged() {
|
||||
if (this->mMenu != nullptr) {
|
||||
this->mMenu->deleteLater();
|
||||
}
|
||||
|
||||
this->mMenu = this->item->createMenu();
|
||||
emit this->menuChanged();
|
||||
}
|
||||
|
||||
void SystemTrayItem::activate() { this->item->activate(); }
|
||||
|
||||
void SystemTrayItem::secondaryActivate() { this->item->secondaryActivate(); }
|
||||
|
|
|
@ -58,15 +58,14 @@ class SystemTrayItem: public QObject {
|
|||
Q_PROPERTY(QString icon READ icon NOTIFY iconChanged);
|
||||
Q_PROPERTY(QString tooltipTitle READ tooltipTitle NOTIFY tooltipTitleChanged);
|
||||
Q_PROPERTY(QString tooltipDescription READ tooltipDescription NOTIFY tooltipDescriptionChanged);
|
||||
Q_PROPERTY(qs::dbus::dbusmenu::DBusMenuItem* menu READ menu NOTIFY menuChanged);
|
||||
// If this tray item only offers a menu and no activation action.
|
||||
Q_PROPERTY(bool onlyMenu READ onlyMenu NOTIFY onlyMenuChanged);
|
||||
QML_ELEMENT;
|
||||
QML_UNCREATABLE("SystemTrayItems can only be acquired from SystemTray");
|
||||
|
||||
public:
|
||||
explicit SystemTrayItem(
|
||||
qs::service::sni::StatusNotifierItem* item = nullptr,
|
||||
QObject* parent = nullptr
|
||||
);
|
||||
explicit SystemTrayItem(qs::service::sni::StatusNotifierItem* item, QObject* parent = nullptr);
|
||||
|
||||
// Primary activation action, generally triggered via a left click.
|
||||
Q_INVOKABLE void activate();
|
||||
|
@ -84,6 +83,7 @@ public:
|
|||
[[nodiscard]] QString icon() const;
|
||||
[[nodiscard]] QString tooltipTitle() const;
|
||||
[[nodiscard]] QString tooltipDescription() const;
|
||||
[[nodiscard]] qs::dbus::dbusmenu::DBusMenuItem* menu() const;
|
||||
[[nodiscard]] bool onlyMenu() const;
|
||||
|
||||
signals:
|
||||
|
@ -94,10 +94,15 @@ signals:
|
|||
void iconChanged();
|
||||
void tooltipTitleChanged();
|
||||
void tooltipDescriptionChanged();
|
||||
void menuChanged();
|
||||
void onlyMenuChanged();
|
||||
|
||||
private slots:
|
||||
void onMenuPathChanged();
|
||||
|
||||
private:
|
||||
qs::service::sni::StatusNotifierItem* item = nullptr;
|
||||
qs::dbus::dbusmenu::DBusMenu* mMenu = nullptr;
|
||||
|
||||
friend class SystemTray;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue