diff --git a/applets/minimizeall/CMakeLists.txt b/applets/minimizeall/CMakeLists.txt --- a/applets/minimizeall/CMakeLists.txt +++ b/applets/minimizeall/CMakeLists.txt @@ -1,21 +1,2 @@ -add_definitions(-DTRANSLATION_DOMAIN="plasma_applet_org.kde.plasma.minimizeall") - -set(minimizeall_SRCS - plugin/minimizeall.cpp - plugin/minimizeallplugin.cpp -) - -add_library(minimizeallplugin SHARED ${minimizeall_SRCS}) - -target_link_libraries(minimizeallplugin - Qt5::Core - Qt5::Qml - Qt5::Quick - KF5::WindowSystem - ) - -install(TARGETS minimizeallplugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/private/minimizeall) -install(FILES plugin/qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/private/minimizeall) - plasma_install_package(package org.kde.plasma.minimizeall) diff --git a/applets/minimizeall/package/contents/ui/main.qml b/applets/minimizeall/package/contents/ui/main.qml --- a/applets/minimizeall/package/contents/ui/main.qml +++ b/applets/minimizeall/package/contents/ui/main.qml @@ -1,6 +1,7 @@ /* * Copyright 2015 Sebastian Kügler * Copyright 2016 Anthony Fieroni + * Copyright 2018 David Edmundson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,8 +24,7 @@ import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore -import org.kde.plasma.private.minimizeall 1.0 - +import org.kde.taskmanager 0.1 as TaskManager Item { id: root @@ -42,18 +42,68 @@ Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation + Plasmoid.onActivated: toggleActive() + + property bool active: false + property var minimizedClients: [] //list of persistentmodelindexes from task manager model of clients minimised by us + function activate() { - if (!minimizeall.active) { - minimizeall.minimizeAllWindows(); + var clients = [] + for (var i = 0 ; i < tasksModel.count; i++) { + var idx = tasksModel.makeModelIndex(i); + if (!tasksModel.data(idx, TaskManager.AbstractTasksModel.IsMinimized)) { + tasksModel.requestToggleMinimized(idx); + clients.push(tasksModel.makePersistentModelIndex(i)); + } + } + root.minimizedClients = clients; + root.active = true; + } + + function deactivate() { + root.active = false; + for (var i = 0 ; i < root.minimizedClients.length; i++) { + var idx = root.minimizedClients[i] + //client deleted, do nothing + if (!idx.valid) { + continue; + } + //if the user has restored it already, do nothing + if (!tasksModel.data(idx, TaskManager.AbstractTasksModel.IsMinimized)) { + continue; + } + tasksModel.requestToggleMinimized(idx); + } + root.minimizedClients = []; + } + + function toggleActive() { + if (root.active) { + deactivate(); } else { - minimizeall.unminimizeAllWindows(); + activate(); } } - Plasmoid.onActivated: activate() + TaskManager.TasksModel { + id: tasksModel + sortMode: TaskManager.TasksModel.SortDisabled + groupMode: TaskManager.TasksModel.GroupDisabled + } - MinimizeAll { - id: minimizeall + Connections { + target: tasksModel + enabled: root.active + onDataChanged: { + for (var i = topLeft.row; i <= bottomRight.row ; i++) { + var idx = tasksModel.makeModelIndex(i); + if (!tasksModel.data(idx, TaskManager.AbstractTasksModel.IsMinimized)) { + deactivate(); + } + } + } + onVirtualDesktopChanged: deactivate() + onActivityChanged: deactivate() } PlasmaCore.FrameSvgItem { @@ -80,7 +130,7 @@ } return prefix; } - opacity: minimizeall.active ? 1 : 0 + opacity: root.active ? 1 : 0 Behavior on opacity { NumberAnimation { duration: units.shortDuration @@ -106,7 +156,7 @@ MouseArea { id: mouseArea anchors.fill: parent - onClicked: activate() + onClicked: root.toggleActive() } //also activate when dragging an item over the plasmoid so a user can easily drag data to the desktop DropArea { @@ -116,7 +166,7 @@ Timer { id: activateTimer interval: 250 //to match TaskManager - onTriggered: activate() + onTriggered: toggleActive() } } } diff --git a/applets/minimizeall/plugin/minimizeall.h b/applets/minimizeall/plugin/minimizeall.h deleted file mode 100644 --- a/applets/minimizeall/plugin/minimizeall.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2015 Sebastian Kügler - * Copyright 2016 Anthony Fieroni - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - - -#ifndef MINIMIZEALL_HEADER -#define MINIMIZEALL_HEADER - -#include -#include - -class MinimizeAll : public QObject -{ - -Q_OBJECT -Q_PROPERTY(bool active READ active NOTIFY activeChanged) - -public: - MinimizeAll(); - ~MinimizeAll() override; - - Q_INVOKABLE void minimizeAllWindows(); - Q_INVOKABLE void unminimizeAllWindows(); - - bool active() const; - -public Q_SLOTS: - void deactivate(bool unminimize); - -Q_SIGNALS: - void activeChanged(); - -private: - bool match(const WId &wid, bool includehidden = true) const; - QList m_minimizedWindows; - bool m_active; -}; - -#endif //MINIMIZEALL_HEADER diff --git a/applets/minimizeall/plugin/minimizeall.cpp b/applets/minimizeall/plugin/minimizeall.cpp deleted file mode 100644 --- a/applets/minimizeall/plugin/minimizeall.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2015 Sebastian Kügler - * Copyright 2016 Anthony Fieroni - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "minimizeall.h" - -#include - -#include -#include - -MinimizeAll::MinimizeAll() -{ - m_active = false; -} - -MinimizeAll::~MinimizeAll() -{ -} - -bool MinimizeAll::active() const -{ - return m_active; -} - -void MinimizeAll::minimizeAllWindows() -{ - m_minimizedWindows.clear(); - - Q_FOREACH (auto wid, KWindowSystem::self()->stackingOrder()) { - if (match(wid, false)) { - m_minimizedWindows << wid; - KWindowSystem::self()->minimizeWindow(wid); - } - } - - if (m_minimizedWindows.isEmpty()) { - return; - } - - if (!m_active) { - m_active = true; - Q_EMIT activeChanged(); - } - - const auto connectionType = Qt::ConnectionType(Qt::UniqueConnection | Qt::QueuedConnection); - - connect(KWindowSystem::self(), static_cast(&KWindowSystem::windowChanged), - this, [this](WId wid) { if (match(wid, false)) deactivate(false); }, connectionType); - connect(KWindowSystem::self(), &KWindowSystem::currentDesktopChanged, - this, [this]() { deactivate(false); }, connectionType); - connect(KWindowSystem::self(), &KWindowSystem::stackingOrderChanged, - this, [this]() { deactivate(false); }, connectionType); -} - -void MinimizeAll::unminimizeAllWindows() -{ - deactivate(true); -} - -bool MinimizeAll::match(const WId& wid, bool includehidden) const -{ - bool match = true; - KWindowInfo info(wid, NET::WMState | NET::WMWindowType | NET::WMDesktop); - if (!includehidden && info.hasState(NET::Hidden)) { - match = false; - } else if (info.windowType(NET::DesktopMask) == NET::Desktop) { - match = false; - } else if (info.windowType(NET::DockMask) == NET::Dock) { - match = false; - } else if (!info.isOnCurrentDesktop()) { - match = false; - } - return match; -} - -void MinimizeAll::deactivate(bool unminimize) -{ - if (m_active) { - disconnect(KWindowSystem::self(), nullptr, this, nullptr); - - if (unminimize) { - Q_FOREACH (auto wid, m_minimizedWindows) { - if (match(wid)) { - KWindowSystem::self()->unminimizeWindow(wid); - } - } - } - m_active = false; - Q_EMIT activeChanged(); - } -} - diff --git a/applets/minimizeall/plugin/minimizeallplugin.h b/applets/minimizeall/plugin/minimizeallplugin.h deleted file mode 100644 --- a/applets/minimizeall/plugin/minimizeallplugin.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2015 Sebastian Kügler - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - - -#ifndef MINIMIZEALLPLUGIN_H -#define MINIMIZEALLPLUGIN_H - -#include -#include -#include - -class MinimizeAllPlugin : public QQmlExtensionPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") - -public: - void registerTypes(const char *uri) override; -}; - -#endif // MINIMIZEALLPLUGIN_H diff --git a/applets/minimizeall/plugin/minimizeallplugin.cpp b/applets/minimizeall/plugin/minimizeallplugin.cpp deleted file mode 100644 --- a/applets/minimizeall/plugin/minimizeallplugin.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2015 Sebastian Kügler - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "minimizeallplugin.h" -#include "minimizeall.h" - -// Qt -#include - -void MinimizeAllPlugin::registerTypes(const char *uri) -{ - Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.plasma.private.minimizeall")); - qmlRegisterType(uri, 1, 0, "MinimizeAll"); -} diff --git a/applets/minimizeall/plugin/qmldir b/applets/minimizeall/plugin/qmldir deleted file mode 100644 --- a/applets/minimizeall/plugin/qmldir +++ /dev/null @@ -1,2 +0,0 @@ -module org.kde.plasma.private.minimizeall -plugin minimizeallplugin