diff --git a/libtaskmanager/abstracttasksmodel.h b/libtaskmanager/abstracttasksmodel.h --- a/libtaskmanager/abstracttasksmodel.h +++ b/libtaskmanager/abstracttasksmodel.h @@ -233,6 +233,19 @@ virtual void requestVirtualDesktop(const QModelIndex &index, qint32 desktop) override; /** + * Request moving the task at the given index to the specified activities. + * + * This is meant for tasks that have an associated window, and may be + * a no-op when there is no window. + * + * This base implementation does nothing. + * + * @param index An index in this tasks model. + * @param activities The new list of activities. + **/ + virtual void requestActivities(const QModelIndex &index, const QStringList &activities); + + /** * Request informing the window manager of new geometry for a visual * delegate for the task at the given index. The geometry should be in * screen coordinates. diff --git a/libtaskmanager/abstracttasksmodel.cpp b/libtaskmanager/abstracttasksmodel.cpp --- a/libtaskmanager/abstracttasksmodel.cpp +++ b/libtaskmanager/abstracttasksmodel.cpp @@ -113,6 +113,12 @@ Q_UNUSED(desktop) } +void AbstractTasksModel::requestActivities(const QModelIndex &index, const QStringList &activities) +{ + Q_UNUSED(index) + Q_UNUSED(activities) +} + void AbstractTasksModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) { Q_UNUSED(index) diff --git a/libtaskmanager/abstracttasksmodeliface.h b/libtaskmanager/abstracttasksmodeliface.h --- a/libtaskmanager/abstracttasksmodeliface.h +++ b/libtaskmanager/abstracttasksmodeliface.h @@ -160,6 +160,18 @@ virtual void requestVirtualDesktop(const QModelIndex &index, qint32 desktop = -1) = 0; /** + * Request moving the task at the given index to the specified virtual + * activities. + * + * This is meant for tasks that have an associated window, and may be + * a no-op when there is no window. + * + * @param index An index in this tasks model. + * @param activities The new list of activities. + **/ + virtual void requestActivities(const QModelIndex &index, const QStringList &activities) = 0; + + /** * Request informing the window manager of new geometry for a visual * delegate for the task at the given index. The geometry should be in * screen coordinates. diff --git a/libtaskmanager/activityinfo.h b/libtaskmanager/activityinfo.h --- a/libtaskmanager/activityinfo.h +++ b/libtaskmanager/activityinfo.h @@ -72,7 +72,7 @@ * * @returns the list of currently-running activities defined in the session. **/ - QStringList runningActivities() const; + Q_INVOKABLE QStringList runningActivities() const; /** * The name of the activity of the given id. diff --git a/libtaskmanager/concatenatetasksproxymodel.h b/libtaskmanager/concatenatetasksproxymodel.h --- a/libtaskmanager/concatenatetasksproxymodel.h +++ b/libtaskmanager/concatenatetasksproxymodel.h @@ -165,6 +165,19 @@ void requestVirtualDesktop(const QModelIndex &index, qint32 desktop); /** + * Request moving the task at the given index to the specified activities. + * + * This is meant for tasks that have an associated window, and may be + * a no-op when there is no window. + * + * This base implementation does nothing. + * + * @param index An index in this tasks model. + * @param activities The new list of activities. + **/ + void requestActivities(const QModelIndex &index, const QStringList &activities); + + /** * Request informing the window manager of new geometry for a visual * delegate for the task at the given index. The geometry should be in * screen coordinates. diff --git a/libtaskmanager/concatenatetasksproxymodel.cpp b/libtaskmanager/concatenatetasksproxymodel.cpp --- a/libtaskmanager/concatenatetasksproxymodel.cpp +++ b/libtaskmanager/concatenatetasksproxymodel.cpp @@ -223,6 +223,23 @@ } } +void ConcatenateTasksProxyModel::requestActivities(const QModelIndex &index, const QStringList &activities) +{ + if (!index.isValid() || index.model() != this) { + return; + } + + const QModelIndex &sourceIndex = mapToSource(index); + const AbstractTasksModelIface *m = dynamic_cast(sourceIndex.model()); + + if (m) { + // NOTE: KConcatenateRowsProxyModel offers no way to get a non-const pointer + // to one of the source models, so we have to go through a mapped index. + const_cast(m)->requestActivities(sourceIndex, activities); + } +} + + void ConcatenateTasksProxyModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) { if (!index.isValid() || index.model() != this) { diff --git a/libtaskmanager/flattentaskgroupsproxymodel.h b/libtaskmanager/flattentaskgroupsproxymodel.h --- a/libtaskmanager/flattentaskgroupsproxymodel.h +++ b/libtaskmanager/flattentaskgroupsproxymodel.h @@ -168,6 +168,17 @@ void requestVirtualDesktop(const QModelIndex &index, qint32 desktop) override; /** + * Request moving the task at the given index to the specified activities. + * + * This is meant for tasks that have an associated window, and may be + * a no-op when there is no window. + * * + * @param index An index in this tasks model. + * @param activities The new list of activities. + **/ + void requestActivities(const QModelIndex &index, const QStringList &activities); + + /** * Request informing the window manager of new geometry for a visual * delegate for the task at the given index. The geometry should be in * screen coordinates. diff --git a/libtaskmanager/flattentaskgroupsproxymodel.cpp b/libtaskmanager/flattentaskgroupsproxymodel.cpp --- a/libtaskmanager/flattentaskgroupsproxymodel.cpp +++ b/libtaskmanager/flattentaskgroupsproxymodel.cpp @@ -140,6 +140,13 @@ } } +void FlattenTaskGroupsProxyModel::requestActivities(const QModelIndex &index, const QStringList &activities) +{ + if (d->sourceTasksModel && index.isValid() && index.model() == this) { + d->sourceTasksModel->requestActivities(mapToSource(index), activities); + } +} + void FlattenTaskGroupsProxyModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) { if (index.isValid() && index.model() == this) { diff --git a/libtaskmanager/taskfilterproxymodel.h b/libtaskmanager/taskfilterproxymodel.h --- a/libtaskmanager/taskfilterproxymodel.h +++ b/libtaskmanager/taskfilterproxymodel.h @@ -325,6 +325,19 @@ void requestVirtualDesktop(const QModelIndex &index, qint32 desktop) override; /** + * Request moving the task at the given index to the specified activities. + * + * This is meant for tasks that have an associated window, and may be + * a no-op when there is no window. + * + * This base implementation does nothing. + * + * @param index An index in this tasks model. + * @param activities The new list of activities. + **/ + void requestActivities(const QModelIndex &index, const QStringList &activities); + + /** * Request informing the window manager of new geometry for a visual * delegate for the task at the given index. The geometry should be in * screen coordinates. diff --git a/libtaskmanager/taskfilterproxymodel.cpp b/libtaskmanager/taskfilterproxymodel.cpp --- a/libtaskmanager/taskfilterproxymodel.cpp +++ b/libtaskmanager/taskfilterproxymodel.cpp @@ -268,6 +268,13 @@ } } +void TaskFilterProxyModel::requestActivities(const QModelIndex &index, const QStringList &activities) +{ + if (d->sourceTasksModel && index.isValid() && index.model() == this) { + d->sourceTasksModel->requestActivities(mapToSource(index), activities); + } +} + void TaskFilterProxyModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) { if (index.isValid() && index.model() == this) { diff --git a/libtaskmanager/taskgroupingproxymodel.h b/libtaskmanager/taskgroupingproxymodel.h --- a/libtaskmanager/taskgroupingproxymodel.h +++ b/libtaskmanager/taskgroupingproxymodel.h @@ -317,6 +317,19 @@ void requestVirtualDesktop(const QModelIndex &index, qint32 desktop) override; /** + * Request moving the task at the given index to the specified activities. + * + * This is meant for tasks that have an associated window, and may be + * a no-op when there is no window. + * + * This base implementation does nothing. + * + * @param index An index in this tasks model. + * @param activities The new list of activities. + **/ + virtual void requestActivities(const QModelIndex &index, const QStringList &activities); + + /** * Request informing the window manager of new geometry for a visual * delegate for the task at the given index. The geometry should be in * screen coordinates. diff --git a/libtaskmanager/taskgroupingproxymodel.cpp b/libtaskmanager/taskgroupingproxymodel.cpp --- a/libtaskmanager/taskgroupingproxymodel.cpp +++ b/libtaskmanager/taskgroupingproxymodel.cpp @@ -1127,6 +1127,27 @@ } } +void TaskGroupingProxyModel::requestActivities(const QModelIndex &index, const QStringList &activities) +{ + if (!d->abstractTasksSourceModel || !index.isValid() || index.model() != this) { + return; + } + + if (index.parent().isValid() || !d->isGroup(index.row())) { + d->abstractTasksSourceModel->requestActivities(mapToSource(index), activities); + } else { + const int row = index.row(); + + for (int i = (rowCount(index) - 1); i >= 1; --i) { + const QModelIndex &sourceChild = mapToSource(index.child(i, 0)); + d->abstractTasksSourceModel->requestActivities(sourceChild, activities); + } + + d->abstractTasksSourceModel->requestActivities(mapToSource(TaskGroupingProxyModel::index(row, 0)), + activities); + } +} + void TaskGroupingProxyModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) { if (!d->abstractTasksSourceModel || !index.isValid() || index.model() != this) { diff --git a/libtaskmanager/tasksmodel.h b/libtaskmanager/tasksmodel.h --- a/libtaskmanager/tasksmodel.h +++ b/libtaskmanager/tasksmodel.h @@ -623,6 +623,19 @@ Q_INVOKABLE void requestVirtualDesktop(const QModelIndex &index, qint32 desktop) override; /** + * Request moving the task at the given index to the specified activities. + * + * This is meant for tasks that have an associated window, and may be + * a no-op when there is no window. + * + * This base implementation does nothing. + * + * @param index An index in this tasks model. + * @param activities The new list of activities. + **/ + Q_INVOKABLE virtual void requestActivities(const QModelIndex &index, const QStringList &activities); + + /** * Request informing the window manager of new geometry for a visual * delegate for the task at the given index. The geometry should be in * screen coordinates. diff --git a/libtaskmanager/tasksmodel.cpp b/libtaskmanager/tasksmodel.cpp --- a/libtaskmanager/tasksmodel.cpp +++ b/libtaskmanager/tasksmodel.cpp @@ -1232,6 +1232,13 @@ } } +void TasksModel::requestActivities(const QModelIndex &index, const QStringList &activities) +{ + if (index.isValid() && index.model() == this) { + d->groupingProxyModel->requestActivities(mapToSource(index), activities); + } +} + void TasksModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) { if (index.isValid() && index.model() == this) { diff --git a/libtaskmanager/waylandtasksmodel.h b/libtaskmanager/waylandtasksmodel.h --- a/libtaskmanager/waylandtasksmodel.h +++ b/libtaskmanager/waylandtasksmodel.h @@ -163,6 +163,16 @@ void requestVirtualDesktop(const QModelIndex &index, qint32 desktop) override; /** + * Request moving the window at the given index to the specified activities + * + * FIXME: This currently does nothing as activities is not implementated in kwin/kwayland + * + * @param index An index in this window tasks model. + * @param desktop A virtual desktop number. + **/ + void requestActivities(const QModelIndex &index, const QStringList &activities) override; + + /** * Request informing the window manager of new geometry for a visual * delegate for the window at the given index. The geometry is retrieved * from the delegate object passed. Right now, QQuickItem is the only diff --git a/libtaskmanager/waylandtasksmodel.cpp b/libtaskmanager/waylandtasksmodel.cpp --- a/libtaskmanager/waylandtasksmodel.cpp +++ b/libtaskmanager/waylandtasksmodel.cpp @@ -462,6 +462,12 @@ d->windows.at(index.row())->requestVirtualDesktop(desktop); } +void WaylandTasksModel::requestActivities(const QModelIndex &index, const QStringList &activities) +{ + Q_UNUSED(index) + Q_UNUSED(activities) +} + void WaylandTasksModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) { /* diff --git a/libtaskmanager/xwindowtasksmodel.h b/libtaskmanager/xwindowtasksmodel.h --- a/libtaskmanager/xwindowtasksmodel.h +++ b/libtaskmanager/xwindowtasksmodel.h @@ -177,6 +177,17 @@ void requestVirtualDesktop(const QModelIndex &index, qint32 desktop) override; /** + * Request moving the task at the given index to the specified activities. + * + * This is meant for tasks that have an associated window, and may be + * a no-op when there is no window. + * * + * @param index An index in this tasks model. + * @param activities The new list of activities. + **/ + void requestActivities(const QModelIndex &index, const QStringList &activities) override; + + /** * Request informing the window manager of new geometry for a visual * delegate for the window at the given index. * diff --git a/libtaskmanager/xwindowtasksmodel.cpp b/libtaskmanager/xwindowtasksmodel.cpp --- a/libtaskmanager/xwindowtasksmodel.cpp +++ b/libtaskmanager/xwindowtasksmodel.cpp @@ -1199,6 +1199,18 @@ } } +void XWindowTasksModel::requestActivities(const QModelIndex &index, const QStringList &activities) +{ + if (!index.isValid() || index.model() != this || index.row() < 0 || index.row() >= d->windows.count()) { + return; + } + + const WId window = d->windows.at(index.row()); + + KWindowSystem::setOnActivities(window, activities); +} + + void XWindowTasksModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) { Q_UNUSED(delegate)