port to new libtaskmanager

almost entirely port the task switcher to the new
libtaskmanager. still needs porting
for the single close current window button
This commit is contained in:
Marco Martin 2016-06-27 18:34:20 +02:00
parent b18580da0e
commit 18b4af0def
5 changed files with 23 additions and 57 deletions

View file

@ -20,6 +20,7 @@
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Layouts 1.1 import QtQuick.Layouts 1.1
import QtQuick.Window 2.2 import QtQuick.Window 2.2
import org.kde.taskmanager 0.1 as TaskManager
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.mobilecomponents 0.2 import org.kde.plasma.mobilecomponents 0.2
@ -42,7 +43,7 @@ Item {
target: tasksView target: tasksView
onContentYChanged: { onContentYChanged: {
var pos = delegate.mapToItem(tasksView, 0, 0); var pos = delegate.mapToItem(tasksView, 0, 0);
plasmoid.nativeInterface.setTaskGeometry(filteredWindowModel.mapRowToSource(model.index), pos.x, pos.y, delegate.width, delegate.height); tasksModel.requestPublishDelegateGeometry(model.index, Qt.rect(pos.x, pos.y, delegate.width, delegate.height));
} }
} }
@ -65,7 +66,7 @@ Item {
ScriptAction { ScriptAction {
script: { script: {
if (background.x != 0) { if (background.x != 0) {
plasmoid.nativeInterface.windowModel.requestClose(filteredWindowModel.mapRowToSource(model.index)); tasksModel.requestClose(model.index);
} }
} }
} }
@ -95,7 +96,7 @@ Item {
anchors.centerIn: parent anchors.centerIn: parent
width: Math.min(parent.width, parent.height) / 2 width: Math.min(parent.width, parent.height) / 2
height: width height: width
source: model.DecorationRole source: model.decoration
} }
PlasmaComponents.Label { PlasmaComponents.Label {
anchors { anchors {
@ -105,7 +106,7 @@ Item {
} }
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
elide: Text.ElideRight elide: Text.ElideRight
text: model.DisplayRole text: model.AppName
} }
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent

View file

@ -20,6 +20,7 @@
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Layouts 1.1 import QtQuick.Layouts 1.1
import QtQuick.Window 2.2 import QtQuick.Window 2.2
import org.kde.taskmanager 0.1 as TaskManager
import org.kde.plasma.core 2.1 as PlasmaCore import org.kde.plasma.core 2.1 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.mobilecomponents 0.2 import org.kde.plasma.mobilecomponents 0.2
@ -33,7 +34,7 @@ FullScreenPanel {
height: Screen.height height: Screen.height
property int offset: 0 property int offset: 0
property int overShoot: units.gridUnit * 2 property int overShoot: units.gridUnit * 2
property int tasksCount: filteredWindowModel.count property int tasksCount: tasksModel.count
property int currentTaskIndex: -1 property int currentTaskIndex: -1
color: Qt.rgba(0, 0, 0, 0.8 * Math.min( color: Qt.rgba(0, 0, 0, 0.8 * Math.min(
@ -41,7 +42,7 @@ FullScreenPanel {
((tasksView.contentHeight - tasksView.contentY - tasksView.headerItem.height - tasksView.footerItem.height)/tasksView.height))) ((tasksView.contentHeight - tasksView.contentY - tasksView.headerItem.height - tasksView.footerItem.height)/tasksView.height)))
function show() { function show() {
if (filteredWindowModel.count == 0) { if (tasksModel.count == 0) {
return; return;
} }
if (!visible) { if (!visible) {
@ -65,19 +66,15 @@ FullScreenPanel {
function setSingleActiveWindow(id) { function setSingleActiveWindow(id) {
var task; var task;
for (var i = 0; i < filteredWindowModel.count; ++i) { for (var i = 0; i < tasksModel.count; ++i) {
task = filteredWindowModel.get(i); task = filterModel.get(i);
if (i == id && task.IsMinimized) { if (i == id) {
//plasmoid.nativeInterface.windowModel.requestToggleMinimized(filteredWindowModel.mapRowToSource(i)); tasksModel.requestActivate(tasksModel.index(i, 0));
plasmoid.nativeInterface.windowModel.requestActivate(filteredWindowModel.mapRowToSource(i));
} else if (i != id && !task.IsMinimized) {
plasmoid.nativeInterface.windowModel.requestToggleMinimized(filteredWindowModel.mapRowToSource(i));
}
}
if (id >= 0) {
plasmoid.nativeInterface.windowModel.requestActivate(filteredWindowModel.mapRowToSource(id));
currentTaskIndex = id; currentTaskIndex = id;
} else if (i != id && !task.IsMinimized) {
tasksModel.requestToggleMinimized(tasksModel.index(i, 0));
}
} }
} }
@ -155,11 +152,13 @@ FullScreenPanel {
} }
} }
TaskManager.TasksModel {
id: tasksModel
}
//This proxy is only used for "get"
PlasmaCore.SortFilterModel { PlasmaCore.SortFilterModel {
id: filteredWindowModel id: filterModel
filterRole: "SkipTaskbar" sourceModel: TaskManager.TasksModel {}
filterRegExp: "false"
sourceModel: plasmoid.nativeInterface.windowModel
onCountChanged: { onCountChanged: {
if (count == 0) { if (count == 0) {
window.hide(); window.hide();
@ -167,7 +166,7 @@ FullScreenPanel {
} }
} }
model: filteredWindowModel model: tasksModel
header: Item { header: Item {
width: window.width width: window.width
height: window.height height: window.height

View file

@ -20,6 +20,7 @@ import QtQuick 2.4
import QtQuick.Layouts 1.1 import QtQuick.Layouts 1.1
import QtQuick.Window 2.2 import QtQuick.Window 2.2
import org.kde.taskmanager 0.1 as TaskManager
import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.components 2.0 as PlasmaComponents
@ -54,7 +55,7 @@ PlasmaCore.ColorScope {
startMouseY = oldMouseY = mouse.y; startMouseY = oldMouseY = mouse.y;
taskSwitcher.offset = -taskSwitcher.height taskSwitcher.offset = -taskSwitcher.height
} }
onPressed: managePressed(); onPressed: managePressed(mouse);
onPositionChanged: { onPositionChanged: {
if (!isDragging && Math.abs(startMouseY - oldMouseY) < root.height) { if (!isDragging && Math.abs(startMouseY - oldMouseY) < root.height) {
oldMouseY = mouse.y; oldMouseY = mouse.y;

View file

@ -72,8 +72,6 @@ void TaskPanel::initWayland()
[this, registry] (quint32 name, quint32 version) { [this, registry] (quint32 name, quint32 version) {
m_windowManagement = registry->createPlasmaWindowManagement(name, version, this); m_windowManagement = registry->createPlasmaWindowManagement(name, version, this);
qRegisterMetaType<QVector<int> >("QVector<int>"); qRegisterMetaType<QVector<int> >("QVector<int>");
m_windowModel = m_windowManagement->createWindowModel();
emit windowModelChanged();
connect(m_windowManagement, &PlasmaWindowManagement::showingDesktopChanged, this, connect(m_windowManagement, &PlasmaWindowManagement::showingDesktopChanged, this,
[this] (bool showing) { [this] (bool showing) {
if (showing == m_showingDesktop) { if (showing == m_showingDesktop) {
@ -85,11 +83,6 @@ void TaskPanel::initWayland()
); );
connect(m_windowManagement, &PlasmaWindowManagement::activeWindowChanged, this, &TaskPanel::updateActiveWindow); connect(m_windowManagement, &PlasmaWindowManagement::activeWindowChanged, this, &TaskPanel::updateActiveWindow);
updateActiveWindow(); updateActiveWindow();
//if a new window is open, show it, not the desktop
connect(m_windowModel, &PlasmaWindowModel::rowsInserted, [this] () {
requestShowingDesktop(false);
});
} }
); );
connect(registry, &Registry::plasmaShellAnnounced, this, connect(registry, &Registry::plasmaShellAnnounced, this,
@ -110,11 +103,6 @@ void TaskPanel::initWayland()
registry->setup(); registry->setup();
} }
QAbstractItemModel *TaskPanel::windowModel() const
{
return m_windowModel;
}
QWindow *TaskPanel::panel() QWindow *TaskPanel::panel()
{ {
return m_panel; return m_panel;
@ -184,23 +172,6 @@ void TaskPanel::closeActiveWindow()
} }
} }
void TaskPanel::setTaskGeometry(int row, int x, int y, int width, int height)
{
using namespace KWayland::Client;
if (!m_shellSurface) {
if (!m_shellInterface || !m_panel || !m_panel->isVisible()) {
return;
}
m_surface = Surface::fromWindow(m_panel);
if (!m_surface) {
return;
}
m_shellSurface = m_shellInterface->createSurface(m_surface, this);
}
m_windowModel->setMinimizedGeometry(row, m_surface, QRect(x, y, width, height));
}
K_EXPORT_PLASMA_APPLET_WITH_JSON(taskpanel, TaskPanel, "metadata.json") K_EXPORT_PLASMA_APPLET_WITH_JSON(taskpanel, TaskPanel, "metadata.json")
#include "taskpanel.moc" #include "taskpanel.moc"

View file

@ -41,7 +41,6 @@ class Surface;
class TaskPanel : public Plasma::Containment class TaskPanel : public Plasma::Containment
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QAbstractItemModel* windowModel READ windowModel NOTIFY windowModelChanged)
Q_PROPERTY(bool showDesktop READ isShowingDesktop WRITE requestShowingDesktop NOTIFY showingDesktopChanged) Q_PROPERTY(bool showDesktop READ isShowingDesktop WRITE requestShowingDesktop NOTIFY showingDesktopChanged)
Q_PROPERTY(bool hasCloseableActiveWindow READ hasCloseableActiveWindow NOTIFY hasCloseableActiveWindowChanged) Q_PROPERTY(bool hasCloseableActiveWindow READ hasCloseableActiveWindow NOTIFY hasCloseableActiveWindowChanged)
Q_PROPERTY(QWindow *panel READ panel WRITE setPanel NOTIFY panelChanged) Q_PROPERTY(QWindow *panel READ panel WRITE setPanel NOTIFY panelChanged)
@ -50,8 +49,6 @@ public:
TaskPanel( QObject *parent, const QVariantList &args ); TaskPanel( QObject *parent, const QVariantList &args );
~TaskPanel(); ~TaskPanel();
QAbstractItemModel *windowModel() const;
QWindow *panel(); QWindow *panel();
void setPanel(QWindow *panel); void setPanel(QWindow *panel);
@ -64,13 +61,10 @@ public:
bool hasCloseableActiveWindow() const; bool hasCloseableActiveWindow() const;
Q_INVOKABLE void setTaskGeometry(int row, int x, int y, int width, int height);
public Q_SLOTS: public Q_SLOTS:
void forgetActiveWindow(); void forgetActiveWindow();
Q_SIGNALS: Q_SIGNALS:
void windowModelChanged();
void showingDesktopChanged(bool); void showingDesktopChanged(bool);
void hasCloseableActiveWindowChanged(); void hasCloseableActiveWindowChanged();
void panelChanged(); void panelChanged();