From ee7597de7bf8a54116285e8c29dbdfb36783c686 Mon Sep 17 00:00:00 2001 From: Pier Luigi Fiorini Date: Sat, 8 Nov 2014 23:33:43 +0100 Subject: [PATCH] Add button to close application windows --- compositor/contents/Compositor.qml | 44 ++++++++++++++++++++----- compositor/contents/WindowManagement.js | 3 ++ compositor/contents/WindowWrapper.qml | 7 ++++ 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/compositor/contents/Compositor.qml b/compositor/contents/Compositor.qml index b9df6add..c0749f51 100644 --- a/compositor/contents/Compositor.qml +++ b/compositor/contents/Compositor.qml @@ -18,6 +18,7 @@ */ import QtQuick 2.0 +import QtQuick.Layouts 1.0 import org.kde.plasma.core 2.0 as PlasmaCore import "WindowManagement.js" as WindowManagement @@ -27,6 +28,7 @@ Rectangle { readonly property alias layers: layers readonly property real topBarHeight: units.iconSizes.small readonly property real bottomBarHeight: units.iconSizes.medium + property var currentWindow: null id: compositorRoot color: "black" @@ -89,16 +91,40 @@ Rectangle { } } - PlasmaCore.IconItem { - anchors.centerIn: parent - colorGroup: PlasmaCore.Theme.ComplementaryColorGroup - width: units.iconSizes.smallMedium - height: width - source: "go-home" + ColumnLayout { + anchors.fill: parent - MouseArea { - anchors.fill: parent - onClicked: showHome = true + PlasmaCore.IconItem { + colorGroup: PlasmaCore.Theme.ComplementaryColorGroup + width: units.iconSizes.smallMedium + height: width + source: "window-close" + + Layout.alignment: Qt.AlignHCenter + + MouseArea { + anchors.fill: parent + onClicked: { + if (currentWindow) { + currentWindow.close(); + currentWindow = null; + } + } + } + } + + PlasmaCore.IconItem { + colorGroup: PlasmaCore.Theme.ComplementaryColorGroup + width: units.iconSizes.smallMedium + height: width + source: "go-home" + + Layout.alignment: Qt.AlignHCenter + + MouseArea { + anchors.fill: parent + onClicked: showHome = true + } } } } diff --git a/compositor/contents/WindowManagement.js b/compositor/contents/WindowManagement.js index 02845550..136f0eaf 100644 --- a/compositor/contents/WindowManagement.js +++ b/compositor/contents/WindowManagement.js @@ -131,6 +131,7 @@ function mapApplicationSurface(surface) { // Switch to the applications layer and take focus compositorRoot.showHome = false; + compositorRoot.currentWindow = window; window.child.takeFocus(); // Run map animation @@ -160,6 +161,7 @@ function mapShellSurface(surface, child) { // Switch to the desktop layer and take focus compositorRoot.showHome = true; + compositorRoot.currentWindow = null; entry.window.child.takeFocus(); return; @@ -202,6 +204,7 @@ function mapShellSurface(surface, child) { function unmapApplicationSurface(surface) { // Reactivate home layer as soon as an application window is unmapped compositorRoot.showHome = true; + compositorRoot.currentWindow = null; } function unmapShellSurface(surface) { diff --git a/compositor/contents/WindowWrapper.qml b/compositor/contents/WindowWrapper.qml index b5c5d237..7756a068 100644 --- a/compositor/contents/WindowWrapper.qml +++ b/compositor/contents/WindowWrapper.qml @@ -37,4 +37,11 @@ Item { anchors.fill: parent source: child } + + function close() { + if (!child || !child.surface) + return; + + child.surface.client.close(); + } }