on xenial help sign in
Do not let mouse and wheel events pass thru the titlebar (LP: #1588424)
commitd8118354f3bf3d57d670d3db70ed0a34d5b35c32 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateMon 27 Jun 2016, 18:43 (10 years ago) parent2bf24dbeba93a7
2 files changed+61−4
qml/Stages/WindowDecoration.qml+10−4 tests/qmltests/Stages/tst_DesktopStage.qml+51
qml/Stages/WindowDecoration.qml+10−4
@@ -27,17 +27,20 @@ MouseArea {
2727 property Item target
2828 property alias title: titleLabel.text
2929 property bool active: false
30+ acceptedButtons: Qt.AllButtons // prevent leaking unhandled mouse events
3031 property alias overlayShown: buttons.overlayShown
3132
32− hoverEnabled: true
33−
3433 signal closeClicked()
3534 signal minimizeClicked()
3635 signal maximizeClicked()
3736 signal maximizeHorizontallyClicked()
3837 signal maximizeVerticallyClicked()
3938
40− onDoubleClicked: root.maximizeClicked()
39+ onDoubleClicked: {
40+ if (mouse.button == Qt.LeftButton) {
41+ root.maximizeClicked();
42+ }
43+ }
4144
4245 QtObject {
4346 id: priv
@@ -47,7 +50,7 @@ MouseArea {
4750 }
4851
4952 onPressedChanged: {
50− if (pressed) {
53+ if (pressed && pressedButtons == Qt.LeftButton) {
5154 var pos = mapToItem(root.target, mouseX, mouseY);
5255 priv.distanceX = pos.x;
5356 priv.distanceY = pos.y;
@@ -70,6 +73,9 @@ MouseArea {
7073 }
7174 }
7275
76+ // do not let unhandled wheel event pass thru the decoration
77+ onWheel: wheel.accepted = true;
78+
7379 Rectangle {
7480 anchors.fill: parent
7581 anchors.bottomMargin: -radius
tests/qmltests/Stages/tst_DesktopStage.qml+51
@@ -691,6 +691,28 @@ Item {
691691 tryCompare(closeButton, "visible", false);
692692 }
693693
694+ function test_canMoveWindowWithLeftMouseButtonOnly_data() {
695+ return [
696+ {tag: "left mouse button", button: Qt.LeftButton },
697+ {tag: "right mouse button", button: Qt.RightButton },
698+ {tag: "middle mouse button", button: Qt.MiddleButton }
699+ ]
700+ }
701+
702+ function test_canMoveWindowWithLeftMouseButtonOnly(data) {
703+ var appDelegate = startApplication("dialer-app");
704+ verify(appDelegate);
705+
706+ var posBefore = Qt.point(appDelegate.x, appDelegate.y);
707+
708+ mousePress(appDelegate, appDelegate.width / 2, units.gu(1), data.button);
709+ mouseMove(appDelegate, appDelegate.width / 2, -units.gu(100), undefined /* delay */, data.button);
710+
711+ var posAfter = Qt.point(appDelegate.x, appDelegate.y);
712+
713+ tryCompareFunction(function(){return posBefore == posAfter;}, data.button !== Qt.LeftButton ? true : false);
714+ }
715+
694716 function test_preventMouseEventsThruDesktopSpread() {
695717 var spread = findChild(desktopStage, "spread");
696718 verify(spread);
@@ -708,5 +730,34 @@ Item {
708730
709731 spread.cancel();
710732 }
733+
734+ function test_eatWindowDecorationMouseEvents_data() {
735+ return [
736+ {tag: "left mouse click", signalName: "clicked", button: Qt.LeftButton },
737+ {tag: "right mouse click", signalName: "clicked", button: Qt.RightButton },
738+ {tag: "middle mouse click", signalName: "clicked", button: Qt.MiddleButton },
739+ {tag: "mouse wheel", signalName: "wheel", button: Qt.MiddleButton },
740+ {tag: "double click (RMB)", signalName: "doubleClicked", button: Qt.RightButton },
741+ ]
742+ }
743+
744+ function test_eatWindowDecorationMouseEvents(data) {
745+ var dialerAppDelegate = startApplication("dialer-app");
746+ verify(dialerAppDelegate);
747+ var decoration = findChild(dialerAppDelegate, "appWindowDecoration");
748+ verify(decoration);
749+
750+ mouseEaterSpy.signalName = data.signalName;
751+ if (data.signalName === "wheel") {
752+ mouseWheel(decoration, decoration.width/2, decoration.height/2, 20, 20);
753+ } else if (data.signalName === "clicked") {
754+ mouseClick(decoration, decoration.width/2, decoration.height/2, data.button);
755+ } else {
756+ mouseDoubleClick(decoration, decoration.width/2, decoration.height/2, data.button);
757+ tryCompare(dialerAppDelegate, "maximized", false);
758+ }
759+
760+ tryCompare(mouseEaterSpy, "count", 0);
761+ }
711762 }
712763}