2 * Copyright (C) 2013 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/>.
16 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
19#include "MouseTouchAdaptor.h"
21#include <qpa/qwindowsysteminterface.h>
23#include <QtGui/QMouseEvent>
24#include <QtTest/QTest>
26using QTest::QTouchEventSequence;
29Qt::MouseButton translateMouseButton(xcb_button_t detail)
32 case 1: return Qt::LeftButton;
33 case 2: return Qt::MidButton;
34 case 3: return Qt::RightButton;
35 // Button values 4-7 are Wheel events
36 default: return Qt::NoButton;
39} // end of anonymous namespace
41MouseTouchAdaptor::MouseTouchAdaptor()
42 : m_leftButtonIsPressed(false)
44 m_touchDevice = new QTouchDevice;
45 m_touchDevice->setType(QTouchDevice::TouchScreen);
46 QWindowSystemInterface::registerTouchDevice(m_touchDevice);
49bool MouseTouchAdaptor::nativeEventFilter(const QByteArray & eventType,
50 void * message, long * /*result*/)
52 if (eventType != "xcb_generic_event_t") {
54 qWarning("MouseTouchAdaptor: XCB backend not in use. Adaptor inoperative!");
58 xcb_generic_event_t *xcbEvent = static_cast<xcb_generic_event_t *>(message);
60 switch (xcbEvent->response_type & ~0x80) {
61 case XCB_BUTTON_PRESS:
62 return handleButtonPress(reinterpret_cast<xcb_button_press_event_t *>(xcbEvent));
64 case XCB_BUTTON_RELEASE:
65 return handleButtonRelease(reinterpret_cast<xcb_button_release_event_t *>(xcbEvent));
67 case XCB_MOTION_NOTIFY:
68 return handleMotionNotify(reinterpret_cast<xcb_motion_notify_event_t *>(xcbEvent));
76bool MouseTouchAdaptor::handleButtonPress(xcb_button_press_event_t *pressEvent)
78 Qt::MouseButton button = translateMouseButton(pressEvent->detail);
80 // Just eat the event if it wasn't a left mouse press
81 if (button != Qt::LeftButton)
84 QPoint windowPos(pressEvent->event_x, pressEvent->event_y);
86 QWindow *targetWindow = findQWindowWithXWindowID(static_cast<WId>(pressEvent->event));
88 QTouchEventSequence touchEvent = QTest::touchEvent(targetWindow, m_touchDevice,
89 false /* autoCommit */);
90 touchEvent.press(0 /* touchId */, windowPos);
91 touchEvent.commit(false /* processEvents */);
93 m_leftButtonIsPressed = true;
97bool MouseTouchAdaptor::handleButtonRelease(xcb_button_release_event_t *releaseEvent)
99 Qt::MouseButton button = translateMouseButton(releaseEvent->detail);
101 // Just eat the event if it wasn't a left mouse release
102 if (button != Qt::LeftButton)
105 QPoint windowPos(releaseEvent->event_x, releaseEvent->event_y);
107 QWindow *targetWindow = findQWindowWithXWindowID(static_cast<WId>(releaseEvent->event));
109 QTouchEventSequence touchEvent = QTest::touchEvent(targetWindow, m_touchDevice,
110 false /* autoCommit */);
111 touchEvent.release(0 /* touchId */, windowPos);
112 touchEvent.commit(false /* processEvents */);
114 m_leftButtonIsPressed = false;
118bool MouseTouchAdaptor::handleMotionNotify(xcb_motion_notify_event_t *event)
120 if (!m_leftButtonIsPressed) {
124 QPoint windowPos(event->event_x, event->event_y);
126 QWindow *targetWindow = findQWindowWithXWindowID(static_cast<WId>(event->event));
128 QTouchEventSequence touchEvent = QTest::touchEvent(targetWindow, m_touchDevice,
129 false /* autoCommit */);
130 touchEvent.move(0 /* touchId */, windowPos);
131 touchEvent.commit(false /* processEvents */);
136QWindow *MouseTouchAdaptor::findQWindowWithXWindowID(WId windowId)
138 QWindowList windowList = QGuiApplication::topLevelWindows();
139 QWindow *foundWindow = nullptr;
142 while (!foundWindow && i < windowList.count()) {
143 QWindow *window = windowList[i];
144 if (window->winId() == windowId) {
145 foundWindow = window;
151 Q_ASSERT(foundWindow);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list