on xenial help sign in
Do not let mouse and wheel events pass thru the titlebar (LP: #1588424)
d811835Lukáš Tinkl
qml/Stages/WindowDecoration.qml+10−4
@@ -27,17 +27,20 @@ MouseArea {
27 property Item target
27 property Item target
28 property alias title: titleLabel.text
28 property alias title: titleLabel.text
29 property bool active: false
29 property bool active: false
30+ acceptedButtons: Qt.AllButtons // prevent leaking unhandled mouse events
30 property alias overlayShown: buttons.overlayShown
31 property alias overlayShown: buttons.overlayShown
31
32
32− hoverEnabled: true
33−
34 signal closeClicked()
33 signal closeClicked()
35 signal minimizeClicked()
34 signal minimizeClicked()
36 signal maximizeClicked()
35 signal maximizeClicked()
37 signal maximizeHorizontallyClicked()
36 signal maximizeHorizontallyClicked()
38 signal maximizeVerticallyClicked()
37 signal maximizeVerticallyClicked()
39
38
39+ onDoubleClicked: {
40+ if (mouse.button == Qt.LeftButton) {
40− onDoubleClicked: root.maximizeClicked()
41+ root.maximizeClicked();
42+ }
43+ }
41
44
42 QtObject {
45 QtObject {
43 id: priv
46 id: priv
@@ -47,7 +50,7 @@ MouseArea {
47 }
50 }
48
51
49 onPressedChanged: {
52 onPressedChanged: {
50− if (pressed) {
53+ if (pressed && pressedButtons == Qt.LeftButton) {
51 var pos = mapToItem(root.target, mouseX, mouseY);
54 var pos = mapToItem(root.target, mouseX, mouseY);
52 priv.distanceX = pos.x;
55 priv.distanceX = pos.x;
53 priv.distanceY = pos.y;
56 priv.distanceY = pos.y;
@@ -70,6 +73,9 @@ MouseArea {
70 }
73 }
71 }
74 }
72
75
76+ // do not let unhandled wheel event pass thru the decoration
77+ onWheel: wheel.accepted = true;
78+
73 Rectangle {
79 Rectangle {
74 anchors.fill: parent
80 anchors.fill: parent
75 anchors.bottomMargin: -radius
81 anchors.bottomMargin: -radius
tests/qmltests/Stages/tst_DesktopStage.qml+51
@@ -691,6 +691,28 @@ Item {
691 tryCompare(closeButton, "visible", false);
691 tryCompare(closeButton, "visible", false);
692 }
692 }
693
693
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+
694 function test_preventMouseEventsThruDesktopSpread() {
716 function test_preventMouseEventsThruDesktopSpread() {
695 var spread = findChild(desktopStage, "spread");
717 var spread = findChild(desktopStage, "spread");
696 verify(spread);
718 verify(spread);
@@ -708,5 +730,34 @@ Item {
708
730
709 spread.cancel();
731 spread.cancel();
710 }
732 }
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+ }
711 }
762 }
712}
763}