Verified Commit 152d00d7 authored by ivan tkachenko's avatar ivan tkachenko
Browse files

Sync/unify minimizeall & showdesktop applets, add support for keyboard navigation

This turns out to be quite a refactoring, but in the end we get a
flattened component hierarchy, consistent structure and behavior, and
of course the keyboard navigation (Meta+Alt+P).

For feature parity, minimizeall applet now also have a parity action
from its sister-applet.

BUG: 454651
parent aebfb005
Pipeline #192553 passed with stage
in 2 minutes and 40 seconds
......@@ -14,13 +14,23 @@ import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.taskmanager 0.1 as TaskManager
Item {
MouseArea {
id: root
readonly property bool inPanel: (plasmoid.location === PlasmaCore.Types.TopEdge
|| plasmoid.location === PlasmaCore.Types.RightEdge
|| plasmoid.location === PlasmaCore.Types.BottomEdge
|| plasmoid.location === PlasmaCore.Types.LeftEdge)
readonly property bool inPanel: [PlasmaCore.Types.TopEdge, PlasmaCore.Types.RightEdge, PlasmaCore.Types.BottomEdge, PlasmaCore.Types.LeftEdge]
.includes(Plasmoid.location)
property bool active: false
// list of persistentmodelindexes from task manager model of clients minimised by us
property var minimizedClients: []
Plasmoid.icon: Plasmoid.configuration.icon
Plasmoid.title: i18n("Minimize all Windows")
Plasmoid.toolTipSubText: i18n("Show the desktop by minimizing all windows")
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
Plasmoid.backgroundHints: PlasmaCore.Types.NoBackground
Layout.minimumWidth: PlasmaCore.Units.gridUnit
Layout.minimumHeight: PlasmaCore.Units.gridUnit
......@@ -28,18 +38,30 @@ Item {
Layout.maximumWidth: inPanel ? PlasmaCore.Units.iconSizeHints.panel : -1
Layout.maximumHeight: inPanel ? PlasmaCore.Units.iconSizeHints.panel : -1
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
Plasmoid.backgroundHints: PlasmaCore.Types.NoBackground
Plasmoid.onActivated: toggleActive()
property bool active: false
property var minimizedClients: [] //list of persistentmodelindexes from task manager model of clients minimised by us
onClicked: Plasmoid.activated()
hoverEnabled: true
activeFocusOnTab: true
Keys.onPressed: {
switch (event.key) {
case Qt.Key_Space:
case Qt.Key_Enter:
case Qt.Key_Return:
case Qt.Key_Select:
Plasmoid.activated();
break;
}
}
Accessible.name: Plasmoid.title
Accessible.description: Plasmoid.toolTipSubText
Accessible.role: Accessible.Button
function activate() {
var clients = []
for (var i = 0 ; i < tasksModel.count; i++) {
var idx = tasksModel.makeModelIndex(i);
const clients = [];
for (let i = 0 ; i < tasksModel.count; i++) {
const idx = tasksModel.makeModelIndex(i);
if (!tasksModel.data(idx, TaskManager.AbstractTasksModel.IsHidden)) {
tasksModel.requestToggleMinimized(idx);
clients.push(tasksModel.makePersistentModelIndex(i));
......@@ -51,13 +73,13 @@ Item {
function deactivate() {
root.active = false;
for (var i = 0 ; i < root.minimizedClients.length; i++) {
var idx = root.minimizedClients[i]
//client deleted, do nothing
for (let i = 0 ; i < root.minimizedClients.length; i++) {
const idx = root.minimizedClients[i];
// client deleted, do nothing
if (!idx.valid) {
continue;
}
//if the user has restored it already, do nothing
// if the user has restored it already, do nothing
if (!tasksModel.data(idx, TaskManager.AbstractTasksModel.IsHidden)) {
continue;
}
......@@ -76,6 +98,7 @@ Item {
TaskManager.TasksModel {
id: tasksModel
sortMode: TaskManager.TasksModel.SortDisabled
groupMode: TaskManager.TasksModel.GroupDisabled
}
......@@ -85,18 +108,41 @@ Item {
enabled: root.active
function onActiveTaskChanged() {
if (tasksModel.activeTask.valid) { //to suppress changing focus to non windows, such as the desktop
if (tasksModel.activeTask.valid) { // to suppress changing focus to non windows, such as the desktop
root.active = false;
root.minimizedClients = [];
}
}
function onVirtualDesktopChanged() {deactivate()}
function onActivityChanged() {deactivate()}
function onVirtualDesktopChanged() {
deactivate();
}
function onActivityChanged() {
deactivate();
}
}
PlasmaCore.IconItem {
anchors.fill: parent
active: root.containsMouse
source: Plasmoid.icon
}
// also activate when dragging an item over the plasmoid so a user can easily drag data to the desktop
DropArea {
anchors.fill: parent
onEntered: activateTimer.start()
onExited: activateTimer.stop()
}
Timer {
id: activateTimer
interval: 250 // to match TaskManager
onTriggered: Plasmoid.activated()
}
PlasmaCore.FrameSvgItem {
property var containerMargins: {
let item = tooltip;
let item = this;
while (item.parent) {
item = item.parent;
if (item.isAppletContainer) {
......@@ -111,26 +157,26 @@ Item {
property bool returnAllMargins: true
// The above makes sure margin is returned even for side margins
// that would be otherwise turned off.
bottomMargin: containerMargins ? -containerMargins('bottom', returnAllMargins) : 0;
topMargin: containerMargins ? -containerMargins('top', returnAllMargins) : 0;
leftMargin: containerMargins ? -containerMargins('left', returnAllMargins) : 0;
rightMargin: containerMargins ? -containerMargins('right', returnAllMargins) : 0;
topMargin: containerMargins ? -containerMargins('top', returnAllMargins) : 0
leftMargin: containerMargins ? -containerMargins('left', returnAllMargins) : 0
rightMargin: containerMargins ? -containerMargins('right', returnAllMargins) : 0
bottomMargin: containerMargins ? -containerMargins('bottom', returnAllMargins) : 0
}
imagePath: "widgets/tabbar"
prefix: {
var prefix;
switch (plasmoid.location) {
case PlasmaCore.Types.LeftEdge:
prefix = "west-active-tab";
break;
case PlasmaCore.Types.TopEdge:
prefix = "north-active-tab";
break;
case PlasmaCore.Types.RightEdge:
prefix = "east-active-tab";
break;
default:
prefix = "south-active-tab";
let prefix;
switch (Plasmoid.location) {
case PlasmaCore.Types.LeftEdge:
prefix = "west-active-tab";
break;
case PlasmaCore.Types.TopEdge:
prefix = "north-active-tab";
break;
case PlasmaCore.Types.RightEdge:
prefix = "east-active-tab";
break;
default:
prefix = "south-active-tab";
}
if (!hasElementPrefix(prefix)) {
prefix = "active-tab";
......@@ -146,34 +192,11 @@ Item {
}
}
PlasmaCore.IconItem {
id:icon
source: plasmoid.configuration.icon
active: tooltip.containsMouse
anchors.fill: parent
function action_showdesktop() {
showdesktop.toggleDesktop();
}
PlasmaCore.ToolTipArea {
id: tooltip
anchors.fill: parent
mainText : i18n("Minimize all Windows")
subText : i18n("Show the desktop by minimizing all windows")
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: root.toggleActive()
}
//also activate when dragging an item over the plasmoid so a user can easily drag data to the desktop
DropArea {
anchors.fill: parent
onEntered: activateTimer.start()
onExited: activateTimer.stop()
Timer {
id: activateTimer
interval: 250 //to match TaskManager
onTriggered: toggleActive()
}
}
Component.onCompleted: {
Plasmoid.setAction("showdesktop", i18nc("@action", "Show Desktop"))
}
}
......@@ -14,133 +14,125 @@ import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.private.showdesktop 0.1
QtObject {
MouseArea {
id: root
// you can't have an applet with just a compact representation :(
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
Plasmoid.onActivated: showdesktop.showingDesktop = !showdesktop.showingDesktop
readonly property bool inPanel: [PlasmaCore.Types.TopEdge, PlasmaCore.Types.RightEdge, PlasmaCore.Types.BottomEdge, PlasmaCore.Types.LeftEdge]
.includes(Plasmoid.location)
Plasmoid.icon: Plasmoid.configuration.icon
Plasmoid.title: i18n("Show Desktop")
Plasmoid.toolTipSubText: i18n("Show the desktop by moving windows aside")
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
Plasmoid.backgroundHints: PlasmaCore.Types.NoBackground
// QtObject has no default property
property QtObject showdesktop: ShowDesktop { }
Layout.minimumWidth: PlasmaCore.Units.iconSizes.small
Layout.minimumHeight: PlasmaCore.Units.iconSizes.small
Component.onCompleted: {
Plasmoid.setAction("minimizeall", i18nc("@action", "Minimize All Windows"))
}
Layout.maximumWidth: inPanel ? PlasmaCore.Units.iconSizeHints.panel : -1
Layout.maximumHeight: inPanel ? PlasmaCore.Units.iconSizeHints.panel : -1
function action_minimizeall() {
showdesktop.minimizeAll()
}
Plasmoid.onActivated: showdesktop.toggleDesktop()
onClicked: Plasmoid.activated();
Plasmoid.fullRepresentation: PlasmaCore.ToolTipArea {
id: fullRep
hoverEnabled: true
readonly property bool inPanel: [PlasmaCore.Types.TopEdge, PlasmaCore.Types.RightEdge, PlasmaCore.Types.BottomEdge, PlasmaCore.Types.LeftEdge]
.includes(Plasmoid.location)
activeFocusOnTab: true
Keys.onPressed: {
switch (event.key) {
case Qt.Key_Space:
case Qt.Key_Enter:
case Qt.Key_Return:
case Qt.Key_Select:
Plasmoid.activated();
break;
}
}
Accessible.name: Plasmoid.title
Accessible.description: Plasmoid.toolTipSubText
Accessible.role: Accessible.Button
Layout.minimumWidth: PlasmaCore.Units.iconSizes.small
Layout.minimumHeight: PlasmaCore.Units.iconSizes.small
ShowDesktop { id: showdesktop }
PlasmaCore.IconItem {
anchors.fill: parent
active: root.containsMouse || showdesktop.showingDesktop
source: Plasmoid.icon
}
Layout.maximumWidth: inPanel ? PlasmaCore.Units.iconSizeHints.panel : -1
Layout.maximumHeight: inPanel ? PlasmaCore.Units.iconSizeHints.panel : -1
// also activate when dragging an item over the plasmoid so a user can easily drag data to the desktop
DropArea {
anchors.fill: parent
onEntered: activateTimer.start()
onExited: activateTimer.stop()
}
mainText: Plasmoid.title
subText: Plasmoid.toolTipSubText
Timer {
id: activateTimer
interval: 250 // to match TaskManager
onTriggered: Plasmoid.activated()
}
MouseArea {
anchors.fill: parent
activeFocusOnTab: true
Keys.onPressed: {
switch (event.key) {
case Qt.Key_Space:
case Qt.Key_Enter:
case Qt.Key_Return:
case Qt.Key_Select:
showdesktop.showingDesktop = !showdesktop.showingDesktop;
break;
// Active/not active indicator
PlasmaCore.FrameSvgItem {
property var containerMargins: {
let item = this;
while (item.parent) {
item = item.parent;
if (item.isAppletContainer) {
return item.getMargins;
}
}
Accessible.name: root.Plasmoid.title
Accessible.description: root.Plasmoid.toolTipSubText
Accessible.role: Accessible.Button
onClicked: showdesktop.showingDesktop = !showdesktop.showingDesktop
}
PlasmaCore.IconItem {
anchors.fill: parent
source: Plasmoid.icon
active: parent.containsMouse || showdesktop.showingDesktop
return undefined;
}
// also activate when dragging an item over the plasmoid so a user can easily drag data to the desktop
DropArea {
anchors.fill: parent
onEntered: activateTimer.start()
onExited: activateTimer.stop()
Timer {
id: activateTimer
interval: 250 //to match TaskManager
onTriggered: Plasmoid.activated()
}
anchors {
fill: parent
property bool returnAllMargins: true
// The above makes sure margin is returned even for side margins
// that would be otherwise turned off.
topMargin: containerMargins ? -containerMargins('top', returnAllMargins) : 0
leftMargin: containerMargins ? -containerMargins('left', returnAllMargins) : 0
rightMargin: containerMargins ? -containerMargins('right', returnAllMargins) : 0
bottomMargin: containerMargins ? -containerMargins('bottom', returnAllMargins) : 0
}
// Active/not active indicator
PlasmaCore.FrameSvgItem {
property var containerMargins: {
let item = fullRep;
while (item.parent) {
item = item.parent;
if (item.isAppletContainer) {
return item.getMargins;
}
}
return undefined;
imagePath: "widgets/tabbar"
visible: fromCurrentTheme && opacity > 0
prefix: {
let prefix;
switch (Plasmoid.location) {
case PlasmaCore.Types.LeftEdge:
prefix = "west-active-tab";
break;
case PlasmaCore.Types.TopEdge:
prefix = "north-active-tab";
break;
case PlasmaCore.Types.RightEdge:
prefix = "east-active-tab";
break;
default:
prefix = "south-active-tab";
}
anchors {
fill: parent
property bool returnAllMargins: true
// The above makes sure margin is returned even for side margins
// that would be otherwise turned off.
bottomMargin: containerMargins ? -containerMargins('bottom', returnAllMargins) : 0
topMargin: containerMargins ? -containerMargins('top', returnAllMargins) : 0
leftMargin: containerMargins ? -containerMargins('left', returnAllMargins) : 0
rightMargin: containerMargins ? -containerMargins('right', returnAllMargins) : 0
if (!hasElementPrefix(prefix)) {
prefix = "active-tab";
}
imagePath: "widgets/tabbar"
visible: fromCurrentTheme && opacity > 0
prefix: {
let prefix;
switch (Plasmoid.location) {
case PlasmaCore.Types.LeftEdge:
prefix = "west-active-tab";
break;
case PlasmaCore.Types.TopEdge:
prefix = "north-active-tab";
break;
case PlasmaCore.Types.RightEdge:
prefix = "east-active-tab";
break;
default:
prefix = "south-active-tab";
}
if (!hasElementPrefix(prefix)) {
prefix = "active-tab";
}
return prefix;
}
opacity: showdesktop.showingDesktop ? 1 : 0
Behavior on opacity {
NumberAnimation {
duration: PlasmaCore.Units.shortDuration
easing.type: Easing.InOutQuad
}
return prefix;
}
opacity: showdesktop.showingDesktop ? 1 : 0
Behavior on opacity {
NumberAnimation {
duration: PlasmaCore.Units.shortDuration
easing.type: Easing.InOutQuad
}
}
}
function action_minimizeall() {
showdesktop.minimizeAll();
}
Component.onCompleted: {
Plasmoid.setAction("minimizeall", i18nc("@action", "Minimize All Windows"))
}
}
......@@ -28,6 +28,7 @@ bool ShowDesktop::showingDesktop() const
void ShowDesktop::setShowingDesktop(bool showingDesktop)
{
KWindowSystem::setShowingDesktop(showingDesktop);
Q_EMIT showingDesktopChanged(showingDesktop);
}
void ShowDesktop::minimizeAll()
......@@ -46,3 +47,10 @@ void ShowDesktop::minimizeAll()
}
}
}
void ShowDesktop::toggleDesktop()
{
const bool showingNow = KWindowSystem::showingDesktop();
KWindowSystem::setShowingDesktop(!showingNow);
Q_EMIT showingDesktopChanged(!showingNow);
}
......@@ -23,6 +23,7 @@ public:
void setShowingDesktop(bool showingDesktop);
Q_INVOKABLE void minimizeAll();
Q_INVOKABLE void toggleDesktop();
Q_SIGNALS:
void showingDesktopChanged(bool showingDesktop);
......
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