on xenial help sign in
extend MousePointer with top boundary and corners
commita404f6c3aa67ab231b5fdedc3dc3a16c4db5c6ba authorLukáš Tinkl <lukas.tinkl@canonical.com> dateThu 25 Aug 2016, 02:34 (10 years ago) parent644484f
8 files changed+73−19
plugins/Cursor/CMakeLists.txt+2−2 plugins/Cursor/Cursor.qml+2 plugins/Cursor/MousePointer.cpp+32−14 plugins/Cursor/MousePointer.h+8 qml/OrientedShell.qml+1−1 qml/Shell.qml+19 tests/mocks/Cursor/CMakeLists.txt+1−1 tests/mocks/Cursor/Cursor.qml+8−1
plugins/Cursor/CMakeLists.txt+2−2
@@ -28,6 +28,6 @@ target_link_libraries(Cursor-qml
2828 ${QT5PLATFORM_SUPPORT_LDFLAGS}
2929)
3030
31−qt5_use_modules(Cursor-qml Qml Quick DBus Network Gui Sql Concurrent Svg)
31+qt5_use_modules(Cursor-qml Qml Quick Svg)
3232
33−add_unity8_plugin(Cursor 1.0 Cursor TARGETS Cursor-qml)
33+add_unity8_plugin(Cursor 1.1 Cursor TARGETS Cursor-qml)
plugins/Cursor/Cursor.qml+2
@@ -21,6 +21,8 @@ import Powerd 0.1
2121MousePointer {
2222 id: mousePointer
2323
24+ property int panelHeight // to be read from MousePointer C++ class
25+
2426 CursorImageInfo {
2527 id: imageInfo
2628 themeName: mousePointer.themeName
plugins/Cursor/MousePointer.cpp+32−14
@@ -22,6 +22,8 @@
2222
2323#include <QQuickWindow>
2424#include <QGuiApplication>
25+#include <QQmlProperty>
26+#include <QtMath>
2527
2628#include <qpa/qwindowsysteminterface.h>
2729
@@ -48,23 +50,33 @@ void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::Mouse
4850 QPointF appliedMovement(int(m_accumulatedMovement.x()), int(m_accumulatedMovement.y()));
4951 m_accumulatedMovement -= appliedMovement;
5052
51− qreal newX = x() + appliedMovement.x();
52− if (newX < 0) {
53+ const qreal newX = x() + appliedMovement.x();
54+ const qreal newY = y() + appliedMovement.y();
55+ const qreal sceneWidth = parentItem()->width();
56+ const qreal sceneHeight = parentItem()->height();
57+
58+ if (newX < 0 && newY < m_panelHeight) { // top left corner
59+ const auto distance = qSqrt(qPow(newX, 2) + qPow(newY-m_panelHeight, 2));
60+ Q_EMIT pushedTopLeftCorner(qAbs(distance), buttons);
61+ } else if (newX >= sceneWidth && newY < m_panelHeight) { // top right corner
62+ const auto distance = qSqrt(qPow(newX-sceneWidth, 2) + qPow(newY-m_panelHeight, 2));
63+ Q_EMIT pushedTopRightCorner(qAbs(distance), buttons);
64+ } else if (newX < 0 && newY >= sceneHeight) { // bottom left corner
65+ const auto distance = qSqrt(qPow(newX, 2) + qPow(newY-sceneHeight, 2));
66+ Q_EMIT pushedBottomLeftCorner(qAbs(distance), buttons);
67+ } else if (newX >= sceneWidth && newY >= sceneHeight) { // bottom right corner
68+ const auto distance = qSqrt(qPow(newX-sceneWidth, 2) + qPow(newY-sceneHeight, 2));
69+ Q_EMIT pushedBottomRightCorner(qAbs(distance), buttons);
70+ } else if (newX < 0) { // left edge
5371 Q_EMIT pushedLeftBoundary(qAbs(newX), buttons);
54− newX = 0;
55− } else if (newX >= parentItem()->width()) {
56− Q_EMIT pushedRightBoundary(newX - (parentItem()->width() - 1), buttons);
57− newX = parentItem()->width() - 1;
72+ } else if (newX >= sceneWidth) { // right edge
73+ Q_EMIT pushedRightBoundary(newX - (sceneWidth - 1), buttons);
74+ } else if (newY < m_panelHeight) { // top edge
75+ Q_EMIT pushedTopBoundary(qAbs(newY), buttons);
5876 }
59− setX(newX);
6077
61− qreal newY = y() + appliedMovement.y();
62− if (newY < 0) {
63− newY = 0;
64− } else if (newY >= parentItem()->height()) {
65− newY = parentItem()->height() - 1;
66− }
67− setY(newY);
78+ setX(qBound(0.0, newX, sceneWidth - 1));
79+ setY(qBound(0.0, newY, sceneHeight - 1));
6880
6981 QPointF scenePosition = mapToItem(nullptr, QPointF(0, 0));
7082 QWindowSystemInterface::handleMouseEvent(window(), timestamp, scenePosition /*local*/, scenePosition /*global*/,
@@ -89,6 +101,12 @@ void MousePointer::itemChange(ItemChange change, const ItemChangeData &value)
89101 }
90102}
91103
104+void MousePointer::componentComplete()
105+{
106+ MirMousePointerInterface::componentComplete();
107+ m_panelHeight = QQmlProperty::read(this, "panelHeight").toInt();
108+}
109+
92110void MousePointer::registerWindow(QWindow *window)
93111{
94112 if (window == m_registeredWindow) {
plugins/Cursor/MousePointer.h+8
@@ -46,10 +46,16 @@ public Q_SLOTS:
4646Q_SIGNALS:
4747 void pushedLeftBoundary(qreal amount, Qt::MouseButtons buttons);
4848 void pushedRightBoundary(qreal amount, Qt::MouseButtons buttons);
49+ void pushedTopBoundary(qreal amount, Qt::MouseButtons buttons);
50+ void pushedTopLeftCorner(qreal amount, Qt::MouseButtons buttons);
51+ void pushedTopRightCorner(qreal amount, Qt::MouseButtons buttons);
52+ void pushedBottomLeftCorner(qreal amount, Qt::MouseButtons buttons);
53+ void pushedBottomRightCorner(qreal amount, Qt::MouseButtons buttons);
4954 void mouseMoved();
5055
5156protected:
5257 void itemChange(ItemChange change, const ItemChangeData &value) override;
58+ void componentComplete() override;
5359
5460private Q_SLOTS:
5561 void registerScreen(QScreen *screen);
@@ -64,6 +70,8 @@ private:
6470
6571 // Accumulated, unapplied, mouse movement.
6672 QPointF m_accumulatedMovement;
73+
74+ int m_panelHeight = 0;
6775};
6876
6977#endif // MOUSEPOINTER_H
qml/OrientedShell.qml+1−1
@@ -260,7 +260,7 @@ Item {
260260 nativeWidth: root.width
261261 nativeHeight: root.height
262262 mode: applicationArguments.mode
263− hasMouse: miceModel.count + touchPadModel.count > 0
263+ hasMouse: pointerInputDevices > 0
264264 // TODO: Factor in if the current screen is a touch screen and if the user wants to
265265 // have multiple keyboards around. For now we only enable one keyboard at a time
266266 // thus hiding it here if there is a physical one around or if we have a second
qml/Shell.qml+19
@@ -764,6 +764,7 @@ StyledItem {
764764 id: cursor
765765 visible: shell.hasMouse
766766 z: itemGrabber.z + 1
767+ panelHeight: panel.panelHeight
767768
768769 property bool mouseNeverMoved: true
769770 Binding {
@@ -778,18 +779,36 @@ StyledItem {
778779 height: units.gu(3)
779780
780781 onPushedLeftBoundary: {
782+ print("!!! Left edge:", amount, buttons)
781783 if (buttons === Qt.NoButton) {
782784 launcher.pushEdge(amount);
783785 }
784786 }
785787
786788 onPushedRightBoundary: {
789+ print("!!! Right edge:", amount, buttons)
787790 if (buttons === Qt.NoButton && applicationsDisplayLoader.item
788791 && applicationsDisplayLoader.item.pushRightEdge) {
789792 applicationsDisplayLoader.item.pushRightEdge(amount);
790793 }
791794 }
792795
796+ onPushedTopBoundary: {
797+ print("!!! Top edge:", amount, buttons)
798+ }
799+ onPushedTopLeftCorner: {
800+ print("!!! Top left corner:", amount, buttons)
801+ }
802+ onPushedTopRightCorner: {
803+ print("!!! Top right corner:", amount, buttons)
804+ }
805+ onPushedBottomLeftCorner: {
806+ print("!!! Bottom left corner:", amount, buttons)
807+ }
808+ onPushedBottomRightCorner: {
809+ print("!!! Bottom right corner:", amount, buttons)
810+ }
811+
793812 onMouseMoved: {
794813 mouseNeverMoved = false;
795814 cursor.opacity = 1;
tests/mocks/Cursor/CMakeLists.txt+1−1
@@ -1 +1 @@
1−add_unity8_mock(Cursor 1.0 Cursor PREFIX mocks)
1+add_unity8_mock(Cursor 1.1 Cursor PREFIX mocks)
tests/mocks/Cursor/Cursor.qml+8−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
55 * it under the terms of the GNU General Public License as published by
@@ -17,7 +17,14 @@
1717import QtQuick 2.4
1818
1919Item {
20+ property int panelHeight // to be read from MousePointer C++ class
21+
2022 signal pushedLeftBoundary(real amount, int buttons)
2123 signal pushedRightBoundary(real amount, int buttons)
24+ signal pushedTopBoundary(real amount, int buttons)
25+ signal pushedTopLeftCorner(real amount, int buttons)
26+ signal pushedTopRightCorner(real amount, int buttons)
27+ signal pushedBottomLeftCorner(real amount, int buttons)
28+ signal pushedBottomRightCorner(real amount, int buttons)
2229 signal mouseMoved()
2330}