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

To avoid blurry renderings

commit60472f0e7bcd7e2dec3b24b48f23bfe7e56458ab authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateThu 19 May 2016, 16:48 (10 years ago) parent81b01b1
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
@@ -56,6 +56,9 @@ private:
5656 QPointer<QWindow> m_registeredWindow;
5757 QString m_cursorName;
5858 QString m_themeName;
59+
60+ // Accumulated, unapplied, mouse movement.
61+ QPointF m_accumulatedMovement;
5962};
6063
6164#endif // MOUSEPOINTER_H
qml/Stages/WindowDecoration.qml+5−2
@@ -58,8 +58,11 @@ MouseArea {
5858 if (priv.dragging) {
5959 Mir.cursorName = "grabbing";
6060 var pos = mapToItem(root.target.parent, mouseX, mouseY);
61− root.target.x = pos.x - priv.distanceX;
62− root.target.y = Math.max(pos.y - priv.distanceY, PanelState.panelHeight);
61+ // Use integer coordinate values to ensure that target is left in a pixel-aligned
62+ // position. Mouse movement could have subpixel precision, yielding a fractional
63+ // mouse position.
64+ root.target.x = Math.round(pos.x - priv.distanceX);
65+ root.target.y = Math.round(Math.max(pos.y - priv.distanceY, PanelState.panelHeight));
6366 }
6467 }
6568