on xenial help sign in
merge prereq
83fec63Michael Zanetti
debian/unity8-private.install+1
@@ -12,6 +12,7 @@ usr/lib/*/unity8/qml/ScreenGrabber
12usr/lib/*/unity8/qml/SessionBroadcast
12usr/lib/*/unity8/qml/SessionBroadcast
13usr/lib/*/unity8/qml/Ubuntu
13usr/lib/*/unity8/qml/Ubuntu
14usr/lib/*/unity8/qml/Unity
14usr/lib/*/unity8/qml/Unity
15+usr/lib/*/unity8/qml/UInput
15usr/lib/*/unity8/qml/Utils
16usr/lib/*/unity8/qml/Utils
16usr/lib/*/unity8/qml/Wizard
17usr/lib/*/unity8/qml/Wizard
17usr/share/accountsservice/interfaces
18usr/share/accountsservice/interfaces
plugins/CMakeLists.txt+1
@@ -22,6 +22,7 @@ add_subdirectory(Powerd)
22add_subdirectory(SessionBroadcast)
22add_subdirectory(SessionBroadcast)
23add_subdirectory(ScreenGrabber)
23add_subdirectory(ScreenGrabber)
24add_subdirectory(Ubuntu)
24add_subdirectory(Ubuntu)
25+add_subdirectory(UInput)
25add_subdirectory(Unity)
26add_subdirectory(Unity)
26add_subdirectory(Utils)
27add_subdirectory(Utils)
27add_subdirectory(Wizard)
28add_subdirectory(Wizard)
plugins/UInput/CMakeLists.txtnew file+7
@@ -0,0 +1,7 @@
1+add_library(UInput-qml MODULE
2+ plugin.cpp
3+ uinput.cpp
4+)
5+
6+qt5_use_modules(UInput-qml Qml)
7+add_unity8_plugin(UInput 0.1 UInput TARGETS UInput-qml)
plugins/UInput/UInput.qmltypesnew file+44
@@ -0,0 +1,44 @@
1+import QtQuick.tooling 1.1
2+
3+// This file describes the plugin-supplied types contained in the library.
4+// It is used for QML tooling purposes only.
5+//
6+// This file was auto-generated by:
7+// 'qmlplugindump -notrelocatable UInput 0.1 plugins'
8+
9+Module {
10+ Component {
11+ name: "UInput"
12+ prototype: "QObject"
13+ exports: ["UInput/UInput 0.1"]
14+ exportMetaObjectRevisions: [0]
15+ Enum {
16+ name: "Button"
17+ values: {
18+ "ButtonLeft": 0,
19+ "ButtonRight": 1,
20+ "ButtonMiddle": 2
21+ }
22+ }
23+ Method { name: "createMouse" }
24+ Method { name: "removeMouse" }
25+ Method {
26+ name: "moveMouse"
27+ Parameter { name: "dx"; type: "int" }
28+ Parameter { name: "dy"; type: "int" }
29+ }
30+ Method {
31+ name: "pressMouse"
32+ Parameter { name: "button"; type: "Button" }
33+ }
34+ Method {
35+ name: "releaseMouse"
36+ Parameter { name: "button"; type: "Button" }
37+ }
38+ Method {
39+ name: "scrollMouse"
40+ Parameter { name: "dh"; type: "int" }
41+ Parameter { name: "dv"; type: "int" }
42+ }
43+ }
44+}
plugins/UInput/plugin.cppnew file+26
@@ -0,0 +1,26 @@
1+/*
2+ * Copyright (C) 2015 Canonical Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it
5+ * under the terms of the GNU General Public License version 3, as published
6+ * by the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but
9+ * WITHOUT ANY WARRANTY; without even the implied warranties of
10+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11+ * PURPOSE. See the GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License along
14+ * with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "plugin.h"
18+#include "uinput.h"
19+
20+#include <QtQml/qqml.h>
21+
22+void UInputPlugin::registerTypes(const char *uri)
23+{
24+ Q_ASSERT(uri == QLatin1String("UInput"));
25+ qmlRegisterType<UInput>(uri, 0, 1, "UInput");
26+}
plugins/UInput/plugin.hnew file+32
@@ -0,0 +1,32 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ */
16+
17+#ifndef UINPUT_PLUGIN_H
18+#define UINPUT_PLUGIN_H
19+
20+#include <QtQml/QQmlEngine>
21+#include <QtQml/QQmlExtensionPlugin>
22+
23+class UInputPlugin : public QQmlExtensionPlugin
24+{
25+ Q_OBJECT
26+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
27+
28+public:
29+ void registerTypes(const char *uri) override;
30+};
31+
32+#endif
plugins/UInput/qmldirnew file+3
@@ -0,0 +1,3 @@
1+module UInput
2+plugin UInput-qml
3+typeinfo UInput.qmltypes
plugins/UInput/uinput.cppnew file+182
@@ -0,0 +1,182 @@
1+/*
2+ * Copyright (C) 2015 Canonical Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it
5+ * under the terms of the GNU General Public License version 3, as published
6+ * by the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but
9+ * WITHOUT ANY WARRANTY; without even the implied warranties of
10+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11+ * PURPOSE. See the GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License along
14+ * with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "uinput.h"
18+
19+#include <QFile>
20+#include <QDebug>
21+#include <QDateTime>
22+
23+#include <unistd.h>
24+#include <time.h>
25+
26+UInput::UInput(QObject *parent) :
27+ QObject(parent)
28+{
29+ m_devName = QByteArrayLiteral("unity8-simulated-mouse");
30+ m_uinput.setFileName(QStringLiteral("/dev/uinput"));
31+
32+ memset(&m_uinput_mouse_dev, 0, sizeof(m_uinput_mouse_dev));
33+ m_uinput_mouse_dev.id.bustype = BUS_USB;
34+ m_uinput_mouse_dev.id.version = 1;
35+ strncpy(m_uinput_mouse_dev.name, m_devName.constData(), m_devName.length());
36+}
37+
38+UInput::~UInput()
39+{
40+ if (m_mouseCreated) {
41+ removeMouse();
42+ }
43+}
44+
45+void UInput::createMouse()
46+{
47+ if (m_mouseCreated) {
48+ qDebug() << "Already have a virtual device. Not creating another one.";
49+ return;
50+ }
51+
52+ if (!m_uinput.isOpen() && !m_uinput.open(QFile::WriteOnly)) {
53+ return;
54+ }
55+
56+ ioctl(m_uinput.handle(), UI_SET_EVBIT, EV_REL);
57+ ioctl(m_uinput.handle(), UI_SET_RELBIT, REL_X);
58+ ioctl(m_uinput.handle(), UI_SET_RELBIT, REL_Y);
59+ ioctl(m_uinput.handle(), UI_SET_RELBIT, REL_HWHEEL);
60+ ioctl(m_uinput.handle(), UI_SET_RELBIT, REL_WHEEL);
61+
62+ ioctl(m_uinput.handle(), UI_SET_EVBIT, EV_KEY);
63+ ioctl(m_uinput.handle(), UI_SET_KEYBIT, BTN_MOUSE);
64+ ioctl(m_uinput.handle(), UI_SET_KEYBIT, BTN_LEFT);
65+ ioctl(m_uinput.handle(), UI_SET_KEYBIT, BTN_MIDDLE);
66+ ioctl(m_uinput.handle(), UI_SET_KEYBIT, BTN_RIGHT);
67+ ioctl(m_uinput.handle(), UI_SET_KEYBIT, BTN_FORWARD);
68+ ioctl(m_uinput.handle(), UI_SET_KEYBIT, BTN_BACK);
69+
70+ ioctl(m_uinput.handle(), UI_SET_EVBIT, EV_SYN);
71+
72+ int len = write(m_uinput.handle(), &m_uinput_mouse_dev, sizeof(m_uinput_mouse_dev));
73+ if (len <= 0) {
74+ qWarning() << "Failed to write to uinput. Cannot create virtual uinput mouse.";
75+ return;
76+ }
77+
78+ int err = ioctl(m_uinput.handle(), UI_DEV_CREATE);
79+ if (err != 0) {
80+ qWarning() << "Cannot create virtual uinput device. Create ioctl failed:" << err;
81+ return;
82+ }
83+ m_mouseCreated = true;
84+ qDebug() << "Virtual uinput mouse device created.";
85+}
86+
87+void UInput::removeMouse()
88+{
89+ if (!m_mouseCreated) {
90+ return;
91+ }
92+
93+ if (!m_uinput.isOpen() && !m_uinput.open(QFile::WriteOnly)) {
94+ qWarning() << "cannot open uinput... ";
95+ return;
96+ }
97+
98+ int err = ioctl(m_uinput.handle(), UI_DEV_DESTROY);
99+ if (err != 0) {
100+ qWarning() << "Failed to destroy virtual uinput device. Destroy ioctl failed:" << err;
101+ } else {
102+ qDebug() << "Virtual uinput mouse device removed.";
103+ }
104+ m_uinput.close();
105+ m_mouseCreated = false;
106+}
107+
108+void UInput::moveMouse(int dx, int dy)
109+{
110+ struct input_event event;
111+ memset(&event, 0, sizeof(event));
112+ clock_gettime(CLOCK_MONOTONIC, (timespec*)&event.time);
113+ event.type = EV_REL;
114+ event.code = REL_X;
115+ event.value = dx;
116+ write(m_uinput.handle(), &event, sizeof(event));
117+
118+ event.code = REL_Y;
119+ event.value = dy;
120+ write(m_uinput.handle(), &event, sizeof(event));
121+
122+ event.type = EV_SYN;
123+ event.code = SYN_REPORT;
124+ event.value = 0;
125+ write(m_uinput.handle(), &event, sizeof(event));
126+}
127+
128+void UInput::pressMouse(Button button)
129+{
130+ injectMouse(button, 1);
131+}
132+
133+void UInput::releaseMouse(Button button)
134+{
135+ injectMouse(button, 0);
136+}
137+
138+void UInput::scrollMouse(int dh, int dv)
139+{
140+ struct input_event event;
141+ memset(&event, 0, sizeof(event));
142+ clock_gettime(CLOCK_MONOTONIC, (timespec*)&event.time);
143+ event.type = EV_REL;
144+ event.code = REL_HWHEEL;
145+ event.value = dh;
146+ write(m_uinput.handle(), &event, sizeof(event));
147+
148+ event.code = REL_WHEEL;
149+ event.value = dv;
150+ write(m_uinput.handle(), &event, sizeof(event));
151+
152+ event.type = EV_SYN;
153+ event.code = SYN_REPORT;
154+ event.value = 0;
155+ write(m_uinput.handle(), &event, sizeof(event));
156+}
157+
158+void UInput::injectMouse(Button button, int down)
159+{
160+ struct input_event event;
161+ memset(&event, 0, sizeof(event));
162+ clock_gettime(CLOCK_MONOTONIC, (timespec*)&event.time);
163+ event.type = EV_KEY;
164+ switch (button) {
165+ case ButtonLeft:
166+ event.code = BTN_LEFT;
167+ break;
168+ case ButtonRight:
169+ event.code = BTN_RIGHT;
170+ break;
171+ case ButtonMiddle:
172+ event.code = BTN_MIDDLE;
173+ break;
174+ }
175+ event.value = down;
176+ write(m_uinput.handle(), &event, sizeof(event));
177+
178+ event.type = EV_SYN;
179+ event.code = SYN_REPORT;
180+ event.value = 0;
181+ write(m_uinput.handle(), &event, sizeof(event));
182+}
plugins/UInput/uinput.hnew file+61
@@ -0,0 +1,61 @@
1+/*
2+ * Copyright (C) 2015 Canonical Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it
5+ * under the terms of the GNU General Public License version 3, as published
6+ * by the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but
9+ * WITHOUT ANY WARRANTY; without even the implied warranties of
10+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11+ * PURPOSE. See the GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License along
14+ * with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+
18+#ifndef UINPUT_H
19+#define UINPUT_H
20+
21+#include <QObject>
22+#include <QFile>
23+
24+#include <linux/uinput.h>
25+
26+
27+class UInput : public QObject
28+{
29+ Q_OBJECT
30+ Q_ENUMS(Button)
31+
32+public:
33+ enum Button {
34+ ButtonLeft,
35+ ButtonRight,
36+ ButtonMiddle
37+ };
38+
39+ explicit UInput(QObject *parent = nullptr);
40+ ~UInput();
41+
42+ Q_INVOKABLE void createMouse();
43+ Q_INVOKABLE void removeMouse();
44+
45+ Q_INVOKABLE void moveMouse(int dx, int dy);
46+ Q_INVOKABLE void pressMouse(Button button);
47+ Q_INVOKABLE void releaseMouse(Button button);
48+ Q_INVOKABLE void scrollMouse(int dh, int dv);
49+
50+private:
51+ void injectMouse(Button button, int down);
52+
53+private:
54+ QFile m_uinput;
55+ uinput_user_dev m_uinput_mouse_dev;
56+ QByteArray m_devName;
57+
58+ bool m_mouseCreated = false;
59+};
60+
61+#endif // UINPUT_H
po/unity8.pot+8−6
@@ -8,7 +8,7 @@ msgid ""
8msgstr ""
8msgstr ""
9"Project-Id-Version: unity8\n"
9"Project-Id-Version: unity8\n"
10"Report-Msgid-Bugs-To: \n"
10"Report-Msgid-Bugs-To: \n"
11−"POT-Creation-Date: 2015-11-20 14:45+0100\n"
11+"POT-Creation-Date: 2015-11-30 10:09+0100\n"
12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14"Language-Team: LANGUAGE <LL@li.org>\n"
14"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -194,15 +194,15 @@ msgstr ""
194msgid "Add to Favorites"
194msgid "Add to Favorites"
195msgstr ""
195msgstr ""
196
196
197−#: qml/Dash/GenericScopeView.qml:569 qml/Dash/GenericScopeView.qml:727
197+#: qml/Dash/GenericScopeView.qml:570 qml/Dash/GenericScopeView.qml:728
198msgid "See less"
198msgid "See less"
199msgstr ""
199msgstr ""
200
200
201−#: qml/Dash/GenericScopeView.qml:569
201+#: qml/Dash/GenericScopeView.qml:570
202msgid "See all"
202msgid "See all"
203msgstr ""
203msgstr ""
204
204
205−#: qml/Dash/GenericScopeView.qml:631
205+#: qml/Dash/GenericScopeView.qml:632
206msgctxt "Label: Hint for dash search line edit"
206msgctxt "Label: Hint for dash search line edit"
207msgid "Search"
207msgid "Search"
208msgstr ""
208msgstr ""
@@ -256,8 +256,10 @@ msgstr ""
256msgid "Also installed"
256msgid "Also installed"
257msgstr ""
257msgstr ""
258
258
259−#: qml/DisabledScreenNotice.qml:42
259+#: qml/DisabledScreenNotice.qml:61
260+msgid ""
260−msgid "Your device is now connected to an external display."
261+"Your device is now connected to an external display. Use this screen as a "
262+"touch pad to interact with the mouse."
261msgstr ""
263msgstr ""
262
264
263#: qml/Greeter/CoverPage.qml:107
265#: qml/Greeter/CoverPage.qml:107
qml/Components/VirtualTouchPad.qmlnew file+133
@@ -0,0 +1,133 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ */
16+
17+import QtQuick 2.4
18+import Ubuntu.Components 1.3
19+import UInput 0.1
20+
21+Item {
22+ property var uinput: UInput {
23+ Component.onCompleted: createMouse();
24+ Component.onDestruction: removeMouse();
25+ }
26+
27+
28+ MultiPointTouchArea {
29+ objectName: "touchPadArea"
30+ anchors.fill: parent
31+
32+ property int clickThreshold: units.gu(1.5)
33+ property bool isClick: false
34+ property bool pressed: false
35+
36+ onPressed: {
37+ // If double-tapping *really* fast, it could happen that we end up having only point2 pressed
38+ // Make sure we check for both combos, only point1 or only point2
39+ if (((point1.pressed && !point2.pressed) || (!point1.pressed && point2.pressed))
40+ && clickTimer.running) {
41+ clickTimer.stop();
42+ uinput.pressMouse(UInput.ButtonLeft)
43+ pressed = true;
44+ }
45+ isClick = true;
46+ }
47+
48+ onUpdated: {
49+ switch (touchPoints.length) {
50+ case 1:
51+ moveMouse(touchPoints);
52+ return;
53+ case 2:
54+ scroll(touchPoints);
55+ return;
56+ }
57+ }
58+
59+ onReleased: {
60+ if (isClick) {
61+ if (pressed) {
62+ uinput.releaseMouse(UInput.ButtonLeft)
63+ pressed = false;
64+ }
65+ clickTimer.scheduleClick(point1.pressed ? UInput.ButtonRight : UInput.ButtonLeft)
66+ }
67+ isClick = false;
68+ }
69+
70+ Timer {
71+ id: clickTimer
72+ repeat: false
73+ interval: 100
74+ property int button: UInput.ButtonLeft
75+ onTriggered: {
76+ uinput.pressMouse(button);
77+ uinput.releaseMouse(button);
78+ }
79+ function scheduleClick(button) {
80+ clickTimer.button = button;
81+ clickTimer.start();
82+ }
83+ }
84+
85+ function moveMouse(touchPoints) {
86+ var tp = touchPoints[0];
87+ if (isClick &&
88+ (Math.abs(tp.x - tp.startX) > clickThreshold ||
89+ Math.abs(tp.y - tp.startY) > clickThreshold)) {
90+ isClick = false;
91+ }
92+
93+ uinput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
94+ }
95+
96+ function scroll(touchPoints) {
97+ var dh = 0;
98+ var dv = 0;
99+ var tp = touchPoints[0];
100+ if (isClick &&
101+ (Math.abs(tp.x - tp.startX) > clickThreshold ||
102+ Math.abs(tp.y - tp.startY) > clickThreshold)) {
103+ isClick = false;
104+ }
105+ dh += tp.x - tp.previousX;
106+ dv += tp.y - tp.previousY;
107+
108+ tp = touchPoints[1];
109+ if (isClick &&
110+ (Math.abs(tp.x - tp.startX) > clickThreshold ||
111+ Math.abs(tp.y - tp.startY) > clickThreshold)) {
112+ isClick = false;
113+ }
114+ dh += tp.x - tp.previousX;
115+ dv += tp.y - tp.previousY;
116+
117+ // As we added up the movement of the two fingers, let's divide it again by 2
118+ dh /= 2;
119+ dv /= 2;
120+
121+ uinput.scrollMouse(dh, dv);
122+ }
123+
124+ touchPoints: [
125+ TouchPoint {
126+ id: point1
127+ },
128+ TouchPoint {
129+ id: point2
130+ }
131+ ]
132+ }
133+}
qml/DisabledScreenNotice.qml+35−15
@@ -15,12 +15,15 @@
15 */
15 */
16
16
17import QtQuick 2.4
17import QtQuick 2.4
18+import QtQuick.Layouts 1.1
18import Ubuntu.Components 1.3
19import Ubuntu.Components 1.3
19import "Components"
20import "Components"
20
21
21Image {
22Image {
22 id: root
23 id: root
23
24
25+ property bool infoNoteDisplayed: true
26+
24 WallpaperResolver {
27 WallpaperResolver {
25 width: root.width
28 width: root.width
26 id: wallpaperResolver
29 id: wallpaperResolver
@@ -28,22 +31,39 @@ Image {
28
31
29 source: wallpaperResolver.background
32 source: wallpaperResolver.background
30
33
31− UbuntuShape {
34+
35+ VirtualTouchPad {
32− anchors.fill: text
36+ anchors.fill: parent
33− anchors.margins: -units.gu(2)
34− backgroundColor: "black"
35− opacity: 0.4
36 }
37 }
37
38
39+ MouseArea {
40+ objectName: "infoNoticeMouseArea"
41+ anchors.fill: parent
42+ opacity: infoNoteDisplayed ? 1 : 0
43+ visible: opacity > 0
44+ enabled: visible
45+ Behavior on opacity {
46+ UbuntuNumberAnimation { }
47+ }
48+
49+ onClicked: root.infoNoteDisplayed = false;
50+
51+ Rectangle {
52+ anchors.fill: parent
53+ color: "black"
54+ opacity: 0.4
55+ }
56+
38− Label {
57+ Label {
39− id: text
58+ id: text
40− anchors.centerIn: parent
59+ anchors.centerIn: parent
41− width: parent.width / 2
60+ width: parent.width - units.gu(8)
42− text: i18n.tr("Your device is now connected to an external display.")
61+ text: i18n.tr("Your device is now connected to an external display. Use this screen as a touch pad to interact with the mouse.")
43− color: "white"
62+ color: "white"
44− horizontalAlignment: Text.AlignHCenter
63+ horizontalAlignment: Text.AlignHCenter
45− verticalAlignment: Text.AlignVCenter
64+ verticalAlignment: Text.AlignVCenter
46− fontSize: "x-large"
65+ fontSize: "x-large"
47− wrapMode: Text.Wrap
66+ wrapMode: Text.Wrap
67+ }
48 }
68 }
49}
69}
tests/mocks/CMakeLists.txt+1
@@ -43,6 +43,7 @@ add_subdirectory(Unity)
43add_subdirectory(QtMultimedia)
43add_subdirectory(QtMultimedia)
44add_subdirectory(Wizard)
44add_subdirectory(Wizard)
45add_subdirectory(Utils)
45add_subdirectory(Utils)
46+add_subdirectory(UInput)
46
47
47install(
48install(
48 DIRECTORY data
49 DIRECTORY data
tests/mocks/UInput/CMakeLists.txtnew file+7
@@ -0,0 +1,7 @@
1+add_library(FakeUInput-qml MODULE
2+ plugin.cpp
3+ mockuinput.cpp
4+)
5+
6+qt5_use_modules(FakeUInput-qml Qml)
7+add_unity8_mock(UInput 0.1 UInput TARGETS FakeUInput-qml)
tests/mocks/UInput/mockuinput.cppnew file+73
@@ -0,0 +1,73 @@
1+/*
2+ * Copyright (C) 2015 Canonical Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it
5+ * under the terms of the GNU General Public License version 3, as published
6+ * by the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but
9+ * WITHOUT ANY WARRANTY; without even the implied warranties of
10+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11+ * PURPOSE. See the GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License along
14+ * with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+
18+#include "mockuinput.h"
19+
20+#include <QFile>
21+#include <QDebug>
22+#include <QDateTime>
23+
24+#include <unistd.h>
25+
26+MockUInput::MockUInput(QObject *parent) :
27+ QObject(parent)
28+{
29+}
30+
31+MockUInput::~MockUInput()
32+{
33+}
34+
35+void MockUInput::createMouse()
36+{
37+ if (m_mouseCreated) {
38+ qDebug() << "Already have a virtual device. Not creating another one.";
39+ return;
40+ }
41+ m_mouseCreated = true;
42+ Q_EMIT mouseCreated();
43+}
44+
45+void MockUInput::removeMouse()
46+{
47+ if (!m_mouseCreated) {
48+ return;
49+ }
50+ qDebug() << "Virtual uinput mouse device removed.";
51+ m_mouseCreated = false;
52+ Q_EMIT mouseRemoved();
53+}
54+
55+void MockUInput::moveMouse(int dx, int dy)
56+{
57+ Q_EMIT mouseMoved(dx, dy);
58+}
59+
60+void MockUInput::pressMouse(Button button)
61+{
62+ Q_EMIT mousePressed(button);
63+}
64+
65+void MockUInput::releaseMouse(Button button)
66+{
67+ Q_EMIT mouseReleased(button);
68+}
69+
70+void MockUInput::scrollMouse(int dh, int dv)
71+{
72+ Q_EMIT mouseScrolled(dh, dv);
73+}
tests/mocks/UInput/mockuinput.hnew file+63
@@ -0,0 +1,63 @@
1+/*
2+ * Copyright (C) 2015 Canonical Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it
5+ * under the terms of the GNU General Public License version 3, as published
6+ * by the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but
9+ * WITHOUT ANY WARRANTY; without even the implied warranties of
10+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11+ * PURPOSE. See the GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License along
14+ * with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+
18+#ifndef MOCKUINPUT_H
19+#define MOCKUINPUT_H
20+
21+#include <QObject>
22+#include <QFile>
23+
24+#include <linux/uinput.h>
25+
26+
27+class MockUInput : public QObject
28+{
29+ Q_OBJECT
30+ Q_ENUMS(Button)
31+
32+public:
33+ enum Button {
34+ ButtonLeft,
35+ ButtonRight,
36+ ButtonMiddle
37+ };
38+
39+ explicit MockUInput(QObject *parent = 0);
40+ ~MockUInput();
41+
42+ Q_INVOKABLE void createMouse();
43+ Q_INVOKABLE void removeMouse();
44+
45+ Q_INVOKABLE void moveMouse(int dx, int dy);
46+ Q_INVOKABLE void pressMouse(Button button);
47+ Q_INVOKABLE void releaseMouse(Button button);
48+ Q_INVOKABLE void scrollMouse(int dh, int dv);
49+
50+Q_SIGNALS:
51+ // for testing
52+ void mouseCreated();
53+ void mouseRemoved();
54+ void mouseMoved(int dx, int dy);
55+ void mousePressed(Button button);
56+ void mouseReleased(Button button);
57+ void mouseScrolled(int dh, int dv);
58+
59+private:
60+ bool m_mouseCreated = false;
61+};
62+
63+#endif // MOCKUINPUT_H
tests/mocks/UInput/plugin.cppnew file+26
@@ -0,0 +1,26 @@
1+/*
2+ * Copyright (C) 2015 Canonical Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it
5+ * under the terms of the GNU General Public License version 3, as published
6+ * by the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but
9+ * WITHOUT ANY WARRANTY; without even the implied warranties of
10+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11+ * PURPOSE. See the GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License along
14+ * with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "plugin.h"
18+#include "mockuinput.h"
19+
20+#include <QtQml/qqml.h>
21+
22+void MockUInputPlugin::registerTypes(const char *uri)
23+{
24+ Q_ASSERT(uri == QLatin1String("UInput"));
25+ qmlRegisterType<MockUInput>(uri, 0, 1, "UInput");
26+}
tests/mocks/UInput/plugin.hnew file+32
@@ -0,0 +1,32 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ */
16+
17+#ifndef MOCKUINPUT_PLUGIN_H
18+#define MOCKUINPUT_PLUGIN_H
19+
20+#include <QtQml/QQmlEngine>
21+#include <QtQml/QQmlExtensionPlugin>
22+
23+class MockUInputPlugin : public QQmlExtensionPlugin
24+{
25+ Q_OBJECT
26+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
27+
28+public:
29+ void registerTypes(const char *uri) override;
30+};
31+
32+#endif
tests/mocks/UInput/qmldirnew file+2
@@ -0,0 +1,2 @@
1+module UInput
2+plugin FakeUInput-qml
tests/qmltests/CMakeLists.txt+1
@@ -17,6 +17,7 @@ add_unity8_qmltest(Components Rating)
17add_unity8_qmltest(Components ResponsiveGridView)
17add_unity8_qmltest(Components ResponsiveGridView)
18add_unity8_qmltest(Components ResponsiveVerticalJournal)
18add_unity8_qmltest(Components ResponsiveVerticalJournal)
19add_unity8_qmltest(Components Showable)
19add_unity8_qmltest(Components Showable)
20+add_unity8_qmltest(Components VirtualTouchPad)
20add_unity8_qmltest(Components WallpaperResolver)
21add_unity8_qmltest(Components WallpaperResolver)
21add_unity8_qmltest(Components ZoomableImage)
22add_unity8_qmltest(Components ZoomableImage)
22add_unity8_qmltest(Dash Dash)
23add_unity8_qmltest(Dash Dash)
tests/qmltests/Components/tst_VirtualTouchPad.qmlnew file+112
@@ -0,0 +1,112 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ */
16+
17+import QtQuick 2.4
18+import QtTest 1.0
19+import Unity.Test 0.1
20+import UInput 0.1
21+import "../../../qml/Components"
22+
23+
24+Item {
25+ id: root
26+ width: units.gu(70)
27+ height: units.gu(70)
28+
29+ VirtualTouchPad {
30+ id: touchScreenPad
31+ anchors.fill: parent
32+ }
33+
34+ SignalSpy {
35+ id: mouseEventSpy1
36+ target: touchScreenPad.uinput
37+ }
38+ SignalSpy {
39+ id: mouseEventSpy2
40+ target: touchScreenPad.uinput
41+ }
42+
43+ UnityTestCase {
44+ id: testCase
45+ name: "VirtualTouchPad"
46+ when: windowShown
47+
48+ function init() {
49+ mouseEventSpy1.clear();
50+ mouseEventSpy2.clear();
51+ }
52+
53+ function test_click() {
54+ mouseEventSpy1.signalName = "mousePressed"
55+ mouseEventSpy2.signalName = "mouseReleased"
56+
57+ var touchPadArea = findChild(touchScreenPad, "touchPadArea");
58+
59+ tap(touchPadArea)
60+ tryCompare(mouseEventSpy1, "count", 1)
61+ tryCompare(mouseEventSpy2, "count", 1)
62+ }
63+
64+ function test_doubleClick() {
65+ mouseEventSpy1.signalName = "mousePressed"
66+ mouseEventSpy2.signalName = "mouseReleased"
67+
68+ var touchPadArea = findChild(touchScreenPad, "touchPadArea");
69+
70+ tap(touchPadArea)
71+ tap(touchPadArea)
72+
73+ tryCompare(mouseEventSpy1, "count", 2)
74+ tryCompare(mouseEventSpy2, "count", 2)
75+ }
76+
77+ function test_move() {
78+ mouseEventSpy1.signalName = "mouseMoved"
79+
80+ var touchPadArea = findChild(touchScreenPad, "touchPadArea");
81+
82+ var moveDiff = units.gu(2);
83+ var moveSteps = 5;
84+
85+ touchFlick(touchPadArea, units.gu(1), units.gu(1), units.gu(1) + moveDiff, units.gu(1) + moveDiff, true, true, 10, moveSteps)
86+
87+ tryCompare(mouseEventSpy1, "count", moveSteps)
88+ var movedX = 0;
89+ var movedY = 0
90+ for (var i = 0; i < 5; i++) {
91+ movedX += mouseEventSpy1.signalArguments[i][0]
92+ movedY += mouseEventSpy1.signalArguments[i][1]
93+ }
94+ compare(movedX, moveDiff)
95+ compare(movedY, moveDiff)
96+ }
97+
98+ function test_doubleTapAndHoldToDrag() {
99+ mouseEventSpy1.signalName = "mousePressed"
100+ mouseEventSpy2.signalName = "mouseReleased"
101+
102+ var touchPadArea = findChild(touchScreenPad, "touchPadArea");
103+
104+ tap(touchPadArea)
105+ mousePress(touchPadArea)
106+
107+ tryCompare(mouseEventSpy1, "count", 1)
108+ tryCompare(mouseEventSpy2, "count", 0)
109+ mouseRelease(touchPadArea)
110+ }
111+ }
112+}
tests/qmltests/tst_DisabledScreenNotice.qml+9−2
@@ -19,13 +19,13 @@ import QtTest 1.0
19import Unity.Test 0.1
19import Unity.Test 0.1
20import "../../qml"
20import "../../qml"
21
21
22−
23Item {
22Item {
24 id: root
23 id: root
25− width: units.gu(70)
24+ width: units.gu(40)
26 height: units.gu(70)
25 height: units.gu(70)
27
26
28 DisabledScreenNotice {
27 DisabledScreenNotice {
28+ id: touchScreenPad
29 anchors.fill: parent
29 anchors.fill: parent
30 }
30 }
31
31
@@ -33,5 +33,12 @@ Item {
33 id: testCase
33 id: testCase
34 name: "DisabledScreenNotice"
34 name: "DisabledScreenNotice"
35 when: windowShown
35 when: windowShown
36+
37+ function test_mouseAreaHidesOnFirstTap() {
38+ var mouseArea = findChild(touchScreenPad, "infoNoticeMouseArea")
39+ compare(mouseArea.enabled, true)
40+ tap(root)
41+ tryCompare(mouseArea, "enabled", false)
42+ }
36 }
43 }
37}
44}