KRunner integration: Send window pixmap along

If there is no icon name available which is very often
the case on X11.

BUG: 430054
This commit is contained in:
Kai Uwe Broulik 2020-12-17 20:04:05 +01:00
parent 810186222b
commit 5edfccac12
2 changed files with 55 additions and 1 deletions

View file

@ -38,6 +38,18 @@ struct RemoteAction
typedef QList<RemoteAction> RemoteActions; typedef QList<RemoteAction> 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) { inline QDBusArgument &operator<< (QDBusArgument &argument, const RemoteMatch &match) {
argument.beginStructure(); argument.beginStructure();
argument << match.id; argument << match.id;
@ -84,8 +96,34 @@ inline const QDBusArgument &operator>>(const QDBusArgument &argument, RemoteActi
return argument; 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(RemoteMatch)
Q_DECLARE_METATYPE(RemoteMatches) Q_DECLARE_METATYPE(RemoteMatches)
Q_DECLARE_METATYPE(RemoteAction) Q_DECLARE_METATYPE(RemoteAction)
Q_DECLARE_METATYPE(RemoteActions) Q_DECLARE_METATYPE(RemoteActions)
Q_DECLARE_METATYPE(RemoteImage)

View file

@ -40,6 +40,7 @@ void WindowsRunner::initialize()
qDBusRegisterMetaType<RemoteMatches>(); qDBusRegisterMetaType<RemoteMatches>();
qDBusRegisterMetaType<RemoteAction>(); qDBusRegisterMetaType<RemoteAction>();
qDBusRegisterMetaType<RemoteActions>(); qDBusRegisterMetaType<RemoteActions>();
qDBusRegisterMetaType<RemoteImage>();
QDBusConnection::sessionBus().registerObject(QStringLiteral("/WindowsRunner"), this); QDBusConnection::sessionBus().registerObject(QStringLiteral("/WindowsRunner"), this);
QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.KWin")); QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.KWin"));
} }
@ -283,6 +284,21 @@ RemoteMatch WindowsRunner::windowsMatch(const AbstractClient *client, const Wind
targetDesktop = desktops.first(); 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<const char *>(convertedImage.constBits()), convertedImage.sizeInBytes())
};
properties.insert(QStringLiteral("icon-data"), QVariant::fromValue(remoteImage));
}
const QString desktopName = targetDesktop->name(); const QString desktopName = targetDesktop->name();
switch (action) { switch (action) {
case CloseAction: case CloseAction: