@@ -18,7 +18,6 @@ import QtQuick 2.4
1818import QtQuick.Layouts 1.1
1919import Ubuntu.Components 1.3
2020import UInput 0.1
21−import Cursor 1.0
2221
2322ColumnLayout {
2423 spacing: units.gu(2)
@@ -28,148 +27,108 @@ ColumnLayout {
2827 Component.onDestruction: removeMouse();
2928 }
3029
31− UbuntuShape {
32− Layout.fillWidth: true
33− Layout.fillHeight: true
34− backgroundColor: "black"
35− opacity: 0.4
36−
37− Image {
38− anchors.centerIn: parent
39− height: units.gu(2)
40− width: units.gu(2)
41− source: "image://cursor/default/left_ptr"
30+
31+ MultiPointTouchArea {
32+ objectName: "touchPadArea"
33+ anchors.fill: parent
34+
35+ property int clickThreshold: units.gu(1.5)
36+ property bool isClick: false
37+ property bool pressed: false
38+
39+ onPressed: {
40+ print("pressed", point1.pressed, point2.pressed)
41+ // If double-tapping *really* fast, it could happen that we end up having only point2 pressed
42+ // Make sure we check for both combos, only point1 or only point2
43+ if (((point1.pressed && !point2.pressed) || (!point1.pressed && point2.pressed))
44+ && clickTimer.running) {
45+ clickTimer.stop();
46+ uinput.pressMouse(UInput.ButtonLeft)
47+ pressed = true;
48+ }
49+ isClick = true;
4250 }
4351
44− MultiPointTouchArea {
45− objectName: "touchPadArea"
46− anchors.fill: parent
47−
48− property int clickThreshold: units.gu(1.5)
49− property bool isClick: false
50− property bool pressed: false
51−
52− onPressed: {
53− print("pressed", point1.pressed, point2.pressed)
54− // If double-tapping *really* fast, it could happen that we end up having only point2 pressed
55− // Make sure we check for both combos, only point1 or only point2
56− if (((point1.pressed && !point2.pressed) || (!point1.pressed && point2.pressed))
57− && clickTimer.running) {
58− clickTimer.stop();
59− uinput.pressMouse(UInput.ButtonLeft)
60− pressed = true;
61− }
62− isClick = true;
52+ onUpdated: {
53+ switch (touchPoints.length) {
54+ case 1:
55+ moveMouse(touchPoints);
56+ return;
57+ case 2:
58+ scroll(touchPoints);
59+ return;
6360 }
61+ }
6462
65− onUpdated: {
66− switch (touchPoints.length) {
67− case 1:
68− moveMouse(touchPoints);
69− return;
70− case 2:
71− scroll(touchPoints);
72− return;
63+ onReleased: {
64+ var tp = touchPoints[0]
65+ if (isClick) {
66+ if (pressed) {
67+ uinput.releaseMouse(UInput.ButtonLeft)
68+ pressed = false;
7369 }
70+ clickTimer.scheduleClick(point1.pressed ? UInput.ButtonRight : UInput.ButtonLeft)
7471 }
72+ isClick = false;
73+ }
7574
76− onReleased: {
77− var tp = touchPoints[0]
78− if (isClick) {
79− if (pressed) {
80− uinput.releaseMouse(UInput.ButtonLeft)
81− pressed = false;
82− }
83− clickTimer.scheduleClick(point1.pressed ? UInput.ButtonRight : UInput.ButtonLeft)
84− }
85− isClick = false;
75+ Timer {
76+ id: clickTimer
77+ repeat: false
78+ interval: 100
79+ property int button: UInput.ButtonLeft
80+ onTriggered: {
81+ uinput.pressMouse(button);
82+ uinput.releaseMouse(button);
8683 }
84+ function scheduleClick(button) {
85+ clickTimer.button = button;
86+ clickTimer.start();
87+ }
88+ }
8789
88− Timer {
89− id: clickTimer
90− repeat: false
91− interval: 100
92− property int button: UInput.ButtonLeft
93− onTriggered: {
94− uinput.pressMouse(button);
95− uinput.releaseMouse(button);
96− }
97− function scheduleClick(button) {
98− clickTimer.button = button;
99− clickTimer.start();
100− }
90+ function moveMouse(touchPoints) {
91+ var tp = touchPoints[0];
92+ if (isClick &&
93+ (Math.abs(tp.x - tp.startX) > clickThreshold ||
94+ Math.abs(tp.y - tp.startY) > clickThreshold)) {
95+ isClick = false;
10196 }
10297
103− function moveMouse(touchPoints) {
104− var tp = touchPoints[0];
105− if (isClick &&
106− (Math.abs(tp.x - tp.startX) > clickThreshold ||
107− Math.abs(tp.y - tp.startY) > clickThreshold)) {
108− isClick = false;
109− }
98+ uinput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
99+ }
110100
111− uinput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
101+ function scroll(touchPoints) {
102+ var dh = 0;
103+ var dv = 0;
104+ var tp = touchPoints[0];
105+ if (isClick &&
106+ (Math.abs(tp.x - tp.startX) > clickThreshold ||
107+ Math.abs(tp.y - tp.startY) > clickThreshold)) {
108+ isClick = false;
112109 }
110+ dh += tp.x - tp.previousX;
111+ dv += tp.y - tp.previousY;
113112
114− function scroll(touchPoints) {
115− var dh = 0;
116− var dv = 0;
117− var tp = touchPoints[0];
118− if (isClick &&
119− (Math.abs(tp.x - tp.startX) > clickThreshold ||
120− Math.abs(tp.y - tp.startY) > clickThreshold)) {
121− isClick = false;
122− }
123− dh += tp.x - tp.previousX;
124− dv += tp.y - tp.previousY;
125−
126− tp = touchPoints[1];
127− if (isClick &&
128− (Math.abs(tp.x - tp.startX) > clickThreshold ||
129− Math.abs(tp.y - tp.startY) > clickThreshold)) {
130− isClick = false;
131− }
132− dh += tp.x - tp.previousX;
133− dv += tp.y - tp.previousY;
134−
135− uinput.scrollMouse(dh, dv);
113+ tp = touchPoints[1];
114+ if (isClick &&
115+ (Math.abs(tp.x - tp.startX) > clickThreshold ||
116+ Math.abs(tp.y - tp.startY) > clickThreshold)) {
117+ isClick = false;
136118 }
119+ dh += tp.x - tp.previousX;
120+ dv += tp.y - tp.previousY;
137121
138− touchPoints: [
139− TouchPoint {
140− id: point1
141− },
142− TouchPoint {
143− id: point2
144− }
145− ]
122+ uinput.scrollMouse(dh, dv);
146123 }
147− }
148124
149− RowLayout {
150− Layout.fillWidth: true
151− spacing: units.gu(2)
152− Button {
153− objectName: "leftButton"
154− Layout.fillWidth: true
155− onPressedChanged: {
156− if (pressed) {
157− uinput.pressMouse(UInput.ButtonLeft)
158− } else {
159− uinput.releaseMouse(UInput.ButtonLeft)
160− }
161− }
162− }
163− Button {
164− objectName: "rightButton"
165− Layout.fillWidth: true
166− onPressedChanged: {
167− if (pressed) {
168− uinput.pressMouse(UInput.ButtonRight)
169− } else {
170− uinput.releaseMouse(UInput.ButtonRight)
171− }
125+ touchPoints: [
126+ TouchPoint {
127+ id: point1
128+ },
129+ TouchPoint {
130+ id: point2
172131 }
173− }
132+ ]
174133 }
175134}