source: trunk/src/gui/embedded/qmouselinuxtp_qws.cpp@ 784

Last change on this file since 784 was 651, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.2 sources.

  • Property svn:eol-style set to native
File size: 9.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qmouselinuxtp_qws.h"
43
44#ifndef QT_NO_QWS_MOUSE_LINUXTP
45#include "qwindowsystem_qws.h"
46#include "qsocketnotifier.h"
47#include "qtimer.h"
48#include "qapplication.h"
49#include "qscreen_qws.h"
50#include <private/qcore_unix_p.h> // overrides QT_OPEN
51
52#include <unistd.h>
53#include <stdlib.h>
54#include <stdio.h>
55#include <sys/ioctl.h>
56#include <sys/types.h>
57#include <sys/stat.h>
58#include <fcntl.h>
59#include <errno.h>
60#include <termios.h>
61
62QT_BEGIN_NAMESPACE
63
64#if defined(QT_QWS_IPAQ)
65 #define QT_QWS_IPAQ_RAW
66 #define QT_QWS_SCREEN_COORDINATES
67 typedef struct {
68 unsigned short pressure;
69 unsigned short x;
70 unsigned short y;
71 unsigned short pad;
72 } TS_EVENT;
73#elif defined(QT_QWS_EBX)
74 #define QT_QWS_EBX_RAW
75 #define QT_QWS_SCREEN_COORDINATES
76#ifndef QT_QWS_SHARP
77 typedef struct {
78 unsigned short pressure;
79 unsigned short x;
80 unsigned short y;
81 unsigned short pad;
82 } TS_EVENT;
83 #else
84 typedef struct {
85 long y;
86 long x;
87 long pressure;
88 long long millisecs;
89 } TS_EVENT;
90 #define QT_QWS_TP_SAMPLE_SIZE 10
91 #define QT_QWS_TP_MINIMUM_SAMPLES 4
92 #define QT_QWS_TP_PRESSURE_THRESHOLD 500
93 #define QT_QWS_TP_MOVE_LIMIT 50
94 #define QT_QWS_TP_JITTER_LIMIT 2
95 #endif
96#else // not IPAQ, not SHARP
97 typedef struct {
98 unsigned short pressure;
99 unsigned short x;
100 unsigned short y;
101 unsigned short pad;
102 } TS_EVENT;
103#endif
104
105#ifndef QT_QWS_TP_SAMPLE_SIZE
106#define QT_QWS_TP_SAMPLE_SIZE 5
107#endif
108
109#ifndef QT_QWS_TP_MINIMUM_SAMPLES
110#define QT_QWS_TP_MINIMUM_SAMPLES 5
111#endif
112
113#ifndef QT_QWS_TP_PRESSURE_THRESHOLD
114#define QT_QWS_TP_PRESSURE_THRESHOLD 1
115#endif
116
117#ifndef QT_QWS_TP_MOVE_LIMIT
118#define QT_QWS_TP_MOVE_LIMIT 100
119#endif
120
121#ifndef QT_QWS_TP_JITTER_LIMIT
122#define QT_QWS_TP_JITTER_LIMIT 2
123#endif
124
125class QWSLinuxTPMouseHandlerPrivate : public QObject
126{
127 Q_OBJECT
128public:
129 QWSLinuxTPMouseHandlerPrivate(QWSLinuxTPMouseHandler *h, const QString &);
130 ~QWSLinuxTPMouseHandlerPrivate();
131
132 void suspend();
133 void resume();
134private:
135 static const int mouseBufSize = 2048;
136 int mouseFD;
137 QPoint oldmouse;
138 QPoint oldTotalMousePos;
139 bool waspressed;
140 QPolygon samples;
141 int currSample;
142 int lastSample;
143 int numSamples;
144 int skipCount;
145 int mouseIdx;
146 uchar mouseBuf[mouseBufSize];
147 QWSLinuxTPMouseHandler *handler;
148 QSocketNotifier *mouseNotifier;
149
150private slots:
151 void readMouseData();
152};
153
154QWSLinuxTPMouseHandler::QWSLinuxTPMouseHandler(const QString &driver, const QString &device)
155 : QWSCalibratedMouseHandler(driver, device)
156{
157 d = new QWSLinuxTPMouseHandlerPrivate(this, device);
158}
159
160QWSLinuxTPMouseHandler::~QWSLinuxTPMouseHandler()
161{
162 delete d;
163}
164
165void QWSLinuxTPMouseHandler::suspend()
166{
167 d->suspend();
168}
169
170void QWSLinuxTPMouseHandler::resume()
171{
172 d->resume();
173}
174
175QWSLinuxTPMouseHandlerPrivate::QWSLinuxTPMouseHandlerPrivate(QWSLinuxTPMouseHandler *h,
176 const QString &device)
177 : samples(QT_QWS_TP_SAMPLE_SIZE), currSample(0), lastSample(0),
178 numSamples(0), skipCount(0), handler(h)
179{
180 QString mousedev;
181 if (device.isEmpty()) {
182#if defined(QT_QWS_IPAQ)
183# ifdef QT_QWS_IPAQ_RAW
184 mousedev = QLatin1String("/dev/h3600_tsraw");
185# else
186 mousedev = QLatin1String("/dev/h3600_ts");
187# endif