qevdevkeyboardhandler.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qevdevkeyboardhandler_p.h"-
41-
42#include <qplatformdefs.h>-
43-
44#include <QFile>-
45#include <QSocketNotifier>-
46#include <QStringList>-
47#include <QCoreApplication>-
48#include <QLoggingCategory>-
49#include <qpa/qwindowsysteminterface.h>-
50#include <private/qcore_unix_p.h>-
51-
52#include <linux/input.h>-
53-
54QT_BEGIN_NAMESPACE-
55-
56Q_LOGGING_CATEGORY(qLcEvdevKey, "qt.qpa.input")
never executed: return category;
0
57Q_LOGGING_CATEGORY(qLcEvdevKeyMap, "qt.qpa.input.keymap")
never executed: return category;
0
58-
59// simple builtin US keymap-
60#include "qevdevkeyboard_defaultmap_p.h"-
61-
62void QFdContainer::reset() Q_DECL_NOTHROW-
63{-
64 if (m_fd >= 0)
m_fd >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
65 qt_safe_close(m_fd);
never executed: qt_safe_close(m_fd);
0
66 m_fd = -1;-
67}
never executed: end of block
0
68-
69QEvdevKeyboardHandler::QEvdevKeyboardHandler(const QString &device, QFdContainer &fd, bool disableZap, bool enableCompose, const QString &keymapFile)-
70 : m_device(device), m_fd(fd.release()), m_notify(Q_NULLPTR),-
71 m_modifiers(0), m_composing(0), m_dead_unicode(0xffff),-
72 m_no_zap(disableZap), m_do_compose(enableCompose),-
73 m_keymap(0), m_keymap_size(0), m_keycompose(0), m_keycompose_size(0)-
74{-
75 qCDebug(qLcEvdevKey) << "Create keyboard handler with for device" << device;
never executed: QMessageLogger(__FILE__, 75, __PRETTY_FUNCTION__, qLcEvdevKey().categoryName()).debug() << "Create keyboard handler with for device" << device;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
76-
77 setObjectName(QLatin1String("LinuxInput Keyboard Handler"));-
78-
79 memset(m_locks, 0, sizeof(m_locks));-
80-
81 if (keymapFile.isEmpty() || !loadKeymap(keymapFile))
keymapFile.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
!loadKeymap(keymapFile)Description
TRUEnever evaluated
FALSEnever evaluated
0
82 unloadKeymap();
never executed: unloadKeymap();
0
83-
84 // socket notifier for events on the keyboard device-
85 m_notify = new QSocketNotifier(m_fd.get(), QSocketNotifier::Read, this);-
86 connect(m_notify, SIGNAL(activated(int)), this, SLOT(readKeycode()));-
87}
never executed: end of block
0
88-
89QEvdevKeyboardHandler::~QEvdevKeyboardHandler()-
90{-
91 unloadKeymap();-
92}
never executed: end of block
0
93-
94QEvdevKeyboardHandler *QEvdevKeyboardHandler::create(const QString &device,-
95 const QString &specification,-
96 const QString &defaultKeymapFile)-
97{-
98 qCDebug(qLcEvdevKey) << "Try to create keyboard handler for" << device << specification;
never executed: QMessageLogger(__FILE__, 98, __PRETTY_FUNCTION__, qLcEvdevKey().categoryName()).debug() << "Try to create keyboard handler for" << device << specification;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
99-
100 QString keymapFile = defaultKeymapFile;-
101 int repeatDelay = 400;-
102 int repeatRate = 80;-
103 bool disableZap = false;-
104 bool enableCompose = false;-
105 int grab = 0;-
106-
107 const auto args = specification.splitRef(QLatin1Char(':'));-
108 for (const QStringRef &arg : args) {-
109 if (arg.startsWith(QLatin1String("keymap=")))
arg.startsWith...ng("keymap="))Description
TRUEnever evaluated
FALSEnever evaluated
0
110 keymapFile = arg.mid(7).toString();
never executed: keymapFile = arg.mid(7).toString();
0
111 else if (arg == QLatin1String("disable-zap"))
arg == QLatin1..."disable-zap")Description
TRUEnever evaluated
FALSEnever evaluated
0
112 disableZap = true;
never executed: disableZap = true;
0
113 else if (arg == QLatin1String("enable-compose"))
arg == QLatin1...able-compose")Description
TRUEnever evaluated
FALSEnever evaluated
0
114 enableCompose = true;
never executed: enableCompose = true;
0
115 else if (arg.startsWith(QLatin1String("repeat-delay=")))
arg.startsWith...peat-delay="))Description
TRUEnever evaluated
FALSEnever evaluated
0
116 repeatDelay = arg.mid(13).toInt();
never executed: repeatDelay = arg.mid(13).toInt();
0
117 else if (arg.startsWith(QLatin1String("repeat-rate=")))
arg.startsWith...epeat-rate="))Description
TRUEnever evaluated
FALSEnever evaluated
0
118 repeatRate = arg.mid(12).toInt();
never executed: repeatRate = arg.mid(12).toInt();
0
119 else if (arg.startsWith(QLatin1String("grab=")))
arg.startsWith...ring("grab="))Description
TRUEnever evaluated
FALSEnever evaluated
0
120 grab = arg.mid(5).toInt();
never executed: grab = arg.mid(5).toInt();
0
121 }
never executed: end of block
0
122-
123 qCDebug(qLcEvdevKey) << "Opening keyboard at" << device;
never executed: QMessageLogger(__FILE__, 123, __PRETTY_FUNCTION__, qLcEvdevKey().categoryName()).debug() << "Opening keyboard at" << device;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
124-
125 QFdContainer fd(qt_safe_open(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0));-
126 if (fd.get() >= 0) {
fd.get() >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
127 ::ioctl(fd.get(), EVIOCGRAB, grab);-
128 if (repeatDelay > 0 && repeatRate > 0) {
repeatDelay > 0Description
TRUEnever evaluated
FALSEnever evaluated
repeatRate > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
129 int kbdrep[2] = { repeatDelay, repeatRate };-
130 ::ioctl(fd.get(), EVIOCSREP, kbdrep);-
131 }
never executed: end of block
0
132-
133 return new QEvdevKeyboardHandler(device, fd, disableZap, enableCompose, keymapFile);
never executed: return new QEvdevKeyboardHandler(device, fd, disableZap, enableCompose, keymapFile);
0
134 } else {-
135 qWarning("Cannot open keyboard input device '%s': %s", qPrintable(device), strerror(errno));-
136 return 0;
never executed: return 0;
0
137 }-
138}-
139-
140void QEvdevKeyboardHandler::switchLed(int led, bool state)-
141{-
142 qCDebug(qLcEvdevKey) << "switchLed" << led << state;
never executed: QMessageLogger(__FILE__, 142, __PRETTY_FUNCTION__, qLcEvdevKey().categoryName()).debug() << "switchLed" << led << state;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
143-
144 struct ::input_event led_ie;-
145 ::gettimeofday(&led_ie.time, 0);-
146 led_ie.type = EV_LED;-
147 led_ie.code = led;-
148 led_ie.value = state;-
149-
150 qt_safe_write(m_fd.get(), &led_ie, sizeof(led_ie));-
151}
never executed: end of block
0
152-
153void QEvdevKeyboardHandler::readKeycode()-
154{-
155 struct ::input_event buffer[32];-
156 int n = 0;-
157-
158 forever {-
159 int result = qt_safe_read(m_fd.get(), reinterpret_cast<char *>(buffer) + n, sizeof(buffer) - n);-
160-
161 if (result == 0) {
result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
162 qWarning("evdevkeyboard: Got EOF from the input device");-
163 return;
never executed: return;
0
164 } else if (result < 0) {
result < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
165 if (errno != EINTR && errno != EAGAIN) {
(*__errno_location ()) != 4Description
TRUEnever evaluated
FALSEnever evaluated
(*__errno_location ()) != 11Description
TRUEnever evaluated
FALSEnever evaluated
0
166 qErrnoWarning(errno, "evdevkeyboard: Could not read from input device");-
167 // If the device got disconnected, stop reading, otherwise we get flooded-
168 // by the above error over and over again.-
169 if (errno == ENODEV) {
(*__errno_location ()) == 19Description
TRUEnever evaluated
FALSEnever evaluated
0
170 delete m_notify;-
171 m_notify = Q_NULLPTR;-
172 m_fd.reset();-
173 }
never executed: end of block
0
174 return;
never executed: return;
0
175 }-
176 } else {
never executed: end of block
0
177 n += result;-
178 if (n % sizeof(buffer[0]) == 0)
n % sizeof(buffer[0]) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
179 break;
never executed: break;
0
180 }
never executed: end of block
0
181 }-
182-
183 n /= sizeof(buffer[0]);-
184-
185 for (int i = 0; i < n; ++i) {
i < nDescription
TRUEnever evaluated
FALSEnever evaluated
0
186 if (buffer[i].type != EV_KEY)
buffer[i].type != 0x01Description
TRUEnever evaluated
FALSEnever evaluated
0
187 continue;
never executed: continue;
0
188-
189 quint16 code = buffer[i].code;-
190 qint32 value = buffer[i].value;-
191-
192 QEvdevKeyboardHandler::KeycodeAction ka;-
193 ka = processKeycode(code, value != 0, value == 2);-
194-
195 switch (ka) {-
196 case QEvdevKeyboardHandler::CapsLockOn:
never executed: case QEvdevKeyboardHandler::CapsLockOn:
0
197 case QEvdevKeyboardHandler::CapsLockOff:
never executed: case QEvdevKeyboardHandler::CapsLockOff:
0
198 switchLed(LED_CAPSL, ka == QEvdevKeyboardHandler::CapsLockOn);-
199 break;
never executed: break;
0
200-
201 case QEvdevKeyboardHandler::NumLockOn:
never executed: case QEvdevKeyboardHandler::NumLockOn:
0
202 case QEvdevKeyboardHandler::NumLockOff:
never executed: case QEvdevKeyboardHandler::NumLockOff:
0
203 switchLed(LED_NUML, ka == QEvdevKeyboardHandler::NumLockOn);-
204 break;
never executed: break;
0
205-
206 case QEvdevKeyboardHandler::ScrollLockOn:
never executed: case QEvdevKeyboardHandler::ScrollLockOn:
0
207 case QEvdevKeyboardHandler::ScrollLockOff:
never executed: case QEvdevKeyboardHandler::ScrollLockOff:
0
208 switchLed(LED_SCROLLL, ka == QEvdevKeyboardHandler::ScrollLockOn);-
209 break;
never executed: break;
0
210-
211 default:
never executed: default:
0
212 // ignore console switching and reboot-
213 break;
never executed: break;
0
214 }-
215 }-
216}
never executed: end of block
0
217-
218void QEvdevKeyboardHandler::processKeyEvent(int nativecode, int unicode, int qtcode,-
219 Qt::KeyboardModifiers modifiers, bool isPress, bool autoRepeat)-
220{-
221 QWindowSystemInterface::handleExtendedKeyEvent(0, (isPress ? QEvent::KeyPress : QEvent::KeyRelease),-
222 qtcode, modifiers, nativecode + 8, 0, int(modifiers),-
223 (unicode != 0xffff ) ? QString(unicode) : QString(), autoRepeat);-
224}
never executed: end of block
0
225-
226QEvdevKeyboardHandler::KeycodeAction QEvdevKeyboardHandler::processKeycode(quint16 keycode, bool pressed, bool autorepeat)-
227{-
228 KeycodeAction result = None;-
229 bool first_press = pressed && !autorepeat;
pressedDescription
TRUEnever evaluated
FALSEnever evaluated
!autorepeatDescription
TRUEnever evaluated
FALSEnever evaluated
0
230-
231 const QEvdevKeyboardMap::Mapping *map_plain = 0;-
232 const QEvdevKeyboardMap::Mapping *map_withmod = 0;-
233-
234 quint8 modifiers = m_modifiers;-
235-
236 // get a specific and plain mapping for the keycode and the current modifiers-
237 for (int i = 0; i < m_keymap_size && !(map_plain && map_withmod); ++i) {
i < m_keymap_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
map_plainDescription
TRUEnever evaluated
FALSEnever evaluated
map_withmodDescription
TRUEnever evaluated
FALSEnever evaluated
0
238 const QEvdevKeyboardMap::Mapping *m = m_keymap + i;-
239 if (m->keycode == keycode) {
m->keycode == keycodeDescription
TRUEnever evaluated
FALSEnever evaluated
0
240 if (m->modifiers == 0)
m->modifiers == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
241 map_plain = m;
never executed: map_plain = m;
0
242-
243 quint8 testmods = m_modifiers;-
244 if (m_locks[0] /*CapsLock*/ && (m->flags & QEvdevKeyboardMap::IsLetter))
m_locks[0]Description
TRUEnever evaluated
FALSEnever evaluated
(m->flags & QE...Map::IsLetter)Description
TRUEnever evaluated
FALSEnever evaluated
0
245 testmods ^= QEvdevKeyboardMap::ModShift;
never executed: testmods ^= QEvdevKeyboardMap::ModShift;
0
246 if (m->modifiers == testmods)
m->modifiers == testmodsDescription
TRUEnever evaluated
FALSEnever evaluated
0
247 map_withmod = m;
never executed: map_withmod = m;
0
248 }
never executed: end of block
0
249 }
never executed: end of block
0
250-
251 if (m_locks[0] /*CapsLock*/ && map_withmod && (map_withmod->flags & QEvdevKeyboardMap::IsLetter))
m_locks[0]Description
TRUEnever evaluated
FALSEnever evaluated
map_withmodDescription
TRUEnever evaluated
FALSEnever evaluated
(map_withmod->...Map::IsLetter)Description
TRUEnever evaluated
FALSEnever evaluated
0
252 modifiers ^= QEvdevKeyboardMap::ModShift;
never executed: modifiers ^= QEvdevKeyboardMap::ModShift;
0
253-
254 qCDebug(qLcEvdevKeyMap, "Processing key event: keycode=%3d, modifiers=%02x pressed=%d, autorepeat=%d | plain=%d, withmod=%d, size=%d",
never executed: QMessageLogger( __FILE__ , 258 , __PRETTY_FUNCTION__, qLcEvdevKeyMap().categoryName()).debug("Processing key event: keycode=%3d, modifiers=%02x pressed=%d, autorepeat=%d | plain=%d, withmod=%d, size=%d", keycode, modifiers, pressed ? 1 : 0, autorepeat ? 1 : 0, int(map_plain ? map_plain - m_keymap : -1), int(map_withmod ? map_withmod - m_keymap : -1), m_keymap_size) ;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
255 keycode, modifiers, pressed ? 1 : 0, autorepeat ? 1 : 0,
never executed: QMessageLogger( __FILE__ , 258 , __PRETTY_FUNCTION__, qLcEvdevKeyMap().categoryName()).debug("Processing key event: keycode=%3d, modifiers=%02x pressed=%d, autorepeat=%d | plain=%d, withmod=%d, size=%d", keycode, modifiers, pressed ? 1 : 0, autorepeat ? 1 : 0, int(map_plain ? map_plain - m_keymap : -1), int(map_withmod ? map_withmod - m_keymap : -1), m_keymap_size) ;
0
256 int(map_plain ? map_plain - m_keymap : -1),
never executed: QMessageLogger( __FILE__ , 258 , __PRETTY_FUNCTION__, qLcEvdevKeyMap().categoryName()).debug("Processing key event: keycode=%3d, modifiers=%02x pressed=%d, autorepeat=%d | plain=%d, withmod=%d, size=%d", keycode, modifiers, pressed ? 1 : 0, autorepeat ? 1 : 0, int(map_plain ? map_plain - m_keymap : -1), int(map_withmod ? map_withmod - m_keymap : -1), m_keymap_size) ;
0
257 int(map_withmod ? map_withmod - m_keymap : -1),
never executed: QMessageLogger( __FILE__ , 258 , __PRETTY_FUNCTION__, qLcEvdevKeyMap().categoryName()).debug("Processing key event: keycode=%3d, modifiers=%02x pressed=%d, autorepeat=%d | plain=%d, withmod=%d, size=%d", keycode, modifiers, pressed ? 1 : 0, autorepeat ? 1 : 0, int(map_plain ? map_plain - m_keymap : -1), int(map_withmod ? map_withmod - m_keymap : -1), m_keymap_size) ;
0
258 m_keymap_size);
never executed: QMessageLogger( __FILE__ , 258 , __PRETTY_FUNCTION__, qLcEvdevKeyMap().categoryName()).debug("Processing key event: keycode=%3d, modifiers=%02x pressed=%d, autorepeat=%d | plain=%d, withmod=%d, size=%d", keycode, modifiers, pressed ? 1 : 0, autorepeat ? 1 : 0, int(map_plain ? map_plain - m_keymap : -1), int(map_withmod ? map_withmod - m_keymap : -1), m_keymap_size) ;
0
259-
260 const QEvdevKeyboardMap::Mapping *it = map_withmod ? map_withmod : map_plain;
map_withmodDescription
TRUEnever evaluated
FALSEnever evaluated
0
261-
262 if (!it) {
!itDescription
TRUEnever evaluated
FALSEnever evaluated
0
263 // we couldn't even find a plain mapping-
264 qCDebug(qLcEvdevKeyMap, "Could not find a suitable mapping for keycode: %3d, modifiers: %02x", keycode, modifiers);
never executed: QMessageLogger(__FILE__, 264, __PRETTY_FUNCTION__, qLcEvdevKeyMap().categoryName()).debug("Could not find a suitable mapping for keycode: %3d, modifiers: %02x", keycode, modifiers);
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
265 return result;
never executed: return result;
0
266 }-
267-
268 bool skip = false;-
269 quint16 unicode = it->unicode;-
270 quint32 qtcode = it->qtcode;-
271-
272 if ((it->flags & QEvdevKeyboardMap::IsModifier) && it->special) {
(it->flags & Q...p::IsModifier)Description
TRUEnever evaluated
FALSEnever evaluated
it->specialDescription
TRUEnever evaluated
FALSEnever evaluated
0
273 // this is a modifier, i.e. Shift, Alt, ...-
274 if (pressed)
pressedDescription
TRUEnever evaluated
FALSEnever evaluated
0
275 m_modifiers |= quint8(it->special);
never executed: m_modifiers |= quint8(it->special);
0
276 else-
277 m_modifiers &= ~quint8(it->special);
never executed: m_modifiers &= ~quint8(it->special);
0
278 } else if (qtcode >= Qt::Key_CapsLock && qtcode <= Qt::Key_ScrollLock) {
qtcode >= Qt::Key_CapsLockDescription
TRUEnever evaluated
FALSEnever evaluated
qtcode <= Qt::Key_ScrollLockDescription
TRUEnever evaluated
FALSEnever evaluated
0
279 // (Caps|Num|Scroll)Lock-
280 if (first_press) {
first_pressDescription
TRUEnever evaluated
FALSEnever evaluated
0
281 quint8 &lock = m_locks[qtcode - Qt::Key_CapsLock];-
282 lock ^= 1;-
283-
284 switch (qtcode) {-
285 case Qt::Key_CapsLock : result = lock ? CapsLockOn : CapsLockOff; break;
never executed: break;
lockDescription
TRUEnever evaluated
FALSEnever evaluated
never executed: case Qt::Key_CapsLock :
0
286 case Qt::Key_NumLock : result = lock ? NumLockOn : NumLockOff; break;
never executed: break;
lockDescription
TRUEnever evaluated
FALSEnever evaluated
never executed: case Qt::Key_NumLock :
0
287 case Qt::Key_ScrollLock: result = lock ? ScrollLockOn : ScrollLockOff; break;
never executed: break;
lockDescription
TRUEnever evaluated
FALSEnever evaluated
never executed: case Qt::Key_ScrollLock:
0
288 default : break;
never executed: break;
never executed: default :
0
289 }-
290 }-
291 } else if ((it->flags & QEvdevKeyboardMap::IsSystem) && it->special && first_press) {
never executed: end of block
(it->flags & Q...Map::IsSystem)Description
TRUEnever evaluated
FALSEnever evaluated
it->specialDescription
TRUEnever evaluated
FALSEnever evaluated
first_pressDescription
TRUEnever evaluated
FALSEnever evaluated
0
292 switch (it->special) {-
293 case QEvdevKeyboardMap::SystemReboot:
never executed: case QEvdevKeyboardMap::SystemReboot:
0
294 result = Reboot;-
295 break;
never executed: break;
0
296-
297 case QEvdevKeyboardMap::SystemZap:
never executed: case QEvdevKeyboardMap::SystemZap:
0
298 if (!m_no_zap)
!m_no_zapDescription
TRUEnever evaluated
FALSEnever evaluated
0
299 qApp->quit();
never executed: QCoreApplication::instance()->quit();
0
300 break;
never executed: break;
0
301-
302 case QEvdevKeyboardMap::SystemConsolePrevious:
never executed: case QEvdevKeyboardMap::SystemConsolePrevious:
0
303 result = PreviousConsole;-
304 break;
never executed: break;
0
305-
306 case QEvdevKeyboardMap::SystemConsoleNext:
never executed: case QEvdevKeyboardMap::SystemConsoleNext:
0
307 result = NextConsole;-
308 break;
never executed: break;
0
309-
310 default:
never executed: default:
0
311 if (it->special >= QEvdevKeyboardMap::SystemConsoleFirst &&
it->special >=...emConsoleFirstDescription
TRUEnever evaluated
FALSEnever evaluated
0
312 it->special <= QEvdevKeyboardMap::SystemConsoleLast) {
it->special <=...temConsoleLastDescription
TRUEnever evaluated
FALSEnever evaluated
0
313 result = KeycodeAction(SwitchConsoleFirst + ((it->special & QEvdevKeyboardMap::SystemConsoleMask) & SwitchConsoleMask));-
314 }
never executed: end of block
0
315 break;
never executed: break;
0
316 }-
317-
318 skip = true; // no need to tell Qt about it-
319 } else if ((qtcode == Qt::Key_Multi_key) && m_do_compose) {
never executed: end of block
(qtcode == Qt::Key_Multi_key)Description
TRUEnever evaluated
FALSEnever evaluated
m_do_composeDescription
TRUEnever evaluated
FALSEnever evaluated
0
320 // the Compose key was pressed-
321 if (first_press)
first_pressDescription
TRUEnever evaluated
FALSEnever evaluated
0
322 m_composing = 2;
never executed: m_composing = 2;
0
323 skip = true;-
324 } else if ((it->flags & QEvdevKeyboardMap::IsDead) && m_do_compose) {
never executed: end of block
(it->flags & Q...rdMap::IsDead)Description
TRUEnever evaluated
FALSEnever evaluated
m_do_composeDescription
TRUEnever evaluated
FALSEnever evaluated
0
325 // a Dead key was pressed-
326 if (first_press && m_composing == 1 && m_dead_unicode == unicode) { // twice
first_pressDescription
TRUEnever evaluated
FALSEnever evaluated
m_composing == 1Description
TRUEnever evaluated
FALSEnever evaluated
m_dead_unicode == unicodeDescription
TRUEnever evaluated
FALSEnever evaluated
0
327 m_composing = 0;-
328 qtcode = Qt::Key_unknown; // otherwise it would be Qt::Key_Dead...-
329 } else if (first_press && unicode != 0xffff) {
never executed: end of block
first_pressDescription
TRUEnever evaluated
FALSEnever evaluated
unicode != 0xffffDescription
TRUEnever evaluated
FALSEnever evaluated
0
330 m_dead_unicode = unicode;-
331 m_composing = 1;-
332 skip = true;-
333 } else {
never executed: end of block
0
334 skip = true;-
335 }
never executed: end of block
0
336 }-
337-
338 if (!skip) {
!skipDescription
TRUEnever evaluated
FALSEnever evaluated
0
339 // a normal key was pressed-
340 const int modmask = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier | Qt::KeypadModifier;-
341-
342 // we couldn't find a specific mapping for the current modifiers,-
343 // or that mapping didn't have special modifiers:-
344 // so just report the plain mapping with additional modifiers.-
345 if ((it == map_plain && it != map_withmod) ||
it == map_plainDescription
TRUEnever evaluated
FALSEnever evaluated
it != map_withmodDescription
TRUEnever evaluated
FALSEnever evaluated
0
346 (map_withmod && !(map_withmod->qtcode & modmask))) {
map_withmodDescription
TRUEnever evaluated
FALSEnever evaluated
!(map_withmod-...ode & modmask)Description
TRUEnever evaluated
FALSEnever evaluated
0
347 qtcode |= QEvdevKeyboardHandler::toQtModifiers(modifiers);-
348 }
never executed: end of block
0
349-
350 if (m_composing == 2 && first_press && !(it->flags & QEvdevKeyboardMap::IsModifier)) {
m_composing == 2Description
TRUEnever evaluated
FALSEnever evaluated
first_pressDescription
TRUEnever evaluated
FALSEnever evaluated
!(it->flags & ...p::IsModifier)Description
TRUEnever evaluated
FALSEnever evaluated
0
351 // the last key press was the Compose key-
352 if (unicode != 0xffff) {
unicode != 0xffffDescription
TRUEnever evaluated
FALSEnever evaluated
0
353 int idx = 0;-
354 // check if this code is in the compose table at all-
355 for ( ; idx < m_keycompose_size; ++idx) {
idx < m_keycompose_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
356 if (m_keycompose[idx].first == unicode)
m_keycompose[i...rst == unicodeDescription
TRUEnever evaluated
FALSEnever evaluated
0
357 break;
never executed: break;
0
358 }
never executed: end of block
0
359 if (idx < m_keycompose_size) {
idx < m_keycompose_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
360 // found it -> simulate a Dead key press-
361 m_dead_unicode = unicode;-
362 unicode = 0xffff;-
363 m_composing = 1;-
364 skip = true;-
365 } else {
never executed: end of block
0
366 m_composing = 0;-
367 }
never executed: end of block
0
368 } else {-
369 m_composing = 0;-
370 }
never executed: end of block
0
371 } else if (m_composing == 1 && first_press && !(it->flags & QEvdevKeyboardMap::IsModifier)) {
m_composing == 1Description
TRUEnever evaluated
FALSEnever evaluated
first_pressDescription
TRUEnever evaluated
FALSEnever evaluated
!(it->flags & ...p::IsModifier)Description
TRUEnever evaluated
FALSEnever evaluated
0
372 // the last key press was a Dead key-
373 bool valid = false;-
374 if (unicode != 0xffff) {
unicode != 0xffffDescription
TRUEnever evaluated
FALSEnever evaluated
0
375 int idx = 0;-
376 // check if this code is in the compose table at all-
377 for ( ; idx < m_keycompose_size; ++idx) {
idx < m_keycompose_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
378 if (m_keycompose[idx].first == m_dead_unicode && m_keycompose[idx].second == unicode)
m_keycompose[i...m_dead_unicodeDescription
TRUEnever evaluated
FALSEnever evaluated
m_keycompose[i...ond == unicodeDescription
TRUEnever evaluated
FALSEnever evaluated
0
379 break;
never executed: break;
0
380 }
never executed: end of block
0
381 if (idx < m_keycompose_size) {
idx < m_keycompose_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
382 quint16 composed = m_keycompose[idx].result;-
383 if (composed != 0xffff) {
composed != 0xffffDescription
TRUEnever evaluated
FALSEnever evaluated
0
384 unicode = composed;-
385 qtcode = Qt::Key_unknown;-
386 valid = true;-
387 }
never executed: end of block
0
388 }
never executed: end of block
0
389 }
never executed: end of block
0
390 if (!valid) {
!validDescription
TRUEnever evaluated
FALSEnever evaluated
0
391 unicode = m_dead_unicode;-
392 qtcode = Qt::Key_unknown;-
393 }
never executed: end of block
0
394 m_composing = 0;-
395 }
never executed: end of block
0
396-
397 if (!skip) {
!skipDescription
TRUEnever evaluated
FALSEnever evaluated
0
398 // Up until now qtcode contained both the key and modifiers. Split it.-
399 Qt::KeyboardModifiers qtmods = Qt::KeyboardModifiers(qtcode & modmask);-
400 qtcode &= ~modmask;-
401-
402 qCDebug(qLcEvdevKeyMap, "Processing: uni=%04x, qt=%08x, qtmod=%08x", unicode, qtcode, int(qtmods));
never executed: QMessageLogger(__FILE__, 402, __PRETTY_FUNCTION__, qLcEvdevKeyMap().categoryName()).debug("Processing: uni=%04x, qt=%08x, qtmod=%08x", unicode, qtcode, int(qtmods));
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
403-
404 // If NumLockOff and keypad key pressed remap event sent-
405 if (!m_locks[1] && (qtmods & Qt::KeypadModifier) &&
!m_locks[1]Description
TRUEnever evaluated
FALSEnever evaluated
(qtmods & Qt::KeypadModifier)Description
TRUEnever evaluated
FALSEnever evaluated
0
406 keycode >= 71 &&
keycode >= 71Description
TRUEnever evaluated
FALSEnever evaluated
0
407 keycode <= 83 &&
keycode <= 83Description
TRUEnever evaluated
FALSEnever evaluated
0
408 keycode != 74 &&
keycode != 74Description
TRUEnever evaluated
FALSEnever evaluated
0
409 keycode != 78) {
keycode != 78Description
TRUEnever evaluated
FALSEnever evaluated
0
410-
411 unicode = 0xffff;-
412 switch (keycode) {-
413 case 71: //7 --> Home
never executed: case 71:
0
414 qtcode = Qt::Key_Home;-
415 break;
never executed: break;
0
416 case 72: //8 --> Up
never executed: case 72:
0
417 qtcode = Qt::Key_Up;-
418 break;
never executed: break;
0
419 case 73: //9 --> PgUp
never executed: case 73:
0
420 qtcode = Qt::Key_PageUp;-
421 break;
never executed: break;
0
422 case 75: //4 --> Left
never executed: case 75:
0
423 qtcode = Qt::Key_Left;-
424 break;
never executed: break;
0
425 case 76: //5 --> Clear
never executed: case 76:
0
426 qtcode = Qt::Key_Clear;-
427 break;
never executed: break;
0
428 case 77: //6 --> right
never executed: case 77:
0
429 qtcode = Qt::Key_Right;-
430 break;
never executed: break;
0
431 case 79: //1 --> End
never executed: case 79:
0
432 qtcode = Qt::Key_End;-
433 break;
never executed: break;
0
434 case 80: //2 --> Down
never executed: case 80:
0
435 qtcode = Qt::Key_Down;-
436 break;
never executed: break;
0
437 case 81: //3 --> PgDn
never executed: case 81:
0
438 qtcode = Qt::Key_PageDown;-
439 break;
never executed: break;
0
440 case 82: //0 --> Ins
never executed: case 82:
0
441 qtcode = Qt::Key_Insert;-
442 break;
never executed: break;
0
443 case 83: //, --> Del
never executed: case 83:
0
444 qtcode = Qt::Key_Delete;-
445 break;
never executed: break;
0
446 }-
447 }
never executed: end of block
0
448-
449 // Map SHIFT + Tab to SHIFT + Backtab, QShortcutMap knows about this translation-
450 if (qtcode == Qt::Key_Tab && (qtmods & Qt::ShiftModifier) == Qt::ShiftModifier)
qtcode == Qt::Key_TabDescription
TRUEnever evaluated
FALSEnever evaluated
(qtmods & Qt::...:ShiftModifierDescription
TRUEnever evaluated
FALSEnever evaluated
0
451 qtcode = Qt::Key_Backtab;
never executed: qtcode = Qt::Key_Backtab;
0
452-
453 // Generate the QPA event.-
454 processKeyEvent(keycode, unicode, qtcode, qtmods, pressed, autorepeat);-
455 }
never executed: end of block
0
456 }
never executed: end of block
0
457 return result;
never executed: return result;
0
458}-
459-
460void QEvdevKeyboardHandler::unloadKeymap()-
461{-
462 qCDebug(qLcEvdevKey) << "Unload current keymap and restore built-in";
never executed: QMessageLogger(__FILE__, 462, __PRETTY_FUNCTION__, qLcEvdevKey().categoryName()).debug() << "Unload current keymap and restore built-in";
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
463-
464 if (m_keymap && m_keymap != s_keymap_default)
m_keymapDescription
TRUEnever evaluated
FALSEnever evaluated
m_keymap != s_keymap_defaultDescription
TRUEnever evaluated
FALSEnever evaluated
0
465 delete [] m_keymap;
never executed: delete [] m_keymap;
0
466 if (m_keycompose && m_keycompose != s_keycompose_default)
m_keycomposeDescription
TRUEnever evaluated
FALSEnever evaluated
m_keycompose !...ompose_defaultDescription
TRUEnever evaluated
FALSEnever evaluated
0
467 delete [] m_keycompose;
never executed: delete [] m_keycompose;
0
468-
469 m_keymap = s_keymap_default;-
470 m_keymap_size = sizeof(s_keymap_default) / sizeof(s_keymap_default[0]);-
471 m_keycompose = s_keycompose_default;-
472 m_keycompose_size = sizeof(s_keycompose_default) / sizeof(s_keycompose_default[0]);-
473-
474 // reset state, so we could switch keymaps at runtime-
475 m_modifiers = 0;-
476 memset(m_locks, 0, sizeof(m_locks));-
477 m_composing = 0;-
478 m_dead_unicode = 0xffff;-
479-
480 //Set locks according to keyboard leds-
481 quint16 ledbits[1];-
482 memset(ledbits, 0, sizeof(ledbits));-
483 if (::ioctl(m_fd.get(), EVIOCGLED(sizeof(ledbits)), ledbits) < 0) {
::ioctl(m_fd.g..., ledbits) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
484 qWarning("evdevkeyboard: Failed to query led states");-
485 switchLed(LED_NUML,false);-
486 switchLed(LED_CAPSL, false);-
487 switchLed(LED_SCROLLL,false);-
488 } else {
never executed: end of block
0
489 //Capslock-
490 if ((ledbits[0]&0x02) > 0)
(ledbits[0]&0x02) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
491 m_locks[0] = 1;
never executed: m_locks[0] = 1;
0
492 //Numlock-
493 if ((ledbits[0]&0x01) > 0)
(ledbits[0]&0x01) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
494 m_locks[1] = 1;
never executed: m_locks[1] = 1;
0
495 //Scrollock-
496 if ((ledbits[0]&0x04) > 0)
(ledbits[0]&0x04) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
497 m_locks[2] = 1;
never executed: m_locks[2] = 1;
0
498 qCDebug(qLcEvdevKey, "numlock=%d , capslock=%d, scrolllock=%d", m_locks[1], m_locks[0], m_locks[2]);
never executed: QMessageLogger(__FILE__, 498, __PRETTY_FUNCTION__, qLcEvdevKey().categoryName()).debug("numlock=%d , capslock=%d, scrolllock=%d", m_locks[1], m_locks[0], m_locks[2]);
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
499 }
never executed: end of block
0
500}-
501-
502bool QEvdevKeyboardHandler::loadKeymap(const QString &file)-
503{-
504 qCDebug(qLcEvdevKey) << "Loading keymap" << file;
never executed: QMessageLogger(__FILE__, 504, __PRETTY_FUNCTION__, qLcEvdevKey().categoryName()).debug() << "Loading keymap" << file;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
505-
506 QFile f(file);-
507-
508 if (!f.open(QIODevice::ReadOnly)) {
!f.open(QIODevice::ReadOnly)Description
TRUEnever evaluated
FALSEnever evaluated
0
509 qWarning("Could not open keymap file '%s'", qPrintable(file));-
510 return false;
never executed: return false;
0
511 }-
512-
513 // .qmap files have a very simple structure:-
514 // quint32 magic (QKeyboard::FileMagic)-
515 // quint32 version (1)-
516 // quint32 keymap_size (# of struct QKeyboard::Mappings)-
517 // quint32 keycompose_size (# of struct QKeyboard::Composings)-
518 // all QKeyboard::Mappings via QDataStream::operator(<<|>>)-
519 // all QKeyboard::Composings via QDataStream::operator(<<|>>)-
520-
521 quint32 qmap_magic, qmap_version, qmap_keymap_size, qmap_keycompose_size;-
522-
523 QDataStream ds(&f);-
524-
525 ds >> qmap_magic >> qmap_version >> qmap_keymap_size >> qmap_keycompose_size;-
526-
527 if (ds.status() != QDataStream::Ok || qmap_magic != QEvdevKeyboardMap::FileMagic || qmap_version != 1 || qmap_keymap_size == 0) {
ds.status() != QDataStream::OkDescription
TRUEnever evaluated
FALSEnever evaluated
qmap_magic != ...Map::FileMagicDescription
TRUEnever evaluated
FALSEnever evaluated
qmap_version != 1Description
TRUEnever evaluated
FALSEnever evaluated
qmap_keymap_size == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
528 qWarning("'%s' is not a valid .qmap keymap file", qPrintable(file));-
529 return false;
never executed: return false;
0
530 }-
531-
532 QEvdevKeyboardMap::Mapping *qmap_keymap = new QEvdevKeyboardMap::Mapping[qmap_keymap_size];-
533 QEvdevKeyboardMap::Composing *qmap_keycompose = qmap_keycompose_size ? new QEvdevKeyboardMap::Composing[qmap_keycompose_size] : 0;
qmap_keycompose_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
534-
535 for (quint32 i = 0; i < qmap_keymap_size; ++i)
i < qmap_keymap_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
536 ds >> qmap_keymap[i];
never executed: ds >> qmap_keymap[i];
0
537 for (quint32 i = 0; i < qmap_keycompose_size; ++i)
i < qmap_keycompose_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
538 ds >> qmap_keycompose[i];
never executed: ds >> qmap_keycompose[i];
0
539-
540 if (ds.status() != QDataStream::Ok) {
ds.status() != QDataStream::OkDescription
TRUEnever evaluated
FALSEnever evaluated
0
541 delete [] qmap_keymap;-
542 delete [] qmap_keycompose;-
543-
544 qWarning("Keymap file '%s' can not be loaded.", qPrintable(file));-
545 return false;
never executed: return false;
0
546 }-
547-
548 // unload currently active and clear state-
549 unloadKeymap();-
550-
551 m_keymap = qmap_keymap;-
552 m_keymap_size = qmap_keymap_size;-
553 m_keycompose = qmap_keycompose;-
554 m_keycompose_size = qmap_keycompose_size;-
555-
556 m_do_compose = true;-
557-
558 return true;
never executed: return true;
0
559}-
560-
561QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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