summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Poulain <benjamin.poulain@nokia.com>2009-08-31 17:19:04 (GMT)
committerBenjamin Poulain <benjamin.poulain@nokia.com>2009-08-31 19:03:43 (GMT)
commita2b2fbbbffa4fa04f47cd8b9e6265e2e61c5e5f3 (patch)
treeb8390e8590219b9dd008fe0b0fadedaf8a0be583
parent258b9c5d5b1d88a5c19ed1dcfb5fed446006de0d (diff)
downloadQt-a2b2fbbbffa4fa04f47cd8b9e6265e2e61c5e5f3.zip
Qt-a2b2fbbbffa4fa04f47cd8b9e6265e2e61c5e5f3.tar.gz
Qt-a2b2fbbbffa4fa04f47cd8b9e6265e2e61c5e5f3.tar.bz2
Disable event compression when the tablet events are accepted
Since Qt 4.5, all tablet events are compressed not to overload the widgets with the corresponding mouse event (a mouse event is generated if the tablet event is not accepted). This behavior reduce the precision when drawing on a widget that use the tablet events. All tablet events should be sent to the widget that are accepting the tablet event. With this patch, the tablet event are filtered only if the widget ignore the first tablet event. The mouse events are compressed. There is two special cases for the filtering: First, if a tablet event is for another widget than the one ignoring the tablet, this event should not be filtered. Second, if there is a mouse press event, the mouse move event should be sent to the widget that received the mouse press event. Helped-by: Pierre Rossi Reviewed-by: Thomas Zander Reviewed-by: Bradley T. Hughes
-rw-r--r--src/gui/kernel/qapplication_x11.cpp111
-rw-r--r--tests/manual/qtabletevent/device_information/main.cpp50
-rw-r--r--tests/manual/qtabletevent/device_information/qtabletevent.pro (renamed from tests/manual/qtabletevent/qtabletevent.pro)0
-rw-r--r--tests/manual/qtabletevent/device_information/tabletwidget.cpp (renamed from tests/manual/qtabletevent/tabletwidget.cpp)0
-rw-r--r--tests/manual/qtabletevent/device_information/tabletwidget.h (renamed from tests/manual/qtabletevent/tabletwidget.h)26
-rw-r--r--tests/manual/qtabletevent/event_compression/event_compression.pro7
-rw-r--r--tests/manual/qtabletevent/event_compression/main.cpp58
-rw-r--r--tests/manual/qtabletevent/event_compression/mousestatwidget.cpp99
-rw-r--r--tests/manual/qtabletevent/event_compression/mousestatwidget.h (renamed from tests/manual/qtabletevent/main.cpp)35
9 files changed, 312 insertions, 74 deletions
diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp
index 69dba40..0056b9e 100644
--- a/src/gui/kernel/qapplication_x11.cpp
+++ b/src/gui/kernel/qapplication_x11.cpp
@@ -4510,7 +4510,9 @@ void fetchWacomToolId(int &deviceType, qint64 &serialId)
struct qt_tablet_motion_data
{
- Time timestamp;
+ bool filterByWidget;
+ const QWidget *widget;
+ const QWidget *etWidget;
int tabletMotionType;
bool error; // found a reason to stop searching
};
@@ -4533,15 +4535,20 @@ static Bool qt_tabletMotion_scanner(Display *, XEvent *event, XPointer arg)
qt_tablet_motion_data *data = (qt_tablet_motion_data *) arg;
if (data->error)
return false;
-
if (event->type == data->tabletMotionType) {
- if (data->timestamp > 0) {
- if ((reinterpret_cast<const XDeviceMotionEvent*>(event))->time > data->timestamp) {
- data->error = true;
- return false;
+ const XDeviceMotionEvent *const motion = reinterpret_cast<const XDeviceMotionEvent*>(event);
+ if (data->filterByWidget) {
+ const QPoint curr(motion->x, motion->y);
+ const QWidget *w = data->etWidget;
+ const QWidget *const child = w->childAt(curr);
+ if (child) {
+ w = child;
}
+ if (w == data->widget)
+ return true;
+ } else {
+ return true;
}
- return true;
}
data->error = event->type != MotionNotify; // we stop compression when another event gets in between.
@@ -4574,57 +4581,17 @@ bool QETWidget::translateXinputEvent(const XEvent *ev, QTabletDeviceData *tablet
qreal rotation = 0;
int deviceType = QTabletEvent::NoDevice;
int pointerType = QTabletEvent::UnknownPointer;
- XEvent mouseMotionEvent;
- XEvent dummy;
const XDeviceMotionEvent *motion = 0;
XDeviceButtonEvent *button = 0;
const XProximityNotifyEvent *proximity = 0;
QEvent::Type t;
Qt::KeyboardModifiers modifiers = 0;
- bool reinsertMouseEvent = false;
- XEvent mouseMotionEventSave;
#if !defined (Q_OS_IRIX)
XID device_id;
#endif
if (ev->type == tablet->xinput_motion) {
motion = reinterpret_cast<const XDeviceMotionEvent*>(ev);
-
- // Do event compression. Skip over tablet+mouse move events if there are newer ones.
- qt_tablet_motion_data tabletMotionData;
- tabletMotionData.tabletMotionType = tablet->xinput_motion;
- while (true) {
- // Find first mouse event since we expect them in pairs inside Qt
- tabletMotionData.error =false;
- tabletMotionData.timestamp = 0;
- if (XCheckIfEvent(X11->display, &mouseMotionEvent, &qt_mouseMotion_scanner, (XPointer) &tabletMotionData)) {
- mouseMotionEventSave = mouseMotionEvent;
- reinsertMouseEvent = true;
- } else {
- break;
- }
-
- // Now discard any duplicate tablet events.
- tabletMotionData.error = false;
- tabletMotionData.timestamp = mouseMotionEvent.xmotion.time;
- while (XCheckIfEvent(X11->display, &dummy, &qt_tabletMotion_scanner, (XPointer) &tabletMotionData)) {
- motion = reinterpret_cast<const XDeviceMotionEvent*>(&dummy);
- }
-
- // now check if there are more recent tablet motion events since we'll compress the current one with
- // newer ones in that case
- tabletMotionData.error = false;
- tabletMotionData.timestamp = 0;
- if (! XCheckIfEvent(X11->display, &dummy, &qt_tabletMotion_scanner, (XPointer) &tabletMotionData)) {
- break; // done with compression
- }
- motion = reinterpret_cast<const XDeviceMotionEvent*>(&dummy);
- }
-
- if (reinsertMouseEvent) {
- XPutBackEvent(X11->display, &mouseMotionEventSave);
- }
-
t = QEvent::TabletMove;
global = QPoint(motion->x_root, motion->y_root);
curr = QPoint(motion->x, motion->y);
@@ -4777,11 +4744,14 @@ bool QETWidget::translateXinputEvent(const XEvent *ev, QTabletDeviceData *tablet
}
#endif
- QWidget *child = w->childAt(curr);
- if (child) {
- w = child;
- curr = w->mapFromGlobal(global);
+ if (tablet->widgetToGetPress) {
+ w = tablet->widgetToGetPress;
+ } else {
+ QWidget *child = w->childAt(curr);
+ if (child)
+ w = child;
}
+ curr = w->mapFromGlobal(global);
if (t == QEvent::TabletPress) {
tablet->widgetToGetPress = w;
@@ -4795,10 +4765,45 @@ bool QETWidget::translateXinputEvent(const XEvent *ev, QTabletDeviceData *tablet
deviceType, pointerType,
qreal(pressure / qreal(tablet->maxPressure - tablet->minPressure)),
xTilt, yTilt, tangentialPressure, rotation, z, modifiers, uid);
- if (proximity)
+ if (proximity) {
QApplication::sendSpontaneousEvent(qApp, &e);
- else
+ } else {
QApplication::sendSpontaneousEvent(w, &e);
+ const bool accepted = e.isAccepted();
+ if (!accepted && ev->type == tablet->xinput_motion) {
+ // If the widget does not accept tablet events, we drop the next ones from the event queue
+ // for this widget so it is not overloaded with the numerous tablet events.
+ qt_tablet_motion_data tabletMotionData;
+ tabletMotionData.tabletMotionType = tablet->xinput_motion;
+ tabletMotionData.widget = w;
+ tabletMotionData.etWidget = this;
+ // if nothing is pressed, the events are filtered by position
+ tabletMotionData.filterByWidget = (tablet->widgetToGetPress == 0);
+
+ bool reinsertMouseEvent = false;
+ XEvent mouseMotionEvent;
+ while (true) {
+ // Find first mouse event since we expect them in pairs inside Qt
+ tabletMotionData.error =false;
+ if (XCheckIfEvent(X11->display, &mouseMotionEvent, &qt_mouseMotion_scanner, (XPointer) &tabletMotionData)) {
+ reinsertMouseEvent = true;
+ } else {
+ break;
+ }
+
+ // Now discard any duplicate tablet events.
+ tabletMotionData.error = false;
+ XEvent dummy;
+ while (XCheckIfEvent(X11->display, &dummy, &qt_tabletMotion_scanner, (XPointer) &tabletMotionData)) {
+ // just discard the event
+ }
+ }
+
+ if (reinsertMouseEvent) {
+ XPutBackEvent(X11->display, &mouseMotionEvent);
+ }
+ }
+ }
return true;
}
#endif
diff --git a/tests/manual/qtabletevent/device_information/main.cpp b/tests/manual/qtabletevent/device_information/main.cpp
new file mode 100644
index 0000000..0c2eda3
--- /dev/null
+++ b/tests/manual/qtabletevent/device_information/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "tabletwidget.h"
+
+int main(int argc, char **argv) {
+ QApplication app(argc, argv);
+ TabletWidget tabletWidget;
+ tabletWidget.showMaximized();
+ return app.exec();
+}
diff --git a/tests/manual/qtabletevent/qtabletevent.pro b/tests/manual/qtabletevent/device_information/qtabletevent.pro
index e0ed549..e0ed549 100644
--- a/tests/manual/qtabletevent/qtabletevent.pro
+++ b/tests/manual/qtabletevent/device_information/qtabletevent.pro
diff --git a/tests/manual/qtabletevent/tabletwidget.cpp b/tests/manual/qtabletevent/device_information/tabletwidget.cpp
index 15a3d80..15a3d80 100644
--- a/tests/manual/qtabletevent/tabletwidget.cpp
+++ b/tests/manual/qtabletevent/device_information/tabletwidget.cpp
diff --git a/tests/manual/qtabletevent/tabletwidget.h b/tests/manual/qtabletevent/device_information/tabletwidget.h
index d3ccb32..b16e9ed 100644
--- a/tests/manual/qtabletevent/tabletwidget.h
+++ b/tests/manual/qtabletevent/device_information/tabletwidget.h
@@ -9,8 +9,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -21,20 +21,20 @@
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
diff --git a/tests/manual/qtabletevent/event_compression/event_compression.pro b/tests/manual/qtabletevent/event_compression/event_compression.pro
new file mode 100644
index 0000000..273fd6c
--- /dev/null
+++ b/tests/manual/qtabletevent/event_compression/event_compression.pro
@@ -0,0 +1,7 @@
+TEMPLATE = app
+QT += testlib
+
+# Input
+SOURCES += main.cpp \
+ mousestatwidget.cpp
+HEADERS += mousestatwidget.h
diff --git a/tests/manual/qtabletevent/event_compression/main.cpp b/tests/manual/qtabletevent/event_compression/main.cpp
new file mode 100644
index 0000000..3b869e3
--- /dev/null
+++ b/tests/manual/qtabletevent/event_compression/main.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mousestatwidget.h"
+
+#include <QApplication>
+#include <QWidget>
+#include <QVBoxLayout>
+
+int main(int argc, char **argv){
+ QApplication app(argc, argv);
+
+ QWidget main;
+ QVBoxLayout *layout = new QVBoxLayout(&main);
+ layout->addWidget(new MouseStatWidget(true));
+ layout->addWidget(new MouseStatWidget(false));
+ main.resize(800, 600);
+ main.show();
+ return app.exec();
+}
diff --git a/tests/manual/qtabletevent/event_compression/mousestatwidget.cpp b/tests/manual/qtabletevent/event_compression/mousestatwidget.cpp
new file mode 100644
index 0000000..024e14a
--- /dev/null
+++ b/tests/manual/qtabletevent/event_compression/mousestatwidget.cpp
@@ -0,0 +1,99 @@
+#include "mousestatwidget.h"
+
+#include <QTabletEvent>
+#include <QPainter>
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QTextOption>
+#include <QTest>
+
+MouseStatWidget::MouseStatWidget(bool acceptTabletEvent):acceptTabletEvent(acceptTabletEvent),
+ receivedMouseEventCount(0),
+ receivedMouseEventCountToPaint(0),
+ receivedTabletEventCount(0),
+ receivedTabletEventCountToPaint(0)
+{
+ startTimer(1000);
+}
+
+
+void MouseStatWidget::tabletEvent(QTabletEvent *event)
+{
+ ++receivedTabletEventCount;
+ if (acceptTabletEvent)
+ event->accept();
+ else
+ event->ignore();
+ // make sure the event loop is slow
+ QTest::qSleep(15);
+}
+
+void MouseStatWidget::mouseMoveEvent(QMouseEvent *)
+{
+ ++receivedMouseEventCount;
+}
+
+void MouseStatWidget::timerEvent(QTimerEvent *)
+{
+ receivedMouseEventCountToPaint = receivedMouseEventCount;
+ receivedTabletEventCountToPaint = receivedTabletEventCount;
+ receivedMouseEventCount = 0;
+ receivedTabletEventCount = 0;
+ update();
+}
+
+void MouseStatWidget::paintEvent(QPaintEvent *)
+{
+ QPainter painter(this);
+ painter.setPen(Qt::black);
+ painter.drawRect(rect());
+ QStringList text;
+ text << ((acceptTabletEvent) ? " - tablet events accepted - " : " - tablet events ignored - ");
+ text << QString("Number of tablet events received in the last second: %1").arg(QString::number(receivedTabletEventCountToPaint));
+ text << QString("Number of mouse events received in the last second: %1").arg(QString::number(receivedMouseEventCountToPaint));
+
+ QTextOption textOption(Qt::AlignCenter);
+ textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
+ painter.drawText(rect(),
+ text.join("\n"),
+ textOption);
+}
diff --git a/tests/manual/qtabletevent/main.cpp b/tests/manual/qtabletevent/event_compression/mousestatwidget.h
index 44afcaf..22c0dff 100644
--- a/tests/manual/qtabletevent/main.cpp
+++ b/tests/manual/qtabletevent/event_compression/mousestatwidget.h
@@ -39,12 +39,31 @@
**
****************************************************************************/
-#include <QtGui>
-#include "tabletwidget.h"
+#ifndef MOUSESTATWIDGET_H
+#define MOUSESTATWIDGET_H
-int main(int argc, char **argv) {
- QApplication app(argc, argv);
- TabletWidget tabletWidget;
- tabletWidget.showMaximized();
- return app.exec();
-}
+#include <QWidget>
+
+class QTabletEvent;
+class QMouseEvent;
+class QTimerEvent;
+class QPaintEvent;
+
+class MouseStatWidget : public QWidget
+{
+public:
+ MouseStatWidget(bool acceptTabletEvent = true);
+protected:
+ void tabletEvent(QTabletEvent *);
+ void mouseMoveEvent(QMouseEvent *);
+ void timerEvent(QTimerEvent *);
+ void paintEvent(QPaintEvent *);
+private:
+ const bool acceptTabletEvent;
+ int receivedMouseEventCount;
+ int receivedMouseEventCountToPaint;
+ int receivedTabletEventCount;
+ int receivedTabletEventCountToPaint;
+};
+
+#endif // MOUSESTATWIDGET_H