2 * Copyright (C) 2015 Canonical, Ltd.
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
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import Ubuntu.Components 1.3
22 property var uinput: UInput {
23 Component.onCompleted: createMouse();
24 Component.onDestruction: removeMouse();
27 readonly property bool pressed: point1.pressed || point2.pressed
30 objectName: "touchPadArea"
33 // FIXME: Once we have Qt DPR support, this should be Qt.styleHints.startDragDistance
34 readonly property int clickThreshold: units.gu(1.5)
35 property bool isClick: false
36 property bool isDoubleClick: false
37 property bool isDrag: false
40 // If double-tapping *really* fast, it could happen that we end up having only point2 pressed
41 // Make sure we check for both combos, only point1 or only point2
42 if (((point1.pressed && !point2.pressed) || (!point1.pressed && point2.pressed))
43 && clickTimer.running) {
45 uinput.pressMouse(UInput.ButtonLeft)
52 switch (touchPoints.length) {
54 moveMouse(touchPoints);
63 if (isDoubleClick || isDrag) {
64 uinput.releaseMouse(UInput.ButtonLeft)
65 isDoubleClick = false;
68 clickTimer.scheduleClick(point1.pressed ? UInput.ButtonRight : UInput.ButtonLeft)
78 property int button: UInput.ButtonLeft
80 uinput.pressMouse(button);
81 uinput.releaseMouse(button);
83 function scheduleClick(button) {
84 clickTimer.button = button;
89 function moveMouse(touchPoints) {
90 var tp = touchPoints[0];
92 (Math.abs(tp.x - tp.startX) > clickThreshold ||
93 Math.abs(tp.y - tp.startY) > clickThreshold)) {
98 uinput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
101 function scroll(touchPoints) {
104 var tp = touchPoints[0];
106 (Math.abs(tp.x - tp.startX) > clickThreshold ||
107 Math.abs(tp.y - tp.startY) > clickThreshold)) {
110 dh += tp.x - tp.previousX;
111 dv += tp.y - tp.previousY;
115 (Math.abs(tp.x - tp.startX) > clickThreshold ||
116 Math.abs(tp.y - tp.startY) > clickThreshold)) {
119 dh += tp.x - tp.previousX;
120 dv += tp.y - tp.previousY;
122 // As we added up the movement of the two fingers, let's divide it again by 2
126 uinput.scrollMouse(dh, dv);