@@ -1,5 +1,5 @@
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013,2015 Canonical, Ltd.
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
@@ -20,12 +20,15 @@
21#include <qpa/qwindowsysteminterface.h>
21#include <qpa/qwindowsysteminterface.h>
23+#include <QCoreApplication>
23−#include <QtGui/QMouseEvent>
24+#include <QMouseEvent>
24−#include <QtTest/QTest>
25+#include <QTest>
26using QTest::QTouchEventSequence;
27using QTest::QTouchEventSequence;
28namespace {
29namespace {
30+MouseTouchAdaptor *g_instance = nullptr;
29Qt::MouseButton translateMouseButton(xcb_button_t detail)
32Qt::MouseButton translateMouseButton(xcb_button_t detail)
31 switch (detail) {
34 switch (detail) {
@@ -39,16 +42,36 @@ Qt::MouseButton translateMouseButton(xcb_button_t detail)
39} // end of anonymous namespace
42} // end of anonymous namespace
41MouseTouchAdaptor::MouseTouchAdaptor()
44MouseTouchAdaptor::MouseTouchAdaptor()
42− : m_leftButtonIsPressed(false)
45+ : QObject(nullptr), m_leftButtonIsPressed(false), m_enabled(true)
47+ QCoreApplication::instance()->installNativeEventFilter(this);
44 m_touchDevice = new QTouchDevice;
49 m_touchDevice = new QTouchDevice;
45 m_touchDevice->setType(QTouchDevice::TouchScreen);
50 m_touchDevice->setType(QTouchDevice::TouchScreen);
46 QWindowSystemInterface::registerTouchDevice(m_touchDevice);
51 QWindowSystemInterface::registerTouchDevice(m_touchDevice);
54+MouseTouchAdaptor::~MouseTouchAdaptor()
56+ g_instance = nullptr;
59+MouseTouchAdaptor* MouseTouchAdaptor::instance()
62+ g_instance = new MouseTouchAdaptor;
49bool MouseTouchAdaptor::nativeEventFilter(const QByteArray & eventType,
68bool MouseTouchAdaptor::nativeEventFilter(const QByteArray & eventType,
50 void * message, long * /*result*/)
69 void * message, long * /*result*/)
52 if (eventType != "xcb_generic_event_t") {
75 if (eventType != "xcb_generic_event_t") {
53 // wrong backend.
76 // wrong backend.
54 qWarning("MouseTouchAdaptor: XCB backend not in use. Adaptor inoperative!");
77 qWarning("MouseTouchAdaptor: XCB backend not in use. Adaptor inoperative!");
@@ -151,3 +174,16 @@ QWindow *MouseTouchAdaptor::findQWindowWithXWindowID(WId windowId)
151 Q_ASSERT(foundWindow);
174 Q_ASSERT(foundWindow);
152 return foundWindow;
175 return foundWindow;
178+bool MouseTouchAdaptor::enabled() const
183+void MouseTouchAdaptor::setEnabled(bool value)
185+ if (value != m_enabled) {
187+ Q_EMIT enabledChanged(value);