on xenial help sign in
Ensure mouse and window movement are pixel-aligned
d3db405Daniel d'Andrada
plugins/Cursor/MousePointer.cpp+8−3
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software: you can redistribute it and/or modify it under
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
5 * the terms of the GNU Lesser General Public License version 3, as published by
@@ -43,7 +43,12 @@ void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::Mouse
43 Q_EMIT mouseMoved();
43 Q_EMIT mouseMoved();
44 }
44 }
45
45
46+ m_accumulatedMovement += movement;
47+ // don't apply the fractional part
48+ QPointF appliedMovement(int(m_accumulatedMovement.x()), int(m_accumulatedMovement.y()));
49+ m_accumulatedMovement -= appliedMovement;
50+
46− qreal newX = x() + movement.x();
51+ qreal newX = x() + appliedMovement.x();
47 if (newX < 0) {
52 if (newX < 0) {
48 Q_EMIT pushedLeftBoundary(qAbs(newX), buttons);
53 Q_EMIT pushedLeftBoundary(qAbs(newX), buttons);
49 newX = 0;
54 newX = 0;
@@ -53,7 +58,7 @@ void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::Mouse
53 }
58 }
54 setX(newX);
59 setX(newX);
55
60
56− qreal newY = y() + movement.y();
61+ qreal newY = y() + appliedMovement.y();
57 if (newY < 0) {
62 if (newY < 0) {
58 newY = 0;
63 newY = 0;
59 } else if (newY > parentItem()->height()) {
64 } else if (newY > parentItem()->height()) {
plugins/Cursor/MousePointer.h+4−1
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software: you can redistribute it and/or modify it under
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
5 * the terms of the GNU Lesser General Public License version 3, as published by
@@ -61,6 +61,9 @@ private:
61 QPointer<QScreen> m_registeredScreen;
61 QPointer<QScreen> m_registeredScreen;
62 QString m_cursorName;
62 QString m_cursorName;
63 QString m_themeName;
63 QString m_themeName;
64+
65+ // Accumulated, unapplied, mouse movement.
66+ QPointF m_accumulatedMovement;
64};
67};
65
68
66#endif // MOUSEPOINTER_H
69#endif // MOUSEPOINTER_H
qml/Stages/WindowDecoration.qml+5−2
@@ -60,8 +60,11 @@ MouseArea {
60 if (priv.dragging) {
60 if (priv.dragging) {
61 Mir.cursorName = "grabbing";
61 Mir.cursorName = "grabbing";
62 var pos = mapToItem(root.target.parent, mouseX, mouseY);
62 var pos = mapToItem(root.target.parent, mouseX, mouseY);
63+ // Use integer coordinate values to ensure that target is left in a pixel-aligned
64+ // position. Mouse movement could have subpixel precision, yielding a fractional
65+ // mouse position.
63− root.target.x = pos.x - priv.distanceX;
66+ root.target.x = Math.round(pos.x - priv.distanceX);
64− root.target.y = Math.max(pos.y - priv.distanceY, PanelState.panelHeight);
67+ root.target.y = Math.round(Math.max(pos.y - priv.distanceY, PanelState.panelHeight));
65 }
68 }
66 }
69 }
67
70