diff --git a/libtaskmanager/CMakeLists.txt b/libtaskmanager/CMakeLists.txt index 9c3e15e9a..a9b8084f9 100644 --- a/libtaskmanager/CMakeLists.txt +++ b/libtaskmanager/CMakeLists.txt @@ -36,13 +36,13 @@ target_link_libraries(taskmanager Qt5::Gui Qt5::Quick KF5::ItemModels - KF5::WaylandClient PRIVATE KF5::Activities KF5::ConfigCore KF5::KIOCore KF5::KIOWidgets KF5::ProcessCore + KF5::WaylandClient KF5::WindowSystem ) diff --git a/libtaskmanager/xwindowtasksmodel.cpp b/libtaskmanager/xwindowtasksmodel.cpp index 14b043f27..54664bd3f 100644 --- a/libtaskmanager/xwindowtasksmodel.cpp +++ b/libtaskmanager/xwindowtasksmodel.cpp @@ -1,5 +1,6 @@ /******************************************************************** Copyright 2016 Eike Hein +Copyright 2008 Aaron J. Seigo This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -47,8 +48,6 @@ License along with this library. If not, see . #include #include -#include - namespace TaskManager { @@ -85,7 +84,8 @@ public: AppData appData(WId window); QIcon icon(WId window); - QString mimeType() const; + static QString mimeType(); + static QString groupMimeType(); QUrl windowUrl(WId window); QUrl launcherUrl(WId window, bool encodeFallbackIcon = true); QUrl serviceUrl(int pid, const QString &type, const QStringList &cmdRemovals); @@ -452,11 +452,16 @@ QIcon XWindowTasksModel::Private::icon(WId window) return icon; } -QString XWindowTasksModel::Private::mimeType() const +QString XWindowTasksModel::Private::mimeType() { return QStringLiteral("windowsystem/winid"); } +QString XWindowTasksModel::Private::groupMimeType() +{ + return QStringLiteral("windowsystem/multiple-winids"); +} + QUrl XWindowTasksModel::Private::windowUrl(WId window) { QUrl url; @@ -1243,4 +1248,80 @@ void XWindowTasksModel::requestPublishDelegateGeometry(const QModelIndex &index, ni.setIconGeometry(rect); } +WId XWindowTasksModel::winIdFromMimeData(const QMimeData *mimeData, bool *ok) +{ + Q_ASSERT(mimeData); + + if (ok) { + *ok = false; + } + + if (!mimeData->hasFormat(Private::mimeType())) { + return 0; + } + + QByteArray data(mimeData->data(Private::mimeType())); + if (data.size() != sizeof(WId)) { + return 0; + } + + WId id; + memcpy(&id, data.data(), sizeof(WId)); + + if (ok) { + *ok = true; + } + + return id; +} + +QList XWindowTasksModel::winIdsFromMimeData(const QMimeData *mimeData, bool *ok) +{ + Q_ASSERT(mimeData); + QList ids; + + if (ok) { + *ok = false; + } + + if (!mimeData->hasFormat(Private::groupMimeType())) { + // Try to extract single window id. + bool singularOk; + WId id = winIdFromMimeData(mimeData, &singularOk); + + if (ok) { + *ok = singularOk; + } + + if (singularOk) { + ids << id; + } + + return ids; + } + + QByteArray data(mimeData->data(Private::groupMimeType())); + if ((unsigned int)data.size() < sizeof(int) + sizeof(WId)) { + return ids; + } + + int count = 0; + memcpy(&count, data.data(), sizeof(int)); + if (count < 1 || (unsigned int)data.size() < sizeof(int) + sizeof(WId) * count) { + return ids; + } + + WId id; + for (int i = 0; i < count; ++i) { + memcpy(&id, data.data() + sizeof(int) + sizeof(WId) * i, sizeof(WId)); + ids << id; + } + + if (ok) { + *ok = true; + } + + return ids; +} + } diff --git a/libtaskmanager/xwindowtasksmodel.h b/libtaskmanager/xwindowtasksmodel.h index 55fc49cfb..cd9710053 100644 --- a/libtaskmanager/xwindowtasksmodel.h +++ b/libtaskmanager/xwindowtasksmodel.h @@ -25,6 +25,10 @@ License along with this library. If not, see . #include "taskmanager_export.h" +#include + +#include + namespace TaskManager { @@ -198,6 +202,22 @@ public: void requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate = nullptr) override; + /** + * Tries to extract a X11 window id from supplied mime data. + * + * @param mimeData Some mime data. + * @param @ok Set to true or false on success or failure. + */ + static WId winIdFromMimeData(const QMimeData *mimeData, bool *ok = 0); + + /** + * Tries to extract X11 window ids from supplied mime data. + * + * @param mimeData Some mime data. + * @param @ok Set to true or false on success or failure. + */ + static QList winIdsFromMimeData(const QMimeData *mimeData, bool *ok = 0); + private: class Private; QScopedPointer d;