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")-
57Q_LOGGING_CATEGORY(qLcEvdevKeyMap, "qt.qpa.input.keymap")-
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;-
76-
77 setObjectName(QLatin1String("LinuxInput Keyboard Handler"));-
78-
79 memset(m_locks, 0, sizeof(m_locks));-
80-
81 if (keymapFile.isEmpty() || !loadKeymap(keymapFile))-
82 unloadKeymap();-
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}-
88-
89QEvdevKeyboardHandler::~QEvdevKeyboardHandler()-
90{-
91 unloadKeymap();-
92}-
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 QStringListconst auto args = specification.splitsplitRef(QLatin1Char(':'));-
108 foreachfor (const QStringQStringRef &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;-
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}-
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) {-
162 qWarning("evdevkeyboard: Got EOF from the input device");-
163 return;-
164 } else if (result < 0) {-
165 if (errno != EINTR && errno != EAGAIN) {-
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) {-
170 delete m_notify;-
171 m_notify = Q_NULLPTR;-
172 m_fd.reset();-
173 }-
174 return;-
175 }-
176 } else {-
177 n += result;-
178 if (n % sizeof(buffer[0]) == 0)-
179 break;-
180 }-
181 }-
182-
183 n /= sizeof(buffer[0]);-
184-
185 for (int i = 0; i < n; ++i) {-
186 if (buffer[i].type != EV_KEY)-
187 continue;-
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:-
197 case QEvdevKeyboardHandler::CapsLockOff:-
198 switchLed(LED_CAPSL, ka == QEvdevKeyboardHandler::CapsLockOn);-
199 break;-
200-
201 case QEvdevKeyboardHandler::NumLockOn:-
202 case QEvdevKeyboardHandler::NumLockOff:-
203 switchLed(LED_NUML, ka == QEvdevKeyboardHandler::NumLockOn);-
204 break;-
205-
206 case QEvdevKeyboardHandler::ScrollLockOn:-
207 case QEvdevKeyboardHandler::ScrollLockOff:-
208 switchLed(LED_SCROLLL, ka == QEvdevKeyboardHandler::ScrollLockOn);-
209 break;-
210-
211 default:-
212 // ignore console switching and reboot-
213 break;-
214 }-
215 }-
216}-
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}-
225-
226QEvdevKeyboardHandler::KeycodeAction QEvdevKeyboardHandler::processKeycode(quint16 keycode, bool pressed, bool autorepeat)-
227{-
228 KeycodeAction result = None;-
229 bool first_press = pressed && !autorepeat;-
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) {-
238 const QEvdevKeyboardMap::Mapping *m = m_keymap + i;-
239 if (m->keycode == keycode) {-
240 if (m->modifiers == 0)-
241 map_plain = m;-
242-
243 quint8 testmods = m_modifiers;-
244 if (m_locks[0] /*CapsLock*/ && (m->flags & QEvdevKeyboardMap::IsLetter))-
245 testmods ^= QEvdevKeyboardMap::ModShift;-
246 if (m->modifiers == testmods)-
247 map_withmod = m;-
248 }-
249 }-
250-
251 if (m_locks[0] /*CapsLock*/ && map_withmod && (map_withmod->flags & QEvdevKeyboardMap::IsLetter))-
252 modifiers ^= QEvdevKeyboardMap::ModShift;-
253-
254 qCDebug(qLcEvdevKeyMap, "Processing key event: keycode=%3d, modifiers=%02x pressed=%d, autorepeat=%d | plain=%d, withmod=%d, size=%d",-
255 keycode, modifiers, pressed ? 1 : 0, autorepeat ? 1 : 0,-
256 int(map_plain ? map_plain - m_keymap : -1),-
257 int(map_withmod ? map_withmod - m_keymap : -1),-
258 m_keymap_size);-
259-
260 const QEvdevKeyboardMap::Mapping *it = map_withmod ? map_withmod : map_plain;-
261-
262 if (!it) {-
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);-
265 return result;-
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) {-
273 // this is a modifier, i.e. Shift, Alt, ...-
274 if (pressed)-
275 m_modifiers |= quint8(it->special);-
276 else-
277 m_modifiers &= ~quint8(it->special);-
278 } else if (qtcode >= Qt::Key_CapsLock && qtcode <= Qt::Key_ScrollLock) {-
279 // (Caps|Num|Scroll)Lock-
280 if (first_press) {-
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;-
286 case Qt::Key_NumLock : result = lock ? NumLockOn : NumLockOff; break;-
287 case Qt::Key_ScrollLock: result = lock ? ScrollLockOn : ScrollLockOff; break;-
288 default : break;-
289 }-
290 }-
291 } else if ((it->flags & QEvdevKeyboardMap::IsSystem) && it->special && first_press) {-
292 switch (it->special) {-
293 case QEvdevKeyboardMap::SystemReboot:-
294 result = Reboot;-
295 break;-
296-
297 case QEvdevKeyboardMap::SystemZap:-
298 if (!m_no_zap)-
299 qApp->quit();-
300 break;-
301-
302 case QEvdevKeyboardMap::SystemConsolePrevious:-
303 result = PreviousConsole;-
304 break;-
305-
306 case QEvdevKeyboardMap::SystemConsoleNext:-
307 result = NextConsole;-
308 break;-
309-
310 default:-
311 if (it->special >= QEvdevKeyboardMap::SystemConsoleFirst &&-
312 it->special <= QEvdevKeyboardMap::SystemConsoleLast) {-
313 result = KeycodeAction(SwitchConsoleFirst + ((it->special & QEvdevKeyboardMap::SystemConsoleMask) & SwitchConsoleMask));-
314 }-
315 break;-
316 }-
317-
318 skip = true; // no need to tell Qt about it-
319 } else if ((qtcode == Qt::Key_Multi_key) && m_do_compose) {-
320 // the Compose key was pressed-
321 if (first_press)-
322 m_composing = 2;-
323 skip = true;-
324 } else if ((it->flags & QEvdevKeyboardMap::IsDead) && m_do_compose) {-
325 // a Dead key was pressed-
326 if (first_press && m_composing == 1 && m_dead_unicode == unicode) { // twice-
327 m_composing = 0;-
328 qtcode = Qt::Key_unknown; // otherwise it would be Qt::Key_Dead...-
329 } else if (first_press && unicode != 0xffff) {-
330 m_dead_unicode = unicode;-
331 m_composing = 1;-
332 skip = true;-
333 } else {-
334 skip = true;-
335 }-
336 }-
337-
338 if (!skip) {-
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) ||-
346 (map_withmod && !(map_withmod->qtcode & modmask))) {-
347 qtcode |= QEvdevKeyboardHandler::toQtModifiers(modifiers);-
348 }-
349-
350 if (m_composing == 2 && first_press && !(it->flags & QEvdevKeyboardMap::IsModifier)) {-
351 // the last key press was the Compose key-
352 if (unicode != 0xffff) {-
353 int idx = 0;-
354 // check if this code is in the compose table at all-
355 for ( ; idx < m_keycompose_size; ++idx) {-
356 if (m_keycompose[idx].first == unicode)-
357 break;-
358 }-
359 if (idx < m_keycompose_size) {-
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 {-
366 m_composing = 0;-
367 }-
368 } else {-
369 m_composing = 0;-
370 }-
371 } else if (m_composing == 1 && first_press && !(it->flags & QEvdevKeyboardMap::IsModifier)) {-
372 // the last key press was a Dead key-
373 bool valid = false;-
374 if (unicode != 0xffff) {-
375 int idx = 0;-
376 // check if this code is in the compose table at all-
377 for ( ; idx < m_keycompose_size; ++idx) {-
378 if (m_keycompose[idx].first == m_dead_unicode && m_keycompose[idx].second == unicode)-
379 break;-
380 }-
381 if (idx < m_keycompose_size) {-
382 quint16 composed = m_keycompose[idx].result;-
383 if (composed != 0xffff) {-
384 unicode = composed;-
385 qtcode = Qt::Key_unknown;-
386 valid = true;-
387 }-
388 }-
389 }-
390 if (!valid) {-
391 unicode = m_dead_unicode;-
392 qtcode = Qt::Key_unknown;-
393 }-
394 m_composing = 0;-
395 }-
396-
397 if (!skip) {-
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));-
403-
404 // If NumLockOff and keypad key pressed remap event sent-
405 if (!m_locks[1] && (qtmods & Qt::KeypadModifier) &&-
406 keycode >= 71 &&-
407 keycode <= 83 &&-
408 keycode != 74 &&-
409 keycode != 78) {-
410-
411 unicode = 0xffff;-
412 switch (keycode) {-
413 case 71: //7 --> Home-
414 qtcode = Qt::Key_Home;-
415 break;-
416 case 72: //8 --> Up-
417 qtcode = Qt::Key_Up;-
418 break;-
419 case 73: //9 --> PgUp-
420 qtcode = Qt::Key_PageUp;-
421 break;-
422 case 75: //4 --> Left-
423 qtcode = Qt::Key_Left;-
424 break;-
425 case 76: //5 --> Clear-
426 qtcode = Qt::Key_Clear;-
427 break;-
428 case 77: //6 --> right-
429 qtcode = Qt::Key_Right;-
430 break;-
431 case 79: //1 --> End-
432 qtcode = Qt::Key_End;-
433 break;-
434 case 80: //2 --> Down-
435 qtcode = Qt::Key_Down;-
436 break;-
437 case 81: //3 --> PgDn-
438 qtcode = Qt::Key_PageDown;-
439 break;-
440 case 82: //0 --> Ins-
441 qtcode = Qt::Key_Insert;-
442 break;-
443 case 83: //, --> Del-
444 qtcode = Qt::Key_Delete;-
445 break;-
446 }-
447 }-
448-
449 // Map SHIFT + Tab to SHIFT + Backtab, QShortcutMap knows about this translation-
450 if (qtcode == Qt::Key_Tab && (qtmods & Qt::ShiftModifier) == Qt::ShiftModifier)-
451 qtcode = Qt::Key_Backtab;-
452-
453 // Generate the QPA event.-
454 processKeyEvent(keycode, unicode, qtcode, qtmods, pressed, autorepeat);-
455 }-
456 }-
457 return result;-
458}-
459-
460void QEvdevKeyboardHandler::unloadKeymap()-
461{-
462 qCDebug(qLcEvdevKey) << "Unload current keymap and restore built-in";-
463-
464 if (m_keymap && m_keymap != s_keymap_default)-
465 delete [] m_keymap;-
466 if (m_keycompose && m_keycompose != s_keycompose_default)-
467 delete [] m_keycompose;-
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) {-
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 {-
489 //Capslock-
490 if ((ledbits[0]&0x02) > 0)-
491 m_locks[0] = 1;-
492 //Numlock-
493 if ((ledbits[0]&0x01) > 0)-
494 m_locks[1] = 1;-
495 //Scrollock-
496 if ((ledbits[0]&0x04) > 0)-
497 m_locks[2] = 1;-
498 qCDebug(qLcEvdevKey, "numlock=%d , capslock=%d, scrolllock=%d", m_locks[1], m_locks[0], m_locks[2]);-
499 }-
500}-
501-
502bool QEvdevKeyboardHandler::loadKeymap(const QString &file)-
503{-
504 qCDebug(qLcEvdevKey) << "Loading keymap" << file;-
505-
506 QFile f(file);-
507-
508 if (!f.open(QIODevice::ReadOnly)) {-
509 qWarning("Could not open keymap file '%s'", qPrintable(file));-
510 return false;-
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) {-
528 qWarning("'%s' is not a valid .qmap keymap file", qPrintable(file));-
529 return false;-
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;-
534-
535 for (quint32 i = 0; i < qmap_keymap_size; ++i)-
536 ds >> qmap_keymap[i];-
537 for (quint32 i = 0; i < qmap_keycompose_size; ++i)-
538 ds >> qmap_keycompose[i];-
539-
540 if (ds.status() != QDataStream::Ok) {-
541 delete [] qmap_keymap;-
542 delete [] qmap_keycompose;-
543-
544 qWarning("Keymap file '%s' can not be loaded.", qPrintable(file));-
545 return false;-
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;-
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