Verified Commit 88ac5a9a authored by ivan tkachenko's avatar ivan tkachenko
Browse files

Revert "[applets/showdesktop]" Refactoring

This reverts commits 53c9a31d through 1b34b968.

They were accidentally committed to the master branch without going
through a proper review.
parent 1b34b968
Pipeline #226213 passed with stage
in 5 minutes and 1 second
/*
SPDX-FileCopyrightText: 2022 ivan (@ratijas) tkachenko <me@ratijas.tk>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQml 2.15
QtObject {
/**
* Whether the effect is currently active, and can be deactivated.
*/
property bool active
property string titleActive
property string titleInactive
property string descriptionActive
property string descriptionInactive
readonly property string title: active ? titleActive : titleInactive
readonly property string description: active ? descriptionActive : descriptionInactive
// virtual
function toggle() {}
}
......@@ -2,23 +2,16 @@
SPDX-FileCopyrightText: 2015 Sebastian Kügler <sebas@kde.org>
SPDX-FileCopyrightText: 2016 Anthony Fieroni <bvbfan@abv.bg>
SPDX-FileCopyrightText: 2018 David Edmundson <davidedmundson@kde.org>
SPDX-FileCopyrightText: 2022 ivan (@ratijas) tkachenko <me@ratijas.tk>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQml 2.15
import QtQuick 2.15
import org.kde.taskmanager 0.1 as TaskManager
Controller {
id: controller
titleActive: i18nc("@action:button", "Restore All Minimized Windows")
titleInactive: i18nc("@action:button", "Minimize All Windows")
descriptionActive: i18nc("@info:tooltip", "Restores the previously minimized windows")
descriptionInactive: i18nc("@info:tooltip", "Shows the Desktop by minimizing all windows")
QtObject {
id: component
readonly property QtObject tasksModel: TaskManager.TasksModel {
id: tasksModel
......@@ -28,24 +21,29 @@ Controller {
readonly property Connections activeTaskChangedConnection: Connections {
target: tasksModel
enabled: controller.active
enabled: component.active
function onActiveTaskChanged() {
if (tasksModel.activeTask.valid) { // to suppress changing focus to non windows, such as the desktop
controller.active = false;
controller.minimizedClients = [];
component.active = false;
component.minimizedClients = [];
}
}
function onVirtualDesktopChanged() {
controller.deactivate();
component.deactivate();
}
function onActivityChanged() {
controller.deactivate();
component.deactivate();
}
}
/**
* Whether the "minimize all" effect is activated
*/
property bool active: false
/**
* List of persistent model indexes from task manager model of
* clients minimized by us
......@@ -82,8 +80,7 @@ Controller {
minimizedClients = [];
}
// override
function toggle() {
function toggleActive() {
if (active) {
deactivate();
} else {
......
/*
SPDX-FileCopyrightText: 2022 ivan (@ratijas) tkachenko <me@ratijas.tk>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import org.kde.plasma.private.showdesktop 0.1
Controller {
id: controller
titleActive: i18nc("@action:button", "Stop Peeking at Desktop")
titleInactive: i18nc("@action:button", "Peek at Desktop")
descriptionActive: i18nc("@info:tooltip", "Moves windows back to their original positions")
descriptionInactive: i18nc("@info:tooltip", "Temporarily reveals the Desktop by moving open windows into screen corners")
active: showdesktop.showingDesktop
// override
function toggle() {
showdesktop.toggleDesktop();
}
readonly property ShowDesktop showdesktop: ShowDesktop {
id: showdesktop
}
}
/*
SPDX-FileCopyrightText: 2014 Ashish Madeti <ashishmadeti@gmail.com>
SPDX-FileCopyrightText: 2016 Kai Uwe Broulik <kde@privat.broulik.de>
SPDX-FileCopyrightText: 2022 ivan (@ratijas) tkachenko <me@ratijas.tk>
SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -13,6 +12,8 @@ import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.private.showdesktop 0.1
MouseArea {
id: root
......@@ -25,11 +26,23 @@ MouseArea {
*/
readonly property bool isMinimizeAll: Plasmoid.pluginName === "org.kde.plasma.minimizeall"
readonly property Controller primaryController: isMinimizeAll ? minimizeAllController : peekController
readonly property bool isMinimizing: minimizeAllComponent.status === Loader.Ready ? minimizeAllComponent.item.active : false
Plasmoid.icon: Plasmoid.configuration.icon
Plasmoid.title: primaryController.title
Plasmoid.toolTipSubText: primaryController.description
Plasmoid.title: {
if (isMinimizeAll) {
return isMinimizing ? i18nc("@action:button", "Restore All Minimized Windows") : i18nc("@action", "Minimize All Windows");
}
return showdesktop.showingDesktop ? i18nc("@action:button", "Stop Peeking at Desktop") : i18nc("@action:button", "Peek at Desktop");
}
Plasmoid.toolTipSubText: {
if (isMinimizeAll) {
return isMinimizing ? i18nc("@info:tooltip", "Restores the previously minimized windows") : i18n("Shows the Desktop by minimizing all windows");
}
return showdesktop.showingDesktop ? i18nc("@info:tooltip", "Moves windows back to their original positions") : i18n("Temporarily reveals the Desktop by moving open windows into screen corners");
}
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
Plasmoid.backgroundHints: PlasmaCore.Types.NoBackground
......@@ -43,7 +56,14 @@ MouseArea {
activeFocusOnTab: true
hoverEnabled: true
Plasmoid.onActivated: primaryController.toggle();
Plasmoid.onActivated: {
if (isMinimizeAll) {
minimizeAllComponent.item.toggleActive();
return;
}
showdesktop.toggleDesktop();
}
onClicked: Plasmoid.activated();
Keys.onPressed: {
......@@ -61,17 +81,19 @@ MouseArea {
Accessible.description: Plasmoid.toolTipSubText
Accessible.role: Accessible.Button
PeekController {
id: peekController
ShowDesktop {
id: showdesktop
}
MinimizeAllController {
id: minimizeAllController
Loader {
id: minimizeAllComponent
active: root.isMinimizeAll
source: "MinimizeAllComponent.qml"
}
PlasmaCore.IconItem {
anchors.fill: parent
active: root.containsMouse || primaryController.active
active: root.containsMouse || showdesktop.showingDesktop
source: Plasmoid.icon
}
......@@ -133,7 +155,13 @@ MouseArea {
}
return prefix;
}
opacity: primaryController.active ? 1 : 0
opacity: {
if (isMinimizeAll) {
return isMinimizing ? 1 : 0;
}
return showdesktop.showingDesktop ? 1 : 0;
}
Behavior on opacity {
NumberAnimation {
......@@ -152,28 +180,15 @@ MouseArea {
}
function action_minimizeall() {
minimizeAllController.toggle();
showdesktop.minimizeAll();
}
function action_peek() {
peekController.toggle();
function action_showdesktop() {
showdesktop.toggleDesktop();
}
Component.onCompleted: {
var action;
Plasmoid.setAction("minimizeall", "");
action = Plasmoid.action("minimizeall")
action.checkable = true;
action.checked = Qt.binding(() => minimizeAllController.active);
action.text = Qt.binding(() => minimizeAllController.title);
action.toolTip = Qt.binding(() => minimizeAllController.description);
Plasmoid.setAction("peek", "");
action = Plasmoid.action("peek")
action.checkable = true;
action.checked = Qt.binding(() => peekController.active);
action.text = Qt.binding(() => peekController.title);
action.toolTip = Qt.binding(() => peekController.description);
Plasmoid.setAction("minimizeall", i18nc("@action", "Minimize All Windows"));
Plasmoid.setAction("showdesktop", i18nc("@action:button", "Peek at Desktop"));
}
}
......@@ -39,6 +39,14 @@ void ShowDesktop::setShowingDesktop(bool showingDesktop)
Q_EMIT showingDesktopChanged(showingDesktop);
}
void ShowDesktop::minimizeAll()
{
const auto &windows = KWindowSystem::windows();
for (WId wid : windows) {
KWindowSystem::minimizeWindow(wid);
}
}
void ShowDesktop::toggleDesktop()
{
setShowingDesktop(!showingDesktop());
......
......@@ -24,6 +24,7 @@ public:
bool showingDesktop() const;
void setShowingDesktop(bool showingDesktop);
Q_INVOKABLE void minimizeAll();
Q_INVOKABLE void toggleDesktop();
Q_SIGNALS:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment