Lomiri
Loading...
Searching...
No Matches
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
25#include <xcb/xcb.h>
26
27class QMouseEvent;
28class QTouchDevice;
29
30// Transforms QMouseEvents into single-finger QTouchEvents.
31class MouseTouchAdaptor : public QObject, public QAbstractNativeEventFilter {
32 Q_OBJECT
33public:
34 virtual ~MouseTouchAdaptor();
35
36 static MouseTouchAdaptor* instance();
37
38 // Filters mouse events and posts the equivalent QTouchEvents.
39 bool nativeEventFilter(const QByteArray & eventType, void *message, long *result) override;
40
41 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
42
43 bool enabled() const;
44 void setEnabled(bool value);
45
46Q_SIGNALS:
47 void enabledChanged(bool value);
48
49private:
50 MouseTouchAdaptor();
51 void fetchXInput2Info();
52 bool xi2HandleEvent(xcb_ge_event_t *event);
53
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);
58
59 QTouchDevice *m_touchDevice;
60 bool m_leftButtonIsPressed;
61 bool m_triPressModifier;
62 bool m_quadPressModifier;
63
64
65 bool m_enabled;
66
67 bool m_xi2Enabled{false};
68 int m_xi2Minor{-1};
69 int m_xiOpCode, m_xiEventBase, m_xiErrorBase;
70};
71
72#endif // MOUSE_TOUCH_ADAPTOR_H