1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 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 "qmouse_qws.h"
|
---|
43 | #include "qwindowsystem_qws.h"
|
---|
44 | #include "qscreen_qws.h"
|
---|
45 | #include "qapplication.h"
|
---|
46 | #include "qtextstream.h"
|
---|
47 | #include "qfile.h"
|
---|
48 | #include "qdebug.h"
|
---|
49 | #include "qscreen_qws.h"
|
---|
50 |
|
---|
51 | QT_BEGIN_NAMESPACE
|
---|
52 |
|
---|
53 | /*!
|
---|
54 | \class QWSPointerCalibrationData
|
---|
55 | \ingroup qws
|
---|
56 |
|
---|
57 | \brief The QWSPointerCalibrationData class is a container for
|
---|
58 | mouse calibration data in Qt for Embedded Linux.
|
---|
59 |
|
---|
60 | Note that this class is only available in \l{Qt for Embedded Linux}.
|
---|
61 |
|
---|
62 | QWSPointerCalibrationData stores device and screen coordinates in
|
---|
63 | the devPoints and screenPoints variables, respectively.
|
---|
64 |
|
---|
65 | A calibration program should create a QWSPointerCalibrationData
|
---|
66 | object, fill the devPoints and screenPoints variables with its
|
---|
67 | device and screen coordinates, and pass the object to the mouse
|
---|
68 | driver using the QWSMouseHandler::calibrate() function.
|
---|
69 |
|
---|
70 | \sa QWSCalibratedMouseHandler, {Mouse Calibration Example}
|
---|
71 | */
|
---|
72 |
|
---|
73 | /*!
|
---|
74 | \variable QWSPointerCalibrationData::devPoints
|
---|
75 | \brief the raw device coordinates for each value of the Location enum.
|
---|
76 | */
|
---|
77 |
|
---|
78 | /*!
|
---|
79 | \variable QWSPointerCalibrationData::screenPoints
|
---|
80 | \brief the logical screen coordinates for each value of the Location enum.
|
---|
81 | */
|
---|
82 |
|
---|
83 | /*!
|
---|
84 | \enum QWSPointerCalibrationData::Location
|
---|
85 |
|
---|
86 | This enum describes the various logical positions that can be
|
---|
87 | specified by the devPoints and screenPoints variables.
|
---|
88 |
|
---|
89 | \value TopLeft Index of the top left corner of the screen.
|
---|
90 | \value BottomLeft Index of the bottom left corner of the screen.
|
---|
91 | \value BottomRight Index of the bottom right corner of the screen.
|
---|
92 | \value TopRight Index of the top right corner of the screen.
|
---|
93 | \value Center Index of the center of the screen.
|
---|
94 | \value LastLocation Last index in the pointer arrays.
|
---|
95 | */
|
---|
96 |
|
---|
97 | class QWSMouseHandlerPrivate
|
---|
98 | {
|
---|
99 | public:
|
---|
100 | QWSMouseHandlerPrivate() : screen(qt_screen) {}
|
---|
101 |
|
---|
102 | const QScreen *screen;
|
---|
103 | };
|
---|
104 |
|
---|
105 | /*!
|
---|
106 | \class QWSMouseHandler
|
---|
107 | \ingroup qws
|
---|
108 |
|
---|
109 | \brief The QWSMouseHandler class is a base class for mouse drivers in
|
---|
110 | Qt for Embedded Linux.
|
---|
111 |
|
---|
112 | Note that this class is only available in \l{Qt for Embedded Linux}.
|
---|
113 |
|
---|
114 | \l{Qt for Embedded Linux} provides ready-made drivers for several mouse
|
---|
115 | protocols, see the \l{Qt for Embedded Linux Pointer Handling}{pointer
|
---|
116 | handling} documentation for details. Custom mouse drivers can be
|
---|
117 | implemented by subclassing the QWSMouseHandler class and creating
|
---|
118 | a mouse driver plugin (derived from QMouseDriverPlugin).
|
---|
119 | The default implementation of the QMouseDriverFactory class
|
---|
120 | will automatically detect the plugin, and load the driver into the
|
---|
121 | server application at run-time using Qt's \l {How to Create Qt
|
---|
122 | Plugins}{plugin system}.
|
---|
123 |
|
---|
124 | The mouse driver receives mouse events from the system device and
|
---|
125 | encapsulates each event with an instance of the QWSEvent class
|
---|
126 | which it then passes to the server application (the server is
|
---|
127 | responsible for propagating the event to the appropriate
|
---|
128 | client). To receive mouse events, a QWSMouseHandler object will
|
---|
129 | usually create a QSocketNotifier object for the given device. The
|
---|
130 | QSocketNotifier class provides support for monitoring activity on
|
---|
131 | a file descriptor. When the socket notifier receives data, it will
|
---|
132 | call the mouse driver's mouseChanged() function to send the event
|
---|
133 | to the \l{Qt for Embedded Linux} server application for relaying to
|
---|
134 | clients.
|
---|
135 |
|
---|
136 | If you are creating a driver for a device that needs calibration
|
---|
137 | or noise reduction, such as a touchscreen, use the
|
---|
138 | QWSCalibratedMouseHandler subclass instead to take advantage of
|
---|
139 | the calibrate() and clearCalibration() functions. The \l
|
---|
140 | {qws/mousecalibration}{Mouse Calibration}
|
---|
141 | demonstrates how to write a simple program using the mechanisms
|
---|
142 | provided by the QWSMouseHandler class to calibrate a mouse driver.
|
---|
143 |
|
---|
144 | Note that when deriving from the QWSMouseHandler class, the
|
---|
145 | resume() and suspend() functions must be reimplemented to control
|
---|
146 | the flow of mouse input, i.e., the default implementation does
|
---|
147 | nothing. Reimplementations of these functions typically call the
|
---|
148 | QSocketNotifier::setEnabled() function to enable or disable the
|
---|
149 | socket notifier, respectively.
|
---|
150 |
|
---|
151 | In addition, QWSMouseHandler provides the setScreen() function
|
---|
152 | that allows you to specify a screen for your mouse driver and the
|
---|
153 | limitToScreen() function that ensures that a given position is
|
---|
154 | within this screen's boundaries (changing the position if
|
---|
155 | necessary). Finally, QWSMouseHandler provides the pos() function
|
---|
156 | returning the current mouse position.
|
---|
157 |
|
---|
158 | \sa QMouseDriverPlugin, QMouseDriverFactory, {Qt for Embedded Linux Pointer
|
---|
159 | Handling}
|
---|
160 | */
|
---|
161 |
|
---|
162 |
|
---|
163 | /*!
|
---|
164 | \fn void QWSMouseHandler::suspend()
|
---|
165 |
|
---|
166 | Implement this function to suspend reading and handling of mouse
|
---|
167 | events, e.g., call the QSocketNotifier::setEnabled() function to
|
---|
168 | disable the socket notifier.
|
---|
169 |
|
---|
170 | \sa resume()
|
---|
171 | */
|
---|
172 |
|
---|
173 | /*!
|
---|
174 | \fn void QWSMouseHandler::resume()
|
---|
175 |
|
---|
176 | Implement this function to resume reading and handling mouse
|
---|
177 | events, e.g., call the QSocketNotifier::setEnabled() function to
|
---|
178 | enable the socket notifier.
|
---|
179 |
|
---|
180 | \sa suspend()
|
---|
181 | */
|
---|
182 |
|
---|
183 | /*!
|
---|
184 | \fn const QPoint &QWSMouseHandler::pos() const
|
---|
185 |
|
---|
186 | Returns the current mouse position.
|
---|
187 |
|
---|
188 | \sa mouseChanged(), limitToScreen()
|
---|
189 | */
|
---|
190 |
|
---|
191 | /*!
|
---|
192 | Constructs a mouse driver. The \a driver and \a device arguments
|
---|
193 | are passed by the QWS_MOUSE_PROTO environment variable.
|
---|
194 |
|
---|
195 | Call the QWSServer::setMouseHandler() function to make the newly
|
---|
196 | created mouse driver, the primary driver. Note that the primary
|
---|
197 | driver is controlled by the system, i.e., the system will delete
|
---|
198 | it upon exit.
|
---|
199 | */
|
---|
200 | QWSMouseHandler::QWSMouseHandler(const QString &, const QString &)
|
---|
201 | : mousePos(QWSServer::mousePosition), d_ptr(new QWSMouseHandlerPrivate)
|
---|
202 | {
|
---|
203 | }
|
---|
204 |
|
---|
205 | /*!
|
---|
206 | Destroys this mouse driver.
|
---|
207 |
|
---|
208 | Do not call this function if this driver is the primary mouse
|
---|
209 | driver, i.e., if QWSServer::setMouseHandler() function has been
|
---|
210 | called passing this driver as argument. The primary mouse
|
---|
211 | driver is deleted by the system.
|
---|
212 | */
|
---|
213 | QWSMouseHandler::~QWSMouseHandler()
|
---|
214 | {
|
---|
215 | delete d_ptr;
|
---|
216 | }
|
---|
217 |
|
---|
218 | /*!
|
---|
219 | Ensures that the given \a position is within the screen's
|
---|
220 | boundaries, changing the \a position if necessary.
|
---|
221 |
|
---|
222 | \sa pos(), setScreen()
|
---|
223 | */
|
---|
224 |
|
---|
225 | void QWSMouseHandler::limitToScreen(QPoint &position)
|
---|
226 | {
|
---|
227 | position.setX(qMin(d_ptr->screen->deviceWidth() - 1, qMax(0, position.x())));
|
---|
228 | position.setY(qMin(d_ptr->screen->deviceHeight() - 1, qMax(0, position.y())));
|
---|
229 | }
|
---|
230 |
|
---|
231 | /*!
|
---|
232 | \since 4.2
|
---|
233 |
|
---|
234 | Sets the screen for this mouse driver to be the given \a screen.
|
---|
235 |
|
---|
236 | \sa limitToScreen()
|
---|
237 | */
|
---|
238 | void QWSMouseHandler::setScreen(const QScreen *screen)
|
---|
239 | {
|
---|
240 | d_ptr->screen = (screen ? screen : qt_screen);
|
---|
241 | }
|
---|
242 |
|
---|
243 | /*!
|
---|
244 | Notifies the system of a new mouse event.
|
---|
245 |
|
---|
246 | This function updates the current mouse position and sends the
|
---|
247 | event to the \l{Qt for Embedded Linux} server application for
|
---|
248 | delivery to the correct widget. Note that a custom mouse driver must call
|
---|
249 | this function whenever it wants to deliver a new mouse event.
|
---|
250 |
|
---|
251 | The given \a position is the global position of the mouse cursor.
|
---|
252 | The \a state parameter is a bitmask of the Qt::MouseButton enum's
|
---|
253 | values, indicating which mouse buttons are pressed. The \a wheel
|
---|
254 | parameter is the delta value of the mouse wheel as returned by
|
---|
255 | QWheelEvent::delta().
|
---|
256 |
|
---|
257 | \sa pos()
|
---|
258 | */
|
---|
259 | void QWSMouseHandler::mouseChanged(const QPoint &position, int state, int wheel)
|
---|
260 | {
|
---|
261 | mousePos = position + d_ptr->screen->offset();
|
---|
262 | QWSServer::sendMouseEvent(mousePos, state, wheel);
|
---|
263 | }
|
---|
264 |
|
---|
265 | /*!
|
---|
266 | \fn QWSMouseHandler::clearCalibration()
|
---|
267 |
|
---|
268 | This virtual function allows subclasses of QWSMouseHandler to
|
---|
269 | clear the calibration information. Note that the default
|
---|
270 | implementation does nothing.
|
---|
271 |
|
---|
272 | \sa QWSCalibratedMouseHandler::clearCalibration(), calibrate()
|
---|
273 | */
|
---|
274 |
|
---|
275 | /*!
|
---|
276 | \fn QWSMouseHandler::calibrate(const QWSPointerCalibrationData *data)
|
---|
277 |
|
---|
278 | This virtual function allows subclasses of QWSMouseHandler to set
|
---|
279 | the calibration information passed in the given \a data. Note that
|
---|
280 | the default implementation does nothing.
|
---|
281 |
|
---|
282 | \sa QWSCalibratedMouseHandler::calibrate(), clearCalibration()
|
---|
283 | */
|
---|
284 |
|
---|
285 | /*! \fn QWSMouseHandler::getCalibration(QWSPointerCalibrationData *data) const
|
---|
286 | This virtual function allows subclasses of QWSMouseHandler
|
---|
287 | to fill in the device coordinates in \a data with values
|
---|
288 | that correspond to screen coordinates that are already in
|
---|
289 | \a data. Note that the default implementation does nothing.
|
---|
290 | */
|
---|
291 |
|
---|
292 | /*!
|
---|
293 | \class QWSCalibratedMouseHandler
|
---|
294 | \ingroup qws
|
---|
295 |
|
---|
296 | \brief The QWSCalibratedMouseHandler class provides mouse
|
---|
297 | calibration and noise reduction in Qt for Embedded Linux.
|
---|
298 |
|
---|
299 | Note that this class is only available in \l{Qt for Embedded Linux}.
|
---|
300 |
|
---|
301 | \l{Qt for Embedded Linux} provides ready-made drivers for several mouse
|
---|
302 | protocols, see the \l{Qt for Embedded Linux Pointer Handling}{pointer
|
---|
303 | handling} documentation for details. In general, custom mouse
|
---|
304 | drivers can be implemented by subclassing the QWSMouseHandler
|
---|
305 | class. But when the system device does not have a fixed mapping
|
---|
306 | between device and screen coordinates and/or produces noisy events
|
---|
307 | (e.g., a touchscreen), you should derive from the
|
---|
308 | QWSCalibratedMouseHandler class instead to take advantage of its
|
---|
309 | calibration functionality. As always, you must also create a mouse
|
---|
310 | driver plugin (derived from QMouseDriverPlugin);
|
---|
311 | the implementation of the QMouseDriverFactory class will then
|
---|
312 | automatically detect the plugin, and load the driver into the
|
---|
313 | server application at run-time using Qt's
|
---|
314 | \l{How to Create Qt Plugins}{plugin system}.
|
---|
315 |
|
---|
316 | QWSCalibratedMouseHandler provides an implementation of the
|
---|
317 | calibrate() function to update the calibration parameters based on
|
---|
|
---|