on xenial help sign in
Ensure mouse and window movement are pixel-aligned

To avoid blurry renderings (LP: #1510382) (LP: #1510382)

commitd3db405986e1e8e14bf2dab99bd7255b7eb278aa authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateFri 17 Jun 2016, 01:13 (10 years ago) parent81bd79a60472f0
3 files changed+17−6
plugins/Cursor/MousePointer.cpp+8−3 plugins/Cursor/MousePointer.h+4−1 qml/Stages/WindowDecoration.qml+5−2
plugins/Cursor/MousePointer.cpp+8−3
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
33 *
44 * This program is free software: you can redistribute it and/or modify it under
55 * 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
4343 Q_EMIT mouseMoved();
4444 }
4545
46− qreal newX = x() + movement.x();
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+
51+ qreal newX = x() + appliedMovement.x();
4752 if (newX < 0) {
4853 Q_EMIT pushedLeftBoundary(qAbs(newX), buttons);
4954 newX = 0;
@@ -53,7 +58,7 @@ void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::Mouse
5358 }
5459 setX(newX);
5560
56− qreal newY = y() + movement.y();
61+ qreal newY = y() + appliedMovement.y();
5762 if (newY < 0) {
5863 newY = 0;
5964 } else if (newY > parentItem()->height()) {
plugins/Cursor/MousePointer.h+4−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
33 *
44 * This program is free software: you can redistribute it and/or modify it under
55 * the terms of the GNU Lesser General Public License version 3, as published by
@@ -61,6 +61,9 @@ private:
6161 QPointer<QScreen> m_registeredScreen;
6262 QString m_cursorName;
6363 QString m_themeName;
64+
65+ // Accumulated, unapplied, mouse movement.
66+ QPointF m_accumulatedMovement;
6467};
6568
6669#endif // MOUSEPOINTER_H
qml/Stages/WindowDecoration.qml+5−2
@@ -60,8 +60,11 @@ MouseArea {
6060 if (priv.dragging) {
6161 Mir.cursorName = "grabbing";
6262 var pos = mapToItem(root.target.parent, mouseX, mouseY);
63− root.target.x = pos.x - priv.distanceX;
64− root.target.y = Math.max(pos.y - priv.distanceY, PanelState.panelHeight);
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.
66+ root.target.x = Math.round(pos.x - priv.distanceX);
67+ root.target.y = Math.round(Math.max(pos.y - priv.distanceY, PanelState.panelHeight));
6568 }
6669 }
6770