From 5edfccac127d054f7dfd47461b501dabbdd8bcf5 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Thu, 17 Dec 2020 20:04:05 +0100 Subject: [PATCH] KRunner integration: Send window pixmap along If there is no icon name available which is very often the case on X11. BUG: 430054 --- plugins/krunner-integration/dbusutils_p.h | 40 ++++++++++++++++++- .../windowsrunnerinterface.cpp | 16 ++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/plugins/krunner-integration/dbusutils_p.h b/plugins/krunner-integration/dbusutils_p.h index a24e73dc08..94845ff734 100644 --- a/plugins/krunner-integration/dbusutils_p.h +++ b/plugins/krunner-integration/dbusutils_p.h @@ -38,6 +38,18 @@ struct RemoteAction typedef QList RemoteActions; +struct RemoteImage +{ + //iiibiiay (matching notification spec image-data attribute) + int width = 0; + int height = 0; + int rowStride = 0; + bool hasAlpha = false; + int bitsPerSample = 0; + int channels = 0; + QByteArray data; +}; + inline QDBusArgument &operator<< (QDBusArgument &argument, const RemoteMatch &match) { argument.beginStructure(); argument << match.id; @@ -84,8 +96,34 @@ inline const QDBusArgument &operator>>(const QDBusArgument &argument, RemoteActi return argument; } +inline QDBusArgument &operator<< (QDBusArgument &argument, const RemoteImage &image) { + argument.beginStructure(); + argument << image.width; + argument << image.height; + argument << image.rowStride; + argument << image.hasAlpha; + argument << image.bitsPerSample; + argument << image.channels; + argument << image.data; + argument.endStructure(); + return argument; +} + +inline const QDBusArgument &operator>>(const QDBusArgument &argument, RemoteImage &image) { + argument.beginStructure(); + argument >> image.width; + argument >> image.height; + argument >> image.rowStride; + argument >> image.hasAlpha; + argument >> image.bitsPerSample; + argument >> image.channels; + argument >> image.data; + argument.endStructure(); + return argument; +} + Q_DECLARE_METATYPE(RemoteMatch) Q_DECLARE_METATYPE(RemoteMatches) Q_DECLARE_METATYPE(RemoteAction) Q_DECLARE_METATYPE(RemoteActions) - +Q_DECLARE_METATYPE(RemoteImage) diff --git a/plugins/krunner-integration/windowsrunnerinterface.cpp b/plugins/krunner-integration/windowsrunnerinterface.cpp index 92f39d13e5..5d2c314ecd 100644 --- a/plugins/krunner-integration/windowsrunnerinterface.cpp +++ b/plugins/krunner-integration/windowsrunnerinterface.cpp @@ -40,6 +40,7 @@ void WindowsRunner::initialize() qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); + qDBusRegisterMetaType(); QDBusConnection::sessionBus().registerObject(QStringLiteral("/WindowsRunner"), this); QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.KWin")); } @@ -283,6 +284,21 @@ RemoteMatch WindowsRunner::windowsMatch(const AbstractClient *client, const Wind targetDesktop = desktops.first(); } + // When there is no icon name, send a pixmap along instead + if (match.iconName.isEmpty()) { + QImage convertedImage = client->icon().pixmap(QSize(16,16)).toImage().convertToFormat(QImage::Format_RGBA8888); + RemoteImage remoteImage{ + convertedImage.width(), + convertedImage.height(), + convertedImage.bytesPerLine(), + true, // hasAlpha + 8, // bitsPerSample + 4, // channels + QByteArray(reinterpret_cast(convertedImage.constBits()), convertedImage.sizeInBytes()) + }; + properties.insert(QStringLiteral("icon-data"), QVariant::fromValue(remoteImage)); + } + const QString desktopName = targetDesktop->name(); switch (action) { case CloseAction: