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 | #ifndef QT_NO_QWS_MOUSE_QVFB
|
---|
43 |
|
---|
44 | #include <stdlib.h>
|
---|
45 | #include <sys/types.h>
|
---|
46 | #include <unistd.h>
|
---|
47 | #include <fcntl.h>
|
---|
48 | #include <errno.h>
|
---|
49 | #include <stdio.h>
|
---|
50 |
|
---|
51 | #include <qvfbhdr.h>
|
---|
52 | #include <qmousevfb_qws.h>
|
---|
53 | #include <qwindowsystem_qws.h>
|
---|
54 | #include <qsocketnotifier.h>
|
---|
55 | #include <qapplication.h>
|
---|
56 | #include <qtimer.h>
|
---|
57 | #include <private/qcore_unix_p.h> // overrides QT_OPEN
|
---|
58 |
|
---|
59 | QT_BEGIN_NAMESPACE
|
---|
60 |
|
---|
61 | QVFbMouseHandler::QVFbMouseHandler(const QString &driver, const QString &device)
|
---|
62 | : QObject(), QWSMouseHandler(driver, device)
|
---|
63 | {
|
---|
64 | QString mouseDev = device;
|
---|
65 | if (device.isEmpty())
|
---|
66 | mouseDev = QLatin1String("/dev/vmouse");
|
---|
67 |
|
---|
68 | mouseFD = QT_OPEN(mouseDev.toLatin1().constData(), O_RDWR | O_NDELAY);
|
---|
69 | if (mouseFD == -1) {
|
---|
70 | perror("QVFbMouseHandler::QVFbMouseHandler");
|
---|
71 | qWarning("QVFbMouseHander: Unable to open device %s",
|
---|
72 | qPrintable(mouseDev));
|
---|
73 | return;
|
---|
74 | }
|
---|
75 |
|
---|
76 | // Clear pending input
|
---|
77 | char buf[2];
|
---|
78 | while (QT_READ(mouseFD, buf, 1) > 0) { }
|
---|
79 |
|
---|
80 | mouseIdx = 0;
|
---|
81 |
|
---|
82 | mouseNotifier = new QSocketNotifier(mouseFD, QSocketNotifier::Read, this);
|
---|
83 | connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
|
---|
84 | }
|
---|
85 |
|
---|
86 | QVFbMouseHandler::~QVFbMouseHandler()
|
---|
87 | {
|
---|
88 | if (mouseFD >= 0)
|
---|
89 | QT_CLOSE(mouseFD);
|
---|
90 | }
|
---|
91 |
|
---|
92 | void QVFbMouseHandler::resume()
|
---|
93 | {
|
---|
94 | mouseNotifier->setEnabled(true);
|
---|
95 | }
|
---|
96 |
|
---|
97 | void QVFbMouseHandler::suspend()
|
---|
98 | {
|
---|
99 | mouseNotifier->setEnabled(false);
|
---|
100 | }
|
---|
101 |
|
---|
102 | void QVFbMouseHandler::readMouseData()
|
---|
103 | {
|
---|
104 | int n;
|
---|
105 | do {
|
---|
106 | n = QT_READ(mouseFD, mouseBuf+mouseIdx, mouseBufSize-mouseIdx);
|
---|
107 | if (n > 0)
|
---|
108 | mouseIdx += n;
|
---|
109 | } while (n > 0);
|
---|
110 |
|
---|
111 | int idx = 0;
|
---|
112 | static const int packetsize = sizeof(QPoint) + 2*sizeof(int);
|
---|
113 | while (mouseIdx-idx >= packetsize) {
|
---|
114 | uchar *mb = mouseBuf+idx;
|
---|
115 | QPoint mousePos = *reinterpret_cast<QPoint *>(mb);
|
---|
116 | mb += sizeof(QPoint);
|
---|
117 | int bstate = *reinterpret_cast<int *>(mb);
|
---|
118 | mb += sizeof(int);
|
---|
119 | int wheel = *reinterpret_cast<int *>(mb);
|
---|
120 | // limitToScreen(mousePos);
|
---|
121 | mouseChanged(mousePos, bstate, wheel);
|
---|
122 | idx += packetsize;
|
---|
123 | }
|
---|
124 |
|
---|
125 | int surplus = mouseIdx - idx;
|
---|
126 | for (int i = 0; i < surplus; i++)
|
---|
127 | mouseBuf[i] = mouseBuf[idx+i];
|
---|
128 | mouseIdx = surplus;
|
---|
129 | }
|
---|
130 |
|
---|
131 | QT_END_NAMESPACE
|
---|
132 |
|
---|
133 | #endif // QT_NO_QWS_MOUSE_QVFB
|
---|