qevdevmousehandler.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10const QLoggingCategory &qLcEvdevMouse() { static const QLoggingCategory category("qt.qpa.input"); return
never executed: return category;
category;
never executed: return category;
}
0
11-
12QEvdevMouseHandler *QEvdevMouseHandler::create(const QString &device, const QString &specification)-
13{-
14 for (bool qt_category_enabled = qLcEvdevMouse().isDebugEnabled(); qt_category_enabled
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
; qt_category_enabled = false) QMessageLogger(__FILE__, 67, __PRETTY_FUNCTION__, qLcEvdevMouse().categoryName()).debug() << "create mouse handler for" << device << specification;
never executed: QMessageLogger(__FILE__, 67, __PRETTY_FUNCTION__, qLcEvdevMouse().categoryName()).debug() << "create mouse handler for" << device << specification;
0
15-
16 bool compression = true;-
17 int jitterLimit = 0;-
18 int grab = 0;-
19 bool abs = false;-
20-
21 const auto args = specification.splitRef(QLatin1Char(':'));-
22 for (const QStringRef &arg : args) {-
23 if (arg == QLatin1String("nocompress")
arg == QLatin1...("nocompress")Description
TRUEnever evaluated
FALSEnever evaluated
)
0
24 compression = false;
never executed: compression = false;
0
25 else if (arg.startsWith(QLatin1String("dejitter="))
arg.startsWith...("dejitter="))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
26 jitterLimit = arg.mid(9).toInt();
never executed: jitterLimit = arg.mid(9).toInt();
0
27 else if (arg.startsWith(QLatin1String("grab="))
arg.startsWith...ring("grab="))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
28 grab = arg.mid(5).toInt();
never executed: grab = arg.mid(5).toInt();
0
29 else if (arg == QLatin1String("abs")
arg == QLatin1String("abs")Description
TRUEnever evaluated
FALSEnever evaluated
)
0
30 abs = true;
never executed: abs = true;
0
31 }
never executed: end of block
0
32-
33 int fd;-
34 fd = qt_safe_open(device.toLocal8Bit().constData(), 00 | 04000, 0);-
35 if (fd >= 0
fd >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
36 ::ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('E')) << (0 +8)) | (((0x90)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), grab);-
37 return
never executed: return new QEvdevMouseHandler(device, fd, abs, compression, jitterLimit);
new QEvdevMouseHandler(device, fd, abs, compression, jitterLimit);
never executed: return new QEvdevMouseHandler(device, fd, abs, compression, jitterLimit);
0
38 } else {-
39 qErrnoWarning((*__errno_location ()), "Cannot open mouse input device %s", QString(device).toLocal8Bit().constData());-
40 return
never executed: return 0;
0;
never executed: return 0;
0
41 }-
42}-
43-
44QEvdevMouseHandler::QEvdevMouseHandler(const QString &device, int fd, bool abs, bool compression, int jitterLimit)-
45 : m_device(device), m_fd(fd), m_notify(0), m_x(0), m_y(0), m_prevx(0), m_prevy(0),-
46 m_abs(abs), m_compression(compression), m_buttons(0), m_prevInvalid(true)-
47{-
48 setObjectName(QLatin1String("Evdev Mouse Handler"));-
49-
50 m_jitterLimitSquared = jitterLimit * jitterLimit;-
51-
52-
53-
54-
55-
56-
57 if (m_abs
m_absDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
58 m_abs = getHardwareMaximum();
never executed: m_abs = getHardwareMaximum();
0
59-
60-
61 m_notify = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);-
62 connect(m_notify, qFlagLocation("2""activated(int)" "\0" __FILE__ ":" "115"), this, qFlagLocation("1""readMouseData()" "\0" __FILE__ ":" "115"));-
63}
never executed: end of block
0
64-
65QEvdevMouseHandler::~QEvdevMouseHandler()-
66{-
67 if (m_fd >= 0
m_fd >= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
68 qt_safe_close(m_fd);
never executed: qt_safe_close(m_fd);
0
69}
never executed: end of block
0
70-
71-
72-
73bool QEvdevMouseHandler::getHardwareMaximum()-
74{-
75 unsigned char absFeatures[(0x3f / 8) + 1];-
76 memset(absFeatures, '\0', sizeof (absFeatures));-
77-
78-
79 if (ioctl(m_fd, (((2U) << (((0 +8)+8)+14)) | (('E') << (0 +8)) | ((0x20 + (0x03)) << 0) | ((sizeof (absFeatures)) << ((0 +8)+8))), absFeatures) == -1
ioctl(m_fd, ((...eatures) == -1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
80 return
never executed: return false;
false;
never executed: return false;
0
81-
82 if ((
(!(absFeatures...1<<(0x00%8))))Description
TRUEnever evaluated
FALSEnever evaluated
!(absFeatures[0x00/8] & (1<<(0x00%8))))
(!(absFeatures...1<<(0x00%8))))Description
TRUEnever evaluated
FALSEnever evaluated
|| (
(!(absFeatures...1<<(0x01%8))))Description
TRUEnever evaluated
FALSEnever evaluated
!(absFeatures[0x01/8] & (1<<(0x01%8))))
(!(absFeatures...1<<(0x01%8))))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
83 return
never executed: return false;
false;
never executed: return false;
0
84-
85-
86 struct input_absinfo absInfo;-
87 if (ioctl(m_fd, (((2U) << (((0 +8)+8)+14)) | ((('E')) << (0 +8)) | (((0x40 + (0x00))) << 0) | ((((sizeof(struct input_absinfo)))) << ((0 +8)+8))), &absInfo) == -1
ioctl(m_fd, ((...absInfo) == -1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
88 return
never executed: return false;
false;
never executed: return false;
0
89-
90 m_hardwareWidth = absInfo.maximum - absInfo.minimum;-
91-
92 if (ioctl(m_fd, (((2U) << (((0 +8)+8)+14)) | ((('E')) << (0 +8)) | (((0x40 + (0x01))) << 0) | ((((sizeof(struct input_absinfo)))) << ((0 +8)+8))), &absInfo) == -1
ioctl(m_fd, ((...absInfo) == -1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
93 return
never executed: return false;
false;
never executed: return false;
0
94-
95 m_hardwareHeight = absInfo.maximum - absInfo.minimum;-
96-
97 QScreen *primaryScreen = QGuiApplication::primaryScreen();-
98 QRect g = QHighDpi::toNativePixels(primaryScreen->virtualGeometry(), primaryScreen);-
99 m_hardwareScalerX = static_cast<qreal>(m_hardwareWidth) / (g.right() - g.left());-
100 m_hardwareScalerY = static_cast<qreal>(m_hardwareHeight) / (g.bottom() - g.top());-
101-
102 for (bool qt_category_enabled = qLcEvdevMouse().isDebugEnabled(); qt_category_enabled
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
; qt_category_enabled = false) QMessageLogger(__FILE__, 155, __PRETTY_FUNCTION__, qLcEvdevMouse().categoryName()).debug() << "Absolute pointing device"
never executed: QMessageLogger(__FILE__, 155, __PRETTY_FUNCTION__, qLcEvdevMouse().categoryName()).debug() << "Absolute pointing device" << "hardware max x" << m_hardwareWidth << "hardware max y" << m_hardwareHeight << "hardware scalers x" << m_hardwareScalerX << 'y' << m_hardwareScalerY;
0
103 << "hardware max x" << m_hardwareWidth
never executed: QMessageLogger(__FILE__, 155, __PRETTY_FUNCTION__, qLcEvdevMouse().categoryName()).debug() << "Absolute pointing device" << "hardware max x" << m_hardwareWidth << "hardware max y" << m_hardwareHeight << "hardware scalers x" << m_hardwareScalerX << 'y' << m_hardwareScalerY;
0
104 << "hardware max y" << m_hardwareHeight
never executed: QMessageLogger(__FILE__, 155, __PRETTY_FUNCTION__, qLcEvdevMouse().categoryName()).debug() << "Absolute pointing device" << "hardware max x" << m_hardwareWidth << "hardware max y" << m_hardwareHeight << "hardware scalers x" << m_hardwareScalerX << 'y' << m_hardwareScalerY;
0
105 << "hardware scalers x" << m_hardwareScalerX << 'y' << m_hardwareScalerY;
never executed: QMessageLogger(__FILE__, 155, __PRETTY_FUNCTION__, qLcEvdevMouse().categoryName()).debug() << "Absolute pointing device" << "hardware max x" << m_hardwareWidth << "hardware max y" << m_hardwareHeight << "hardware scalers x" << m_hardwareScalerX << 'y' << m_hardwareScalerY;
0
106-
107 return
never executed: return true;
true;
never executed: return true;
0
108}-
109-
110void QEvdevMouseHandler::sendMouseEvent()-
111{-
112 int x;-
113 int y;-
114-
115 if (!m_abs
!m_absDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
116 x = m_x - m_prevx;-
117 y = m_y - m_prevy;-
118 }
never executed: end of block
0
119 else {-
120 x = m_x / m_hardwareScalerX;-
121 y = m_y / m_hardwareScalerY;-
122 }
never executed: end of block
0
123-
124 if (m_prevInvalid
m_prevInvalidDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
125 x = y = 0;-
126 m_prevInvalid = false;-
127 }
never executed: end of block
0
128-
129 handleMouseEvent(x, y, m_abs, m_buttons);-
130-
131 m_prevx = m_x;-
132 m_prevy = m_y;-
133}
never executed: end of block
0
134-
135void QEvdevMouseHandler::readMouseData()-
136{-
137 struct ::input_event buffer[32];-
138 int n = 0;-
139 bool posChanged = false, btnChanged = false;-
140 bool pendingMouseEvent = false;-
141 int eventCompressCount = 0;-
142 for(;;) {-
143 int result = qt_safe_read(m_fd, reinterpret_cast<char *>(buffer) + n, sizeof(buffer) - n);-
144-
145 if (result == 0
result == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
146 QMessageLogger(__FILE__, 199, __PRETTY_FUNCTION__).warning("evdevmouse: Got EOF from the input device");-
147 return;
never executed: return;
0
148 } else if (result < 0
result < 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
149 if ((*
(*__errno_location ()) != 4Description
TRUEnever evaluated
FALSEnever evaluated
__errno_location ()) != 4
(*__errno_location ()) != 4Description
TRUEnever evaluated
FALSEnever evaluated
&& (*
(*__errno_location ()) != 11Description
TRUEnever evaluated
FALSEnever evaluated
__errno_location ()) != 11
(*__errno_location ()) != 11Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
150 qErrnoWarning((*__errno_location ()), "evdevmouse: Could not read from input device");-
151-
152-
153 if ((*
(*__errno_location ()) == 19Description
TRUEnever evaluated
FALSEnever evaluated
__errno_location ()) == 19
(*__errno_location ()) == 19Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
154 delete m_notify;-
155 m_notify = nullptr;-
156 qt_safe_close(m_fd);-
157 m_fd = -1;-
158 }
never executed: end of block
0
159 return;
never executed: return;
0
160 }-
161 }
never executed: end of block
else {
0
162 n += result;-
163 if (n % sizeof(buffer[0]) == 0
n % sizeof(buffer[0]) == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
164 break;
never executed: break;
0
165 }
never executed: end of block
0
166 }-
167-
168 n /= sizeof(buffer[0]);-
169-
170 for (int i = 0; i < n
i < nDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
171 struct ::input_event *data = &buffer[i];-
172 if (data->type == 0x03
data->type == 0x03Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
173-
174 if (data->code == 0x00
data->code == 0x00Description
TRUEnever evaluated
FALSEnever evaluated
&& m_x != data->value
m_x != data->valueDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
175 m_x = data->value;-
176 posChanged = true;-
177 }
never executed: end of block
else if (data->code == 0x01
data->code == 0x01Description
TRUEnever evaluated
FALSEnever evaluated
&& m_y != data->value
m_y != data->valueDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
178 m_y = data->value;-
179 posChanged = true;-
180 }
never executed: end of block
0
181 }
never executed: end of block
else if (data->type == 0x02
data->type == 0x02Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
182 if (data->code == 0x00
data->code == 0x00Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
183 m_x += data->value;-
184 posChanged = true;-
185 }
never executed: end of block
else if (data->code == 0x01
data->code == 0x01Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
186 m_y += data->value;-
187 posChanged = true;-
188 }
never executed: end of block
else if (data->code == 0x08
data->code == 0x08Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
189-
190 const int delta = 120 * data->value;-
191 handleWheelEvent(delta, Qt::Vertical);-
192 }
never executed: end of block
else if (data->code == 0x06
data->code == 0x06Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
193-
194 const int delta = 120 * -data->value;-
195 handleWheelEvent(delta, Qt::Horizontal);-
196 }
never executed: end of block
0
197 }
never executed: end of block
else if (data->type == 0x01
data->type == 0x01Description
TRUEnever evaluated
FALSEnever evaluated
&& data->code == 0x14a
data->code == 0x14aDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
198-
199-
200 m_prevInvalid = true;-
201 }
never executed: end of block
else if (data->type == 0x01
data->type == 0x01Description
TRUEnever evaluated
FALSEnever evaluated
&& data->code >= 0x110
data->code >= 0x110Description
TRUEnever evaluated
FALSEnever evaluated
&& data->code <= 0x120
data->code <= 0x120Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
202 Qt::MouseButton button = Qt::NoButton;-
203-
204-
205 switch (data->code) {-
206 case
never executed: case 0x110:
0x110:
never executed: case 0x110:
button = Qt::LeftButton; break;
never executed: break;
0
207 case
never executed: case 0x111:
0x111:
never executed: case 0x111:
button = Qt::RightButton; break;
never executed: break;
0
208 case
never executed: case 0x112:
0x112:
never executed: case 0x112:
button = Qt::MiddleButton; break;
never executed: break;
0
209 case
never executed: case 0x113:
0x113:
never executed: case 0x113:
button = Qt::ExtraButton1; break;
never executed: break;
0
210 case
never executed: case 0x114:
0x114:
never executed: case 0x114:
button = Qt::ExtraButton2; break;
never executed: break;
0
211 case
never executed: case 0x115:
0x115:
never executed: case 0x115:
button = Qt::ExtraButton3; break;
never executed: break;
0
212 case
never executed: case 0x116:
0x116:
never executed: case 0x116:
button = Qt::ExtraButton4; break;
never executed: break;
0
213 case
never executed: case 0x117:
0x117:
never executed: case 0x117:
button = Qt::ExtraButton5; break;
never executed: break;
0
214 case
never executed: case 0x118:
0x118:
never executed: case 0x118:
button = Qt::ExtraButton6; break;
never executed: break;
0
215 case
never executed: case 0x119:
0x119:
never executed: case 0x119:
button = Qt::ExtraButton7; break;
never executed: break;
0
216 case
never executed: case 0x11a:
0x11a:
never executed: case 0x11a:
button = Qt::ExtraButton8; break;
never executed: break;
0
217 case
never executed: case 0x11b:
0x11b:
never executed: case 0x11b:
button = Qt::ExtraButton9; break;
never executed: break;
0
218 case
never executed: case 0x11c:
0x11c:
never executed: case 0x11c:
button = Qt::ExtraButton10; break;
never executed: break;
0
219 case
never executed: case 0x11d:
0x11d:
never executed: case 0x11d:
button = Qt::ExtraButton11; break;
never executed: break;
0
220 case
never executed: case 0x11e:
0x11e:
never executed: case 0x11e:
button = Qt::ExtraButton12; break;
never executed: break;
0
221 case
never executed: case 0x11f:
0x11f:
never executed: case 0x11f:
button = Qt::ExtraButton13; break;
never executed: break;
0
222 }-
223 m_buttons.setFlag(button, data->value);-
224 btnChanged = true;-
225 }
never executed: end of block
else if (data->type == 0x00
data->type == 0x00Description
TRUEnever evaluated
FALSEnever evaluated
&& data->code == 0
data->code == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
226 if (btnChanged
btnChangedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
227 btnChanged = posChanged = false;-
228 sendMouseEvent();-
229 pendingMouseEvent = false;-
230 }
never executed: end of block
else if (posChanged
posChangedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
231 posChanged = false;-
232 if (m_compression
m_compressionDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
233 pendingMouseEvent = true;-
234 eventCompressCount++;-
235 }
never executed: end of block
else {
0
236 sendMouseEvent();-
237 }
never executed: end of block
0
238 }-
239 }
never executed: end of block
else if (data->type == 0x04
data->type == 0x04Description
TRUEnever evaluated
FALSEnever evaluated
&& data->code == 0x04
data->code == 0x04Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
240-
241 continue;
never executed: continue;
0
242 }-
243 }
never executed: end of block
0
244 if (m_compression
m_compressionDescription
TRUEnever evaluated
FALSEnever evaluated
&& pendingMouseEvent
pendingMouseEventDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
245 int distanceSquared = (m_x - m_prevx)*(m_x - m_prevx) + (m_y - m_prevy)*(m_y - m_prevy);-
246 if (distanceSquared > m_jitterLimitSquared
distanceSquare...erLimitSquaredDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
247 sendMouseEvent();
never executed: sendMouseEvent();
0
248 }
never executed: end of block
0
249}
never executed: end of block
0
250-
251-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9