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