on xenial help sign in
extend MousePointer with top boundary and corners
a404f6cLukáš Tinkl
plugins/Cursor/CMakeLists.txt+2−2
@@ -28,6 +28,6 @@ target_link_libraries(Cursor-qml
28 ${QT5PLATFORM_SUPPORT_LDFLAGS}
28 ${QT5PLATFORM_SUPPORT_LDFLAGS}
29)
29)
30
30
31−qt5_use_modules(Cursor-qml Qml Quick DBus Network Gui Sql Concurrent Svg)
31+qt5_use_modules(Cursor-qml Qml Quick Svg)
32
32
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
21MousePointer {
21MousePointer {
22 id: mousePointer
22 id: mousePointer
23
23
24+ property int panelHeight // to be read from MousePointer C++ class
25+
24 CursorImageInfo {
26 CursorImageInfo {
25 id: imageInfo
27 id: imageInfo
26 themeName: mousePointer.themeName
28 themeName: mousePointer.themeName
plugins/Cursor/MousePointer.cpp+32−14
@@ -22,6 +22,8 @@
22
22
23#include <QQuickWindow>
23#include <QQuickWindow>
24#include <QGuiApplication>
24#include <QGuiApplication>
25+#include <QQmlProperty>
26+#include <QtMath>
25
27
26#include <qpa/qwindowsysteminterface.h>
28#include <qpa/qwindowsysteminterface.h>
27
29
@@ -48,23 +50,33 @@ void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::Mouse
48 QPointF appliedMovement(int(m_accumulatedMovement.x()), int(m_accumulatedMovement.y()));
50 QPointF appliedMovement(int(m_accumulatedMovement.x()), int(m_accumulatedMovement.y()));
49 m_accumulatedMovement -= appliedMovement;
51 m_accumulatedMovement -= appliedMovement;
50
52
51− qreal newX = x() + appliedMovement.x();
53+ const qreal newX = x() + appliedMovement.x();
52− if (newX < 0) {
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
53 Q_EMIT pushedLeftBoundary(qAbs(newX), buttons);
71 Q_EMIT pushedLeftBoundary(qAbs(newX), buttons);
54− newX = 0;
72+ } else if (newX >= sceneWidth) { // right edge
55− } else if (newX >= parentItem()->width()) {
56− Q_EMIT pushedRightBoundary(newX - (parentItem()->width() - 1), buttons);
73+ Q_EMIT pushedRightBoundary(newX - (sceneWidth - 1), buttons);
57− newX = parentItem()->width() - 1;
74+ } else if (newY < m_panelHeight) { // top edge
75+ Q_EMIT pushedTopBoundary(qAbs(newY), buttons);
58 }
76 }
59− setX(newX);
60
77
61− qreal newY = y() + appliedMovement.y();
78+ setX(qBound(0.0, newX, sceneWidth - 1));
62− if (newY < 0) {
63− newY = 0;
64− } else if (newY >= parentItem()->height()) {
65− newY = parentItem()->height() - 1;
66− }
67− setY(newY);
79+ setY(qBound(0.0, newY, sceneHeight - 1));
68
80
69 QPointF scenePosition = mapToItem(nullptr, QPointF(0, 0));
81 QPointF scenePosition = mapToItem(nullptr, QPointF(0, 0));
70 QWindowSystemInterface::handleMouseEvent(window(), timestamp, scenePosition /*local*/, scenePosition /*global*/,
82 QWindowSystemInterface::handleMouseEvent(window(), timestamp, scenePosition /*local*/, scenePosition /*global*/,
@@ -89,6 +101,12 @@ void MousePointer::itemChange(ItemChange change, const ItemChangeData &value)
89 }
101 }
90}
102}
91
103
104+void MousePointer::componentComplete()
105+{
106+ MirMousePointerInterface::componentComplete();
107+ m_panelHeight = QQmlProperty::read(this, "panelHeight").toInt();
108+}
109+
92void MousePointer::registerWindow(QWindow *window)
110void MousePointer::registerWindow(QWindow *window)
93{
111{
94 if (window == m_registeredWindow) {
112 if (window == m_registeredWindow) {
plugins/Cursor/MousePointer.h+8
@@ -46,10 +46,16 @@ public Q_SLOTS:
46Q_SIGNALS:
46Q_SIGNALS:
47 void pushedLeftBoundary(qreal amount, Qt::MouseButtons buttons);
47 void pushedLeftBoundary(qreal amount, Qt::MouseButtons buttons);
48 void pushedRightBoundary(qreal amount, Qt::MouseButtons buttons);
48 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);
49 void mouseMoved();
54 void mouseMoved();
50
55
51protected:
56protected:
52 void itemChange(ItemChange change, const ItemChangeData &value) override;
57 void itemChange(ItemChange change, const ItemChangeData &value) override;
58+ void componentComplete() override;
53
59
54private Q_SLOTS:
60private Q_SLOTS:
55 void registerScreen(QScreen *screen);
61 void registerScreen(QScreen *screen);
@@ -64,6 +70,8 @@ private:
64
70
65 // Accumulated, unapplied, mouse movement.
71 // Accumulated, unapplied, mouse movement.
66 QPointF m_accumulatedMovement;
72 QPointF m_accumulatedMovement;
73+
74+ int m_panelHeight = 0;
67};
75};
68
76
69#endif // MOUSEPOINTER_H
77#endif // MOUSEPOINTER_H
qml/OrientedShell.qml+1−1
@@ -260,7 +260,7 @@ Item {
260 nativeWidth: root.width
260 nativeWidth: root.width
261 nativeHeight: root.height
261 nativeHeight: root.height
262 mode: applicationArguments.mode
262 mode: applicationArguments.mode
263− hasMouse: miceModel.count + touchPadModel.count > 0
263+ hasMouse: pointerInputDevices > 0
264 // TODO: Factor in if the current screen is a touch screen and if the user wants to
264 // TODO: Factor in if the current screen is a touch screen and if the user wants to
265 // have multiple keyboards around. For now we only enable one keyboard at a time
265 // have multiple keyboards around. For now we only enable one keyboard at a time
266 // thus hiding it here if there is a physical one around or if we have a second
266 // 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 {
764 id: cursor
764 id: cursor
765 visible: shell.hasMouse
765 visible: shell.hasMouse
766 z: itemGrabber.z + 1
766 z: itemGrabber.z + 1
767+ panelHeight: panel.panelHeight
767
768
768 property bool mouseNeverMoved: true
769 property bool mouseNeverMoved: true
769 Binding {
770 Binding {
@@ -778,18 +779,36 @@ StyledItem {
778 height: units.gu(3)
779 height: units.gu(3)
779
780
780 onPushedLeftBoundary: {
781 onPushedLeftBoundary: {
782+ print("!!! Left edge:", amount, buttons)
781 if (buttons === Qt.NoButton) {
783 if (buttons === Qt.NoButton) {
782 launcher.pushEdge(amount);
784 launcher.pushEdge(amount);
783 }
785 }
784 }
786 }
785
787
786 onPushedRightBoundary: {
788 onPushedRightBoundary: {
789+ print("!!! Right edge:", amount, buttons)
787 if (buttons === Qt.NoButton && applicationsDisplayLoader.item
790 if (buttons === Qt.NoButton && applicationsDisplayLoader.item
788 && applicationsDisplayLoader.item.pushRightEdge) {
791 && applicationsDisplayLoader.item.pushRightEdge) {
789 applicationsDisplayLoader.item.pushRightEdge(amount);
792 applicationsDisplayLoader.item.pushRightEdge(amount);
790 }
793 }
791 }
794 }
792
795
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+
793 onMouseMoved: {
812 onMouseMoved: {
794 mouseNeverMoved = false;
813 mouseNeverMoved = false;
795 cursor.opacity = 1;
814 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 @@
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
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -17,7 +17,14 @@
17import QtQuick 2.4
17import QtQuick 2.4
18
18
19Item {
19Item {
20+ property int panelHeight // to be read from MousePointer C++ class
21+
20 signal pushedLeftBoundary(real amount, int buttons)
22 signal pushedLeftBoundary(real amount, int buttons)
21 signal pushedRightBoundary(real amount, int buttons)
23 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)
22 signal mouseMoved()
29 signal mouseMoved()
23}
30}