Implement setBadgeNumber for xcb backend
This use the unity launcher specification which is defined here https://wiki.ubuntu.com/Unity/LauncherAPI This spec is used by Plasma and Unity. On other Linux desktop platform where the unity DBus interface is not detected this is no-op. Change-Id: I81a9b95fe4886ad597bb4e775641926b161c49a5 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: David Edmundson <davidedmundson@kde.org>
This commit is contained in:
parent
447f3ade9a
commit
ac973cb74f
@ -751,7 +751,8 @@ QString QGuiApplication::applicationDisplayName()
|
||||
of unread messages or similar.
|
||||
|
||||
The badge will be overlaid on the application's icon in the Dock
|
||||
on \macos, the home screen icon on iOS, or the task bar on Windows.
|
||||
on \macos, the home screen icon on iOS, or the task bar on Windows
|
||||
and Linux.
|
||||
|
||||
If the number is outside the range supported by the platform, the
|
||||
number will be clamped to the supported range. If the number does
|
||||
|
@ -575,6 +575,37 @@ bool QGenericUnixServices::hasCapability(Capability capability) const
|
||||
return false;
|
||||
}
|
||||
|
||||
void QGenericUnixServices::setApplicationBadge(qint64 number)
|
||||
{
|
||||
#if QT_CONFIG(dbus)
|
||||
if (qGuiApp->desktopFileName().isEmpty()) {
|
||||
qWarning("QGuiApplication::desktopFileName() is empty");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const QString launcherUrl = QStringLiteral("application://") + qGuiApp->desktopFileName() + QStringLiteral(".desktop");
|
||||
const qint64 count = qBound(0, number, 9999);
|
||||
QVariantMap dbusUnityProperties;
|
||||
|
||||
if (count > 0) {
|
||||
dbusUnityProperties[QStringLiteral("count")] = count;
|
||||
dbusUnityProperties[QStringLiteral("count-visible")] = true;
|
||||
} else {
|
||||
dbusUnityProperties[QStringLiteral("count-visible")] = false;
|
||||
}
|
||||
|
||||
auto signal = QDBusMessage::createSignal(QStringLiteral("/com/canonical/unity/launcherentry/")
|
||||
+ qGuiApp->applicationName(), QStringLiteral("com.canonical.Unity.LauncherEntry"), QStringLiteral("Update"));
|
||||
|
||||
signal.setArguments({launcherUrl, dbusUnityProperties});
|
||||
|
||||
QDBusConnection::sessionBus().send(signal);
|
||||
#else
|
||||
Q_UNUSED(number)
|
||||
#endif
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "qgenericunixservices.moc"
|
||||
|
@ -35,6 +35,7 @@ public:
|
||||
bool openDocument(const QUrl &url) override;
|
||||
QPlatformServiceColorPicker *colorPicker(QWindow *parent = nullptr) override;
|
||||
|
||||
void setApplicationBadge(qint64 number);
|
||||
virtual QString portalWindowIdentifier(QWindow *window);
|
||||
|
||||
private:
|
||||
|
@ -585,4 +585,10 @@ QPlatformVulkanInstance *QXcbIntegration::createPlatformVulkanInstance(QVulkanIn
|
||||
}
|
||||
#endif
|
||||
|
||||
void QXcbIntegration::setApplicationBadge(qint64 number)
|
||||
{
|
||||
auto unixServices = dynamic_cast<QGenericUnixServices *>(services());
|
||||
unixServices->setApplicationBadge(number);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -102,6 +102,8 @@ public:
|
||||
|
||||
static QXcbIntegration *instance() { return m_instance; }
|
||||
|
||||
void setApplicationBadge(qint64 number) override;
|
||||
|
||||
private:
|
||||
QXcbConnection *m_connection = nullptr;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user