Unity 8
MouseTouchAdaptor.h
1 /*
2  * Copyright (C) 2013 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  * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
17  */
18 
19 #ifndef MOUSE_TOUCH_ADAPTOR_H
20 #define MOUSE_TOUCH_ADAPTOR_H
21 
22 #include <QtCore/QAbstractNativeEventFilter>
23 #include <QWindow>
24 #include <xcb/xcb.h>
25 
26 class QMouseEvent;
27 class QTouchDevice;
28 
29 // Transforms QMouseEvents into single-finger QTouchEvents.
30 class MouseTouchAdaptor : public QAbstractNativeEventFilter {
31 
32 public:
33  MouseTouchAdaptor();
34 
35  // Filters mouse events and posts the equivalent QTouchEvents.
36  virtual bool nativeEventFilter(const QByteArray & eventType, void *message, long *result);
37 
38 private:
39 
40  bool handleButtonPress(xcb_button_press_event_t *pressEvent);
41  bool handleButtonRelease(xcb_button_release_event_t *releaseEvent);
42  bool handleMotionNotify(xcb_motion_notify_event_t *event);
43  QWindow *findQWindowWithXWindowID(WId windowId);
44 
45  QTouchDevice *m_touchDevice;
46  bool m_leftButtonIsPressed;
47 };
48 
49 #endif // MOUSE_TOUCH_ADAPTOR_H