on xenial help sign in
Respect Fitt's law wrt the window control buttons in panel (LP: #1611959)

Approved by: Albert Astals Cid

commit3472f4dc94cd87e3b2ba5c14de0664a50ed62774 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateTue 13 Sep 2016, 06:51 (10 years ago) parentf7a99a5024ffd8
4 files changed+33−16
qml/Components/WindowControlButtons.qml+7−5 qml/Panel/Panel.qml+5−6 qml/Stages/WindowDecoration.qml+2−5 tests/qmltests/Panel/tst_Panel.qml+19
qml/Components/WindowControlButtons.qml+7−5
@@ -19,13 +19,12 @@ import Ubuntu.Components 1.3
1919
2020Row {
2121 id: root
22− spacing: overlayShown ? units.gu(2) : units.gu(1)
22+ spacing: overlayShown ? units.gu(2) : windowIsMaximized ? 0 : units.gu(1)
2323 Behavior on spacing {
2424 UbuntuNumberAnimation {}
2525 }
2626
2727 // to be set from outside
28− property Item target
2928 property bool active: false
3029 property bool windowIsMaximized: false
3130 property bool closeButtonShown: true
@@ -49,13 +48,14 @@ Row {
4948
5049 Rectangle {
5150 anchors.fill: parent
51+ anchors.margins: windowIsMaximized ? units.dp(3) : 0
5252 radius: height / 2
5353 color: theme.palette.normal.negative
5454 visible: parent.containsMouse && !overlayShown
5555 }
5656 Icon {
5757 anchors.fill: parent
58− anchors.margins: units.dp(3)
58+ anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
5959 source: "graphics/window-close.svg"
6060 color: root.active ? "white" : UbuntuColors.slate
6161 }
@@ -71,13 +71,14 @@ Row {
7171
7272 Rectangle {
7373 anchors.fill: parent
74+ anchors.margins: windowIsMaximized ? units.dp(3) : 0
7475 radius: height / 2
7576 color: root.active ? UbuntuColors.graphite : UbuntuColors.ash
7677 visible: parent.containsMouse && !overlayShown
7778 }
7879 Icon {
7980 anchors.fill: parent
80− anchors.margins: units.dp(3)
81+ anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
8182 source: "graphics/window-minimize.svg"
8283 color: root.active ? "white" : UbuntuColors.slate
8384 }
@@ -103,13 +104,14 @@ Row {
103104
104105 Rectangle {
105106 anchors.fill: parent
107+ anchors.margins: windowIsMaximized ? units.dp(3) : 0
106108 radius: height / 2
107109 color: root.active ? UbuntuColors.graphite : UbuntuColors.ash
108110 visible: parent.containsMouse && !overlayShown
109111 }
110112 Icon {
111113 anchors.fill: parent
112− anchors.margins: units.dp(3)
114+ anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
113115 source: root.windowIsMaximized ? "graphics/window-window.svg" : "graphics/window-maximize.svg"
114116 color: root.active ? "white" : UbuntuColors.slate
115117 }
qml/Panel/Panel.qml+5−6
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013-2015 Canonical, Ltd.
2+ * Copyright (C) 2013-2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -120,11 +120,8 @@ Item {
120120 anchors {
121121 left: parent.left
122122 top: parent.top
123− leftMargin: units.gu(1)
124− topMargin: units.gu(0.5)
125− bottomMargin: units.gu(0.5)
126123 }
127− height: indicators.minimizedPanelHeight - anchors.topMargin - anchors.bottomMargin
124+ height: indicators.minimizedPanelHeight
128125
129126 visible: ((PanelState.buttonsVisible && parent.containsMouse) || PanelState.buttonsAlwaysVisible)
130127 && !root.locked && !callHint.visible
@@ -183,13 +180,15 @@ Item {
183180 }
184181 color: "white"
185182 height: indicators.minimizedPanelHeight - anchors.topMargin - anchors.bottomMargin
186− visible: !windowControlButtons.visible && !root.locked && !callHint.visible
183+ opacity: !windowControlButtons.visible && !root.locked && !callHint.visible ? 1 : 0
184+ visible: opacity != 0
187185 verticalAlignment: Text.AlignVCenter
188186 fontSize: "medium"
189187 font.weight: PanelState.buttonsVisible ? Font.Light : Font.Medium
190188 text: PanelState.title
191189 elide: Text.ElideRight
192190 maximumLineCount: 1
191+ Behavior on opacity { UbuntuNumberAnimation {} }
193192 }
194193
195194 // TODO here would the Locally integrated menus come
qml/Stages/WindowDecoration.qml+2−5
@@ -108,7 +108,6 @@ MouseArea {
108108 onMaximizeHorizontallyClicked: root.maximizeHorizontallyClicked();
109109 onMaximizeVerticallyClicked: root.maximizeVerticallyClicked();
110110 closeButtonShown: root.target.application.appId !== "unity8-dash"
111− target: root.target
112111 }
113112
114113 Label {
@@ -122,10 +121,8 @@ MouseArea {
122121 font.weight: root.active ? Font.Light : Font.Medium
123122 elide: Text.ElideRight
124123 opacity: overlayShown ? 0 : 1
125− visible: opacity == 1
126− Behavior on opacity {
127− OpacityAnimator { duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing }
128− }
124+ visible: opacity != 0
125+ Behavior on opacity { UbuntuNumberAnimation {} }
129126 }
130127 }
131128}
tests/qmltests/Panel/tst_Panel.qml+19
@@ -182,6 +182,12 @@ IndicatorTest {
182182 signalName: "pressedChanged"
183183 }
184184
185+ SignalSpy {
186+ id: windowControlButtonsSpy
187+ target: PanelState
188+ signalName: "closeClicked"
189+ }
190+
185191 function init() {
186192 panel.fullscreenMode = false;
187193 callManager.foregroundCall = null;
@@ -197,6 +203,8 @@ IndicatorTest {
197203
198204 backgroundPressedSpy.clear();
199205 compare(backgroundPressedSpy.valid, true);
206+ windowControlButtonsSpy.clear();
207+ compare(windowControlButtonsSpy.valid, true);
200208 }
201209
202210 function get_indicator_item(index) {
@@ -494,5 +502,16 @@ IndicatorTest {
494502 compare(panel.indicators.shown, false);
495503 tryCompare(panel.indicators, "fullyClosed", true);
496504 }
505+
506+ // https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1611959
507+ function test_windowControlButtonsFittsLaw() {
508+ var buttonsVisible = PanelState.buttonsVisible;
509+ PanelState.buttonsVisible = true;
510+ // click in very topleft corner and verify the close button got clicked too
511+ mouseMove(panel, 0, 0);
512+ mouseClick(panel, 0, 0, undefined /*button*/, undefined /*modifiers*/, 100 /*short delay*/);
513+ compare(windowControlButtonsSpy.count, 1);
514+ PanelState.buttonsVisible = buttonsVisible;
515+ }
497516 }
498517}