Summary: This introduces a new WindowTasksModel which is a QIdentityProxyModel around an instance of either WaylandTasksModel or XWindowsTasksModel. This arbitration was previously done directly in TasksModel, along with refcounting to share a single window tasks sub-model between TasksModel instances. Factoring out both of these things has two goals: - It allows users of libtaskmanager which are solely interested in window data (e.g. the Pager) to skip the unnecessary complexity of TasksModel, while still sharing the windowing monitoring with users of TasksModel. - TasksModel becomes fully free of windowing system-specific code and calls to KWindowSystem (to query the platform), making its code a little cleaner. The downside is another layer of indirection (the QIdentityProxyModel), but the upside is clear: The Pager wants to share window data and window monitoring with the Task Manager, but is not interested in startup notifications, does its own sorting (using the window stacking order), does not need grouping and has different filtering needs. The Pager backend will use QSortFilterProxyModel around WindowTasksModel to mix in its own data and sort by stacking order. Reviewers: #plasma, mart, davidedmundson Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D2379wilder-5.14
parent
5834c7fa6c
commit
acfbcb4fa5
4 changed files with 378 additions and 23 deletions
@ -0,0 +1,203 @@ |
||||
/********************************************************************
|
||||
Copyright 2016 Eike Hein <hein@kde.org> |
||||
|
||||
This library is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU Lesser General Public |
||||
License as published by the Free Software Foundation; either |
||||
version 2.1 of the License, or (at your option) version 3, or any |
||||
later version accepted by the membership of KDE e.V. (or its |
||||
successor approved by the membership of KDE e.V.), which shall |
||||
act as a proxy defined in Section 6 of version 3 of the license. |
||||
|
||||
This library is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
Lesser General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU Lesser General Public |
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/ |
||||
|
||||
#include "windowtasksmodel.h" |
||||
|
||||
#include <config-X11.h> |
||||
|
||||
#include "waylandtasksmodel.h" |
||||
#if HAVE_X11 |
||||
#include "xwindowtasksmodel.h" |
||||
#endif |
||||
|
||||
#include <KWindowSystem> |
||||
|
||||
namespace TaskManager |
||||
{ |
||||
|
||||
class WindowTasksModel::Private |
||||
{ |
||||
public: |
||||
Private(WindowTasksModel *q); |
||||
~Private(); |
||||
|
||||
static int instanceCount; |
||||
static AbstractTasksModel* sourceTasksModel; |
||||
|
||||
void initSourceTasksModel(); |
||||
|
||||
private: |
||||
WindowTasksModel *q; |
||||
}; |
||||
|
||||
int WindowTasksModel::Private::instanceCount = 0; |
||||
AbstractTasksModel* WindowTasksModel::Private::sourceTasksModel = nullptr; |
||||
|
||||
WindowTasksModel::Private::Private(WindowTasksModel *q) |
||||
: q(q) |
||||
{ |
||||
++instanceCount; |
||||
} |
||||
|
||||
WindowTasksModel::Private::~Private() |
||||
{ |
||||
--instanceCount; |
||||
|
||||
|
||||
if (!instanceCount) { |
||||
delete sourceTasksModel; |
||||
sourceTasksModel = nullptr; |
||||
} |
||||
} |
||||
|
||||
void WindowTasksModel::Private::initSourceTasksModel() |
||||
{ |
||||
if (!sourceTasksModel && KWindowSystem::isPlatformWayland()) { |
||||
sourceTasksModel = new WaylandTasksModel(); |
||||
} |
||||
|
||||
#if HAVE_X11 |
||||
if (!sourceTasksModel && KWindowSystem::isPlatformX11()) { |
||||
sourceTasksModel = new XWindowTasksModel(); |
||||
} |
||||
#endif |
||||
|
||||
q->setSourceModel(sourceTasksModel); |
||||
} |
||||
|
||||
WindowTasksModel::WindowTasksModel(QObject *parent) |
||||
: QIdentityProxyModel(parent) |
||||
, d(new Private(this)) |
||||
{ |
||||
d->initSourceTasksModel(); |
||||
} |
||||
|
||||
WindowTasksModel::~WindowTasksModel() |
||||
{ |
||||
} |
||||
|
||||
QHash<int, QByteArray> WindowTasksModel::roleNames() const |
||||
{ |
||||
if (d->sourceTasksModel) { |
||||
return d->sourceTasksModel->roleNames(); |
||||
} |
||||
|
||||
return QHash<int, QByteArray>(); |
||||
} |
||||
|
||||
void WindowTasksModel::requestActivate(const QModelIndex &index) |
||||
{ |
||||
if (d->sourceTasksModel && index.isValid() && index.model() == this) { |
||||
d->sourceTasksModel->requestActivate(mapToSource(index)); |
||||
} |
||||
} |
||||
|
||||
void WindowTasksModel::requestNewInstance(const QModelIndex &index) |
||||
{ |
||||
if (d->sourceTasksModel && index.isValid() && index.model() == this) { |
||||
d->sourceTasksModel->requestNewInstance(mapToSource(index)); |
||||
} |
||||
} |
||||
|
||||
void WindowTasksModel::requestClose(const QModelIndex &index) |
||||
{ |
||||
if (d->sourceTasksModel && index.isValid() && index.model() == this) { |
||||
d->sourceTasksModel->requestClose(mapToSource(index)); |
||||
} |
||||
} |
||||
|
||||
void WindowTasksModel::requestMove(const QModelIndex &index) |
||||
{ |
||||
if (d->sourceTasksModel && index.isValid() && index.model() == this) { |
||||
d->sourceTasksModel->requestMove(mapToSource(index)); |
||||
} |
||||
} |
||||
|
||||
void WindowTasksModel::requestResize(const QModelIndex &index) |
||||
{ |
||||
if (d->sourceTasksModel && index.isValid() && index.model() == this) { |
||||
d->sourceTasksModel->requestResize(mapToSource(index)); |
||||
} |
||||
} |
||||
|
||||
void WindowTasksModel::requestToggleMinimized(const QModelIndex &index) |
||||
{ |
||||
if (d->sourceTasksModel && index.isValid() && index.model() == this) { |
||||
d->sourceTasksModel->requestToggleMinimized(mapToSource(index)); |
||||
} |
||||
} |
||||
|
||||
void WindowTasksModel::requestToggleMaximized(const QModelIndex &index) |
||||
{ |
||||
if (d->sourceTasksModel && index.isValid() && index.model() == this) { |
||||
d->sourceTasksModel->requestToggleMaximized(mapToSource(index)); |
||||
} |
||||
} |
||||
|
||||
void WindowTasksModel::requestToggleKeepAbove(const QModelIndex &index) |
||||
{ |
||||
if (d->sourceTasksModel && index.isValid() && index.model() == this) { |
||||
d->sourceTasksModel->requestToggleKeepAbove(mapToSource(index)); |
||||
} |
||||
} |
||||
|
||||
void WindowTasksModel::requestToggleKeepBelow(const QModelIndex &index) |
||||
{ |
||||
if (d->sourceTasksModel && index.isValid() && index.model() == this) { |
||||
d->sourceTasksModel->requestToggleKeepBelow(mapToSource(index)); |
||||
} |
||||
} |
||||
|
||||
void WindowTasksModel::requestToggleFullScreen(const QModelIndex &index) |
||||
{ |
||||
if (d->sourceTasksModel && index.isValid() && index.model() == this) { |
||||
d->sourceTasksModel->requestToggleFullScreen(mapToSource(index)); |
||||
} |
||||
} |
||||
|
||||
void WindowTasksModel::requestToggleShaded(const QModelIndex &index) |
||||
{ |
||||
if (d->sourceTasksModel && index.isValid() && index.model() == this) { |
||||
d->sourceTasksModel->requestToggleShaded(mapToSource(index)); |
||||
} |
||||
} |
||||
|
||||
void WindowTasksModel::requestVirtualDesktop(const QModelIndex &index, qint32 desktop) |
||||
{ |
||||
if (d->sourceTasksModel && index.isValid() && index.model() == this) { |
||||
d->sourceTasksModel->requestVirtualDesktop(mapToSource(index), desktop); |
||||
} |
||||
} |
||||
|
||||
void WindowTasksModel::requestActivities(const QModelIndex &index, const QStringList &activities) |
||||
{ |
||||
if (d->sourceTasksModel && index.isValid() && index.model() == this) { |
||||
d->sourceTasksModel->requestActivities(mapToSource(index), activities); |
||||
} |
||||
} |
||||
|
||||
void WindowTasksModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) |
||||
{ |
||||
if (index.isValid() && index.model() == this) { |
||||
d->sourceTasksModel->requestPublishDelegateGeometry(mapToSource(index), geometry, delegate); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,167 @@ |
||||
/********************************************************************
|
||||
Copyright 2016 Eike Hein <hein.org> |
||||
|
||||
This library is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU Lesser General Public |
||||
License as published by the Free Software Foundation; either |
||||
version 2.1 of the License, or (at your option) version 3, or any |
||||
later version accepted by the membership of KDE e.V. (or its |
||||
successor approved by the membership of KDE e.V.), which shall |
||||
act as a proxy defined in Section 6 of version 3 of the license. |
||||
|
||||
This library is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
Lesser General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU Lesser General Public |
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/ |
||||
|
||||
#ifndef WINDOWTASKSMODEL_H |
||||
#define WINDOWTASKSMODEL_H |
||||
|
||||
#include <QIdentityProxyModel> |
||||
|
||||
#include "abstracttasksmodeliface.h" |
||||
|
||||
#include "taskmanager_export.h" |
||||
|
||||
namespace TaskManager |
||||
{ |
||||
|
||||
/**
|
||||
* @short A window tasks model. |
||||
* |
||||
* This model presents tasks sourced from window data retrieved from the |
||||
* windowing server the host process is connected to. The underlying |
||||
* windowing system is abstracted away. |
||||
* |
||||
* @author Eike Hein <hein@kde.org> |
||||
**/ |
||||
|
||||
class TASKMANAGER_EXPORT WindowTasksModel : public QIdentityProxyModel, public AbstractTasksModelIface |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit WindowTasksModel(QObject *parent = 0); |
||||
virtual ~WindowTasksModel(); |
||||
|
||||
QHash<int, QByteArray> roleNames() const override; |
||||
|
||||
/**
|
||||
* Request activation of the window at the given index. |
||||
* |
||||
* @param index An index in this window tasks model. |
||||
**/ |
||||
void requestActivate(const QModelIndex &index) override; |
||||
|
||||
/**
|
||||
* Request an additional instance of the application owning the window |
||||
* at the given index. Success depends on whether a |
||||
* AbstractTasksModel::LauncherUrl could be derived from window metadata. |
||||
* |
||||
* @param index An index in this window tasks model. |
||||
**/ |
||||
void requestNewInstance(const QModelIndex &index) override; |
||||
|
||||
/**
|
||||
* Request the window at the given index be closed. |
||||
* |
||||
* @param index An index in this window tasks model. |
||||
**/ |
||||
void requestClose(const QModelIndex &index) override; |
||||
|
||||
/**
|
||||
* Request starting an interactive move for the window at the given index. |
||||
* |
||||
* @param index An index in this window tasks model. |
||||
**/ |
||||
void requestMove(const QModelIndex &index) override; |
||||
|
||||
/**
|
||||
* Request starting an interactive resize for the window at the given index. |
||||
* |
||||
* @param index An index in this window tasks model. |
||||
**/ |
||||
void requestResize(const QModelIndex &index) override; |
||||
|
||||
/**
|
||||
* Request toggling the minimized state of the window at the given index. |
||||
* |
||||
* @param index An index in this window tasks model. |
||||
**/ |
||||
void requestToggleMinimized(const QModelIndex &index) override; |
||||
|
||||
/**
|
||||
* Request toggling the maximized state of the window at the given index. |
||||
* |
||||
* @param index An index in this window tasks model. |
||||
**/ |
||||
void requestToggleMaximized(const QModelIndex &index) override; |
||||
|
||||
/**
|
||||
* Request toggling the keep-above state of the window at the given index. |
||||
* |
||||
* @param index An index in this window tasks model. |
||||
**/ |
||||
void requestToggleKeepAbove(const QModelIndex &index) override; |
||||
|
||||
/**
|
||||
* Request toggling the keep-below state of the window at the given index. |
||||
* |
||||
* @param index An index in this window tasks model. |
||||
**/ |
||||
void requestToggleKeepBelow(const QModelIndex &index) override; |
||||
|
||||
/**
|
||||
* Request toggling the fullscreen state of the window at the given index. |
||||
* |
||||
* @param index An index in this window tasks model. |
||||
**/ |
||||
void requestToggleFullScreen(const QModelIndex &index) override; |
||||
|
||||
/**
|
||||
* Request toggling the shaded state of the window at the given index. |
||||
* |
||||
* @param index An index in this window tasks model. |
||||
**/ |
||||
void requestToggleShaded(const QModelIndex &index) override; |
||||
|
||||
/**
|
||||
* Request moving the window at the given index to the specified virtual |
||||
* desktop. |
||||
* |
||||
* @param index An index in this window tasks model. |
||||
* @param desktop A virtual desktop number. |
||||
**/ |
||||
void requestVirtualDesktop(const QModelIndex &index, qint32 desktop) override; |
||||
|
||||
/**
|
||||
* Request moving the window at the given index to the specified activities. |
||||
* |
||||
* @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. |
||||
* |
||||
* @param index An index in this window tasks model. |
||||
* @param geometry Visual delegate geometry in screen coordinates. |
||||
* @param delegate The delegate. |
||||
**/ |
||||
void requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, |
||||
QObject *delegate = nullptr) override; |
||||
|
||||
private: |
||||
class Private; |
||||
QScopedPointer<Private> d; |
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif |
||||
Loading…
Reference in new issue