Unity 8
MouseTouchAdaptor.h
1 /*
2  * Copyright (C) 2013,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  * 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 QObject, public QAbstractNativeEventFilter {
31  Q_OBJECT
32 public:
33  virtual ~MouseTouchAdaptor();
34 
35  static MouseTouchAdaptor* instance();
36 
37  // Filters mouse events and posts the equivalent QTouchEvents.
38  bool nativeEventFilter(const QByteArray & eventType, void *message, long *result) override;
39 
40  Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
41 
42  bool enabled() const;
43  void setEnabled(bool value);
44 
45 Q_SIGNALS:
46  void enabledChanged(bool value);
47 
48 private:
49  MouseTouchAdaptor();
50 
51  bool handleButtonPress(xcb_button_press_event_t *pressEvent);
52  bool handleButtonRelease(xcb_button_release_event_t *releaseEvent);
53  bool handleMotionNotify(xcb_motion_notify_event_t *event);
54  QWindow *findQWindowWithXWindowID(WId windowId);
55 
56  QTouchDevice *m_touchDevice;
57  bool m_leftButtonIsPressed;
58 
59  bool m_enabled;
60 };
61 
62 #endif // MOUSE_TOUCH_ADAPTOR_H