on xenial help sign in
Add window control buttons to panel for fullscreen applications

Approved by: Gerry Boland

commite2456386907e5c29a31d2a330b26b40b93e2c2ad authorMichael Zanetti <michael.zanetti@canonical.com> dateThu 11 Dec 2014, 13:24 (12 years ago) parent0f896a3c3bc4a1
6 files changed+135−32
qml/Components/PanelState/PanelState.qml+29 qml/Components/PanelState/qmldir+1 qml/Components/WindowControlButtons.qml+60 qml/Panel/Panel.qml+17−2 qml/Stages/DesktopStage.qml+20 qml/Stages/WindowDecoration.qml+8−30
qml/Components/PanelState/PanelState.qmlnew file+29
@@ -0,0 +1,29 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+pragma Singleton
18+import QtQuick 2.0
19+
20+QtObject {
21+ id: root
22+
23+ property string title: ""
24+ property bool buttonsVisible: false
25+
26+ signal close()
27+ signal minimize()
28+ signal maximize()
29+}
qml/Components/PanelState/qmldirnew file+1
@@ -0,0 +1 @@
1+singleton PanelState 1.0 PanelState.qml
qml/Components/WindowControlButtons.qmlnew file+60
@@ -0,0 +1,60 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
17+ */
18+
19+import QtQuick 2.3
20+import Ubuntu.Components 1.1
21+
22+Row {
23+ id: root
24+ spacing: units.gu(0.5)
25+
26+ signal close()
27+ signal minimize()
28+ signal maximize()
29+
30+ Rectangle {
31+ height: parent.height; width: height; radius: height / 2
32+ gradient: Gradient {
33+ GradientStop { color: "#F49073"; position: 0 }
34+ GradientStop { color: "#DF4F1C"; position: 1 }
35+ }
36+ border.width: units.dp(.5)
37+ border.color: "black"
38+ MouseArea { anchors.fill: parent; onClicked: root.close() }
39+ }
40+ Rectangle {
41+ height: parent.height; width: height; radius: height / 2
42+ gradient: Gradient {
43+ GradientStop { color: "#92918C"; position: 0 }
44+ GradientStop { color: "#5E5D58"; position: 1 }
45+ }
46+ border.width: units.dp(.5)
47+ border.color: "black"
48+ MouseArea { anchors.fill: parent; onClicked: root.minimize() }
49+ }
50+ Rectangle {
51+ height: parent.height; width: height; radius: height / 2
52+ gradient: Gradient {
53+ GradientStop { color: "#92918C"; position: 0 }
54+ GradientStop { color: "#5E5D58"; position: 1 }
55+ }
56+ border.width: units.dp(.5)
57+ border.color: "black"
58+ MouseArea { anchors.fill: parent; onClicked: root.maximize() }
59+ }
60+}
qml/Panel/Panel.qml+17−2
@@ -18,6 +18,7 @@ import QtQuick 2.2
1818import Ubuntu.Components 1.1
1919import Unity.Application 0.1
2020import "../Components"
21+import "../Components/PanelState"
2122import ".."
2223
2324Item {
@@ -123,7 +124,7 @@ Item {
123124 }
124125
125126 shown: false
126− width: root.width
127+ width: root.width - (PanelState.buttonsVisible ? windowControlButtons.width : 0)
127128 minimizedPanelHeight: units.gu(3)
128129 expandedPanelHeight: units.gu(7)
129130 openedHeight: root.height - indicatorOrangeLine.height
@@ -148,6 +149,20 @@ Item {
148149 }
149150 }
150151
152+ WindowControlButtons {
153+ id: windowControlButtons
154+ anchors {
155+ left: parent.left
156+ top: parent.top
157+ margins: units.gu(0.7)
158+ }
159+ height: indicators.minimizedPanelHeight - anchors.margins * 2
160+ visible: PanelState.buttonsVisible
161+ onClose: PanelState.close()
162+ onMinimize: PanelState.minimize()
163+ onMaximize: PanelState.maximize()
164+ }
165+
151166 PanelSeparatorLine {
152167 id: indicatorOrangeLine
153168 anchors {
@@ -161,7 +176,7 @@ Item {
161176 id: __callHint
162177 anchors {
163178 top: parent.top
164− left: parent.left
179+ left: PanelState.buttonsVisible ? windowControlButtons.right : parent.left
165180 }
166181 height: indicators.minimizedPanelHeight
167182 visible: active && indicators.state == "initial"
qml/Stages/DesktopStage.qml+20
@@ -19,6 +19,7 @@
1919import QtQuick 2.3
2020import Ubuntu.Components 1.1
2121import Unity.Application 0.1
22+import "../Components/PanelState"
2223
2324Item {
2425 id: root
@@ -54,6 +55,10 @@ Item {
5455
5556 QtObject {
5657 id: priv
58+
59+ readonly property string focusedAppId: ApplicationManager.focusedApplicationId
60+ readonly property var focusedAppDelegate: focusedAppId ? appRepeater.itemAt(indexOf(focusedAppId)) : null
61+
5762 function indexOf(appId) {
5863 for (var i = 0; i < ApplicationManager.count; i++) {
5964 if (ApplicationManager.get(i).appId == appId) {
@@ -64,6 +69,21 @@ Item {
6469 }
6570 }
6671
72+ Connections {
73+ target: PanelState
74+ onClose: {
75+ ApplicationManager.stopApplication(ApplicationManager.focusedApplicationId)
76+ }
77+ onMinimize: appRepeater.itemAt(0).state = "minimized"
78+ onMaximize: appRepeater.itemAt(0).state = "normal"
79+ }
80+
81+ Binding {
82+ target: PanelState
83+ property: "buttonsVisible"
84+ value: priv.focusedAppDelegate !== null && priv.focusedAppDelegate.state === "maximized"
85+ }
86+
6787 Repeater {
6888 id: appRepeater
6989 model: ApplicationManager
qml/Stages/WindowDecoration.qml+8−30
@@ -18,6 +18,7 @@
1818
1919import QtQuick 2.3
2020import Ubuntu.Components 1.1
21+import "../Components"
2122
2223Item {
2324 id: root
@@ -42,37 +43,14 @@ Item {
4243
4344 Row {
4445 anchors { left: parent.left; top: parent.top; bottom: parent.bottom; margins: units.gu(0.7) }
45− spacing: units.gu(0.5)
46+ spacing: units.gu(1)
4647 opacity: root.active ? 1 : 0.5
47− Rectangle {
48− height: parent.height; width: height; radius: height / 2
49− gradient: Gradient {
50− GradientStop { color: "#F49073"; position: 0 }
51− GradientStop { color: "#DF4F1C"; position: 1 }
52− }
53− border.width: units.dp(.5)
54− border.color: "black"
55− MouseArea { anchors.fill: parent; onClicked: root.close() }
56− }
57− Rectangle {
58− height: parent.height; width: height; radius: height / 2
59− gradient: Gradient {
60− GradientStop { color: "#92918C"; position: 0 }
61− GradientStop { color: "#5E5D58"; position: 1 }
62− }
63− border.width: units.dp(.5)
64− border.color: "black"
65− MouseArea { anchors.fill: parent; onClicked: root.minimize() }
66− }
67− Rectangle {
68− height: parent.height; width: height; radius: height / 2
69− gradient: Gradient {
70− GradientStop { color: "#92918C"; position: 0 }
71− GradientStop { color: "#5E5D58"; position: 1 }
72− }
73− border.width: units.dp(.5)
74− border.color: "black"
75− MouseArea { anchors.fill: parent; onClicked: root.maximize() }
48+
49+ WindowControlButtons {
50+ height: parent.height
51+ onClose: root.close();
52+ onMinimize: root.minimize();
53+ onMaximize: root.maximize();
7654 }
7755
7856 Label {