on xenial help sign in
hide the mouse pointer on touch, reveal it again on mouse move
commite28150aeed8395fe49bc47af7fcc29e872c6fdfd authorLukáš Tinkl <lukas.tinkl@canonical.com> dateTue 1 Dec 2015, 22:40 (11 years ago) parent106f357
6 files changed+48−5
plugins/Cursor/MousePointer.cpp+4 plugins/Cursor/MousePointer.h+1 plugins/Utils/HomeKeyWatcher.cpp+7 plugins/Utils/HomeKeyWatcher.h+3 qml/Shell.qml+30 qml/Stages/WindowResizeArea.qml+3−5
plugins/Cursor/MousePointer.cpp+4
@@ -42,6 +42,10 @@ void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::Mouse
4242 return;
4343 }
4444
45+ if (!movement.isNull()) {
46+ Q_EMIT mouseMoved();
47+ }
48+
4549 qreal newX = x() + movement.x();
4650 if (newX < 0) {
4751 Q_EMIT pushedLeftBoundary(qAbs(newX), buttons);
plugins/Cursor/MousePointer.h+1
@@ -48,6 +48,7 @@ public Q_SLOTS:
4848Q_SIGNALS:
4949 void pushedLeftBoundary(qreal amount, Qt::MouseButtons buttons);
5050 void pushedRightBoundary(qreal amount, Qt::MouseButtons buttons);
51+ void mouseMoved();
5152
5253protected:
5354 void itemChange(ItemChange change, const ItemChangeData &value) override;
plugins/Utils/HomeKeyWatcher.cpp+7
@@ -86,11 +86,18 @@ void HomeKeyWatcher::update(QEvent *event)
8686
8787 m_activationTimer->stop();
8888 m_windowBeingTouched = true;
89+ Q_EMIT windowTouched();
8990
9091 } else if (event->type() == QEvent::TouchEnd) {
9192
9293 m_windowBeingTouched = false;
9394 m_windowLastTouchedTimer->start();
95+
96+ QTouchEvent * touchEv = static_cast<QTouchEvent *>(event);
97+ if (touchEv && !touchEv->touchPoints().isEmpty()) {
98+ const QPointF pos = touchEv->touchPoints().last().screenPos();
99+ Q_EMIT windowReleased(pos);
100+ }
94101 }
95102}
96103
plugins/Utils/HomeKeyWatcher.h+3
@@ -59,6 +59,9 @@ Q_SIGNALS:
5959 // Emitted when the home key has been intentionally tapped
6060 void activated();
6161
62+ void windowTouched();
63+ void windowReleased(const QPointF &pos);
64+
6265private Q_SLOTS:
6366 void setupFilterOnWindow(QQuickWindow *window);
6467 void emitActivatedIfNoTouchesAround();
qml/Shell.qml+30
@@ -132,6 +132,24 @@ Item {
132132 shell.activateApplication(app);
133133 }
134134
135+ QtObject {
136+ id: cursorPriv
137+ property bool touchDetected: false;
138+
139+ function hideCursor() {
140+ touchDetected = true;
141+ shell.cursorVisible = false;
142+ }
143+
144+ function revealCursor() {
145+ if (touchDetected) {
146+ touchDetected = false;
147+ Mir.cursorName = "";
148+ shell.cursorVisible = true;
149+ }
150+ }
151+ }
152+
135153 Binding {
136154 target: LauncherModel
137155 property: "applicationManager"
@@ -147,6 +165,7 @@ Item {
147165 }
148166
149167 LightDM{id: lightDM} // Provide backend access
168+
150169 VolumeControl {
151170 id: volumeControl
152171 indicators: panel.indicators
@@ -178,6 +197,12 @@ Item {
178197
179198 HomeKeyWatcher {
180199 onActivated: { launcher.fadeOut(); shell.showHome(); }
200+ onWindowTouched: { cursorPriv.hideCursor(); }
201+ onWindowReleased: {
202+ // store the last known touch position
203+ cursor.x = pos.x;
204+ cursor.y = pos.y;
205+ }
181206 }
182207
183208 Item {
@@ -663,6 +688,7 @@ Item {
663688 id: cursor
664689 visible: shell.hasMouse
665690 z: screenGrabber.z + 1
691+ opacity: shell.cursorVisible ? 1 : 0
666692
667693 onPushedLeftBoundary: {
668694 if (buttons === Qt.NoButton) {
@@ -676,6 +702,10 @@ Item {
676702 applicationsDisplayLoader.item.pushRightEdge(amount);
677703 }
678704 }
705+
706+ onMouseMoved: {
707+ cursorPriv.revealCursor();
708+ }
679709 }
680710
681711 Rectangle {
qml/Stages/WindowResizeArea.qml+3−5
@@ -118,8 +118,8 @@ MouseArea {
118118 property real currentWidth
119119 property real currentHeight
120120
121− property string cursorName: {
122− if (root.containsMouse || root.pressed) {
121+ readonly property string cursorName: {
122+ if (root.containsMouse || dragging) {
123123 if (leftBorder && !topBorder && !bottomBorder) {
124124 return "left_side";
125125 } else if (rightBorder && !topBorder && !bottomBorder) {
@@ -186,9 +186,7 @@ MouseArea {
186186 } else {
187187 resetBordersToMoveTimer.start();
188188 d.dragging = false;
189− if (containsMouse) {
190− d.updateBorders();
191− }
189+ d.updateBorders();
192190 }
193191 }
194192