diff options
author | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2011-07-19 15:34:21 +0300 |
---|---|---|
committer | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2011-07-19 15:34:21 +0300 |
commit | 42ae9a55f099765345d280f35405fd2c36123662 (patch) | |
tree | 038c344ac97ff6ec8c4d60d22fba1bca5719a322 /examples/qwidget-compositor | |
parent | 33788d5c45cec4de2f2cd378ce8b12e62319d133 (diff) | |
parent | 36733fe04853fbe092e8ae9bfb94daf8b015e986 (diff) |
Merge branch 'master' into refactor
Conflicts:
examples/qwidget-compositor-mdi/main.cpp
src/qt-compositor/hardware_integration/mesa_egl/mesaeglintegration.cpp
src/qt-compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.cpp
src/qt-compositor/qt-compositor.pri
src/qt-compositor/wayland_wrapper/wlsurface.h
Diffstat (limited to 'examples/qwidget-compositor')
-rw-r--r-- | examples/qwidget-compositor/main.cpp | 69 | ||||
-rw-r--r-- | examples/qwidget-compositor/qt-compositor.pro | 12 |
2 files changed, 80 insertions, 1 deletions
diff --git a/examples/qwidget-compositor/main.cpp b/examples/qwidget-compositor/main.cpp index c0410d207..9cd500676 100644 --- a/examples/qwidget-compositor/main.cpp +++ b/examples/qwidget-compositor/main.cpp @@ -55,6 +55,24 @@ #include <QDebug> +#include "qtouchscreen.h" + +static int touch_x_min, touch_x_max, touch_y_min, touch_y_max; + +class QWidgetCompositor; + +class TouchObserver : public QTouchScreenObserver +{ +public: + TouchObserver(QWidgetCompositor *compositor) + : m_compositor(compositor) { } + void touch_configure(int x_min, int x_max, int y_min, int y_max); + void touch_point(QEvent::Type state, const QList<QWindowSystemInterface::TouchPoint> &points); + +private: + QWidgetCompositor *m_compositor; +}; + #ifdef QT_COMPOSITOR_WAYLAND_GL class QWidgetCompositor : public QGLWidget, public WaylandCompositor #else @@ -235,8 +253,56 @@ private: WaylandSurface *m_dragSurface; QPoint m_dragOffset; + + friend class TouchObserver; }; +void TouchObserver::touch_configure(int x_min, int x_max, int y_min, int y_max) +{ + touch_x_min = x_min; + touch_x_max = x_max; + touch_y_min = y_min; + touch_y_max = y_max; +} + +void TouchObserver::touch_point(QEvent::Type state, const QList<QWindowSystemInterface::TouchPoint> &points) +{ + Q_UNUSED(state); + WaylandSurface *focusSurface = m_compositor->inputFocus(); + if (focusSurface) { + if (points.isEmpty()) + return; + for (int i = 0; i < points.count(); ++i) { + const QWindowSystemInterface::TouchPoint &point(points.at(i)); + + // These are hw coordinates. + int x = int(point.area.left()); + int y = int(point.area.top()); + + // Wayland expects surface-relative coordinates. + + // Translate so that (0, 0) is the top-left corner. + x = qBound(touch_x_min, x, touch_x_max) - touch_x_min; + y = qBound(touch_y_min, y, touch_y_max) - touch_y_min; + + // Get a normalized position in range 0..1. + const int hw_w = touch_x_max - touch_x_min; + const int hw_h = touch_y_max - touch_y_min; + const qreal nx = x / qreal(hw_w); + const qreal ny = y / qreal(hw_h); + + // Map to surface. + QRect winRect(focusSurface->geometry()); + x = int(nx * winRect.width()); + y = int(ny * winRect.height()); + + focusSurface->sendTouchPointEvent(point.id, + x, y, + point.state); + } + focusSurface->sendTouchFrameEvent(); + } +} int main(int argc, char *argv[]) { @@ -246,8 +312,9 @@ int main(int argc, char *argv[]) compositor.resize(800, 600); compositor.show(); - return app.exec(); + QTouchScreenHandlerThread t(QString(), new TouchObserver(&compositor)); + return app.exec(); } #include "main.moc" diff --git a/examples/qwidget-compositor/qt-compositor.pro b/examples/qwidget-compositor/qt-compositor.pro index b7211b776..69c3c429a 100644 --- a/examples/qwidget-compositor/qt-compositor.pro +++ b/examples/qwidget-compositor/qt-compositor.pro @@ -20,3 +20,15 @@ SOURCES += main.cpp CONFIG += qt warn_on debug create_prl link_prl OBJECTS_DIR = .obj/release-shared MOC_DIR = .moc/release-shared + +# Touch support +isEmpty(QT_SOURCE_TREE) { + QTBASE = $$[QT_INSTALL_DATA] +} else { + QTBASE = $$QT_SOURCE_TREE +} +TOUCHSCREEN_BASE = $$QTBASE/src/plugins/generic/touchscreen +SOURCES += $$TOUCHSCREEN_BASE/qtouchscreen.cpp +HEADERS += $$TOUCHSCREEN_BASE/qtouchscreen.h +INCLUDEPATH += $$TOUCHSCREEN_BASE +LIBS += -ludev -lmtdev |