@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013,2015 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
@@ -20,12 +20,15 @@
2020
2121#include <qpa/qwindowsysteminterface.h>
2222
23−#include <QtGui/QMouseEvent>
24−#include <QtTest/QTest>
23+#include <QCoreApplication>
24+#include <QMouseEvent>
25+#include <QTest>
2526
2627using QTest::QTouchEventSequence;
2728
2829namespace {
30+MouseTouchAdaptor *g_instance = nullptr;
31+
2932Qt::MouseButton translateMouseButton(xcb_button_t detail)
3033{
3134 switch (detail) {
@@ -39,16 +42,36 @@ Qt::MouseButton translateMouseButton(xcb_button_t detail)
3942} // end of anonymous namespace
4043
4144MouseTouchAdaptor::MouseTouchAdaptor()
42− : m_leftButtonIsPressed(false)
45+ : QObject(nullptr), m_leftButtonIsPressed(false), m_enabled(true)
4346{
47+ QCoreApplication::instance()->installNativeEventFilter(this);
48+
4449 m_touchDevice = new QTouchDevice;
4550 m_touchDevice->setType(QTouchDevice::TouchScreen);
4651 QWindowSystemInterface::registerTouchDevice(m_touchDevice);
4752}
4853
54+MouseTouchAdaptor::~MouseTouchAdaptor()
55+{
56+ g_instance = nullptr;
57+}
58+
59+MouseTouchAdaptor* MouseTouchAdaptor::instance()
60+{
61+ if (!g_instance) {
62+ g_instance = new MouseTouchAdaptor;
63+ }
64+
65+ return g_instance;
66+}
67+
4968bool MouseTouchAdaptor::nativeEventFilter(const QByteArray & eventType,
5069 void * message, long * /*result*/)
5170{
71+ if (!m_enabled) {
72+ return false;
73+ }
74+
5275 if (eventType != "xcb_generic_event_t") {
5376 // wrong backend.
5477 qWarning("MouseTouchAdaptor: XCB backend not in use. Adaptor inoperative!");
@@ -151,3 +174,16 @@ QWindow *MouseTouchAdaptor::findQWindowWithXWindowID(WId windowId)
151174 Q_ASSERT(foundWindow);
152175 return foundWindow;
153176}
177+
178+bool MouseTouchAdaptor::enabled() const
179+{
180+ return m_enabled;
181+}
182+
183+void MouseTouchAdaptor::setEnabled(bool value)
184+{
185+ if (value != m_enabled) {
186+ m_enabled = value;
187+ Q_EMIT enabledChanged(value);
188+ }
189+}