on master help sign in
unity8/src/MouseTouchAdaptor.h
72 lines 2.2 kB history raw
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 */
19#ifndef MOUSE_TOUCH_ADAPTOR_H
20#define MOUSE_TOUCH_ADAPTOR_H
22#include <QtCore/QAbstractNativeEventFilter>
23#include <QWindow>
25#include <xcb/xcb.h>
27class QMouseEvent;
28class QTouchDevice;
30// Transforms QMouseEvents into single-finger QTouchEvents.
31class MouseTouchAdaptor : public QObject, public QAbstractNativeEventFilter {
32 Q_OBJECT
33public:
34 virtual ~MouseTouchAdaptor();
36 static MouseTouchAdaptor* instance();
38 // Filters mouse events and posts the equivalent QTouchEvents.
39 bool nativeEventFilter(const QByteArray & eventType, void *message, long *result) override;
41 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
43 bool enabled() const;
44 void setEnabled(bool value);
46Q_SIGNALS:
47 void enabledChanged(bool value);
49private:
50 MouseTouchAdaptor();
51 void fetchXInput2Info();
52 bool xi2HandleEvent(xcb_ge_event_t *event);
54 bool handleButtonPress(WId windowId, uint32_t detail, uint32_t modifiers, int x, int y);
55 bool handleButtonRelease(WId windowId, uint32_t detail, uint32_t modifiers, int x, int y);
56 bool handleMotionNotify(WId windowId, uint32_t modifiers, int x, int y);
57 QWindow *findQWindowWithXWindowID(WId windowId);
59 QTouchDevice *m_touchDevice;
60 bool m_leftButtonIsPressed;
61 bool m_triPressModifier;
62 bool m_quadPressModifier;
65 bool m_enabled;
67 bool m_xi2Enabled{false};
68 int m_xi2Minor{-1};
69 int m_xiOpCode, m_xiEventBase, m_xiErrorBase;
70};
72#endif // MOUSE_TOUCH_ADAPTOR_H