on bbce293 help sign in
unity8/src/MouseTouchAdaptor.h
62 lines 1.9 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>
24#include <xcb/xcb.h>
26class QMouseEvent;
27class QTouchDevice;
29// Transforms QMouseEvents into single-finger QTouchEvents.
30class MouseTouchAdaptor : public QObject, public QAbstractNativeEventFilter {
31 Q_OBJECT
32public:
33 virtual ~MouseTouchAdaptor();
35 static MouseTouchAdaptor* instance();
37 // Filters mouse events and posts the equivalent QTouchEvents.
38 bool nativeEventFilter(const QByteArray & eventType, void *message, long *result) override;
40 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
42 bool enabled() const;
43 void setEnabled(bool value);
45Q_SIGNALS:
46 void enabledChanged(bool value);
48private:
49 MouseTouchAdaptor();
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);
56 QTouchDevice *m_touchDevice;
57 bool m_leftButtonIsPressed;
59 bool m_enabled;
60};
62#endif // MOUSE_TOUCH_ADAPTOR_H