diff options
Diffstat (limited to 'src/platformsupport/input/evdevkeyboard')
4 files changed, 108 insertions, 6 deletions
diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp index 0841544208..9c44283b0e 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp @@ -93,13 +93,15 @@ QEvdevKeyboardHandler::~QEvdevKeyboardHandler() qt_safe_close(m_fd); } -QEvdevKeyboardHandler *QEvdevKeyboardHandler::create(const QString &device, const QString &specification) +QEvdevKeyboardHandler *QEvdevKeyboardHandler::create(const QString &device, + const QString &specification, + const QString &defaultKeymapFile) { #ifdef QT_QPA_KEYMAP_DEBUG qWarning() << "Try to create keyboard handler for" << device << specification; #endif - QString keymapFile; + QString keymapFile = defaultKeymapFile; int repeatDelay = 400; int repeatRate = 80; bool disableZap = false; @@ -406,6 +408,53 @@ QEvdevKeyboardHandler::KeycodeAction QEvdevKeyboardHandler::processKeycode(quint #ifdef QT_QPA_KEYMAP_DEBUG qWarning("Processing: uni=%04x, qt=%08x, qtmod=%08x", unicode, qtcode & ~modmask, (qtcode & modmask)); #endif + //If NumLockOff and keypad key pressed remap event sent + if (!m_locks[1] && + (qtcode & Qt::KeypadModifier) && + keycode >= 71 && + keycode <= 83 && + keycode != 74 && + keycode != 78) { + + unicode = 0xffff; + int oldMask = (qtcode & modmask); + switch (keycode) { + case 71: //7 --> Home + qtcode = Qt::Key_Home; + break; + case 72: //8 --> Up + qtcode = Qt::Key_Up; + break; + case 73: //9 --> PgUp + qtcode = Qt::Key_PageUp; + break; + case 75: //4 --> Left + qtcode = Qt::Key_Left; + break; + case 76: //5 --> Clear + qtcode = Qt::Key_Clear; + break; + case 77: //6 --> right + qtcode = Qt::Key_Right; + break; + case 79: //1 --> End + qtcode = Qt::Key_End; + break; + case 80: //2 --> Down + qtcode = Qt::Key_Down; + break; + case 81: //3 --> PgDn + qtcode = Qt::Key_PageDown; + break; + case 82: //0 --> Ins + qtcode = Qt::Key_Insert; + break; + case 83: //, --> Del + qtcode = Qt::Key_Delete; + break; + } + qtcode ^= oldMask; + } // send the result to the server processKeyEvent(keycode, unicode, qtcode & ~modmask, Qt::KeyboardModifiers(qtcode & modmask), pressed, autorepeat); @@ -435,6 +484,29 @@ void QEvdevKeyboardHandler::unloadKeymap() memset(m_locks, 0, sizeof(m_locks)); m_composing = 0; m_dead_unicode = 0xffff; + + //Set locks according to keyboard leds + quint16 ledbits[1]; + memset(ledbits, 0, sizeof(ledbits)); + if (::ioctl(m_fd, EVIOCGLED(sizeof(ledbits)), ledbits) < 0) { + qWarning("Failed to query led states. Settings numlock & capslock off"); + switchLed(LED_NUML,false); + switchLed(LED_CAPSL, false); + switchLed(LED_SCROLLL,false); + } else { + //Capslock + if ((ledbits[0]&0x02) > 0) + m_locks[0] = 1; + //Numlock + if ((ledbits[0]&0x01) > 0) + m_locks[1] = 1; + //Scrollock + if ((ledbits[0]&0x04) > 0) + m_locks[2] = 1; +#ifdef QT_QPA_KEYMAP_DEBUG + qWarning("numlock=%d , capslock=%d, scrolllock=%d",m_locks[1],m_locks[0],m_locks[2]); +#endif + } } bool QEvdevKeyboardHandler::loadKeymap(const QString &file) diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h index 81bc2f6154..06b7818135 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h @@ -156,7 +156,9 @@ public: SwitchConsoleMask = 0x0000007f }; - static QEvdevKeyboardHandler *create(const QString &device, const QString &specification); + static QEvdevKeyboardHandler *create(const QString &device, + const QString &specification, + const QString &defaultKeymapFile = QString()); static Qt::KeyboardModifiers toQtModifiers(quint8 mod) { @@ -172,13 +174,14 @@ public: return qtmod; } + bool loadKeymap(const QString &file); + void unloadKeymap(); + private slots: void readKeycode(); KeycodeAction processKeycode(quint16 keycode, bool pressed, bool autorepeat); private: - void unloadKeymap(); - bool loadKeymap(const QString &file); void processKeyEvent(int nativecode, int unicode, int qtcode, Qt::KeyboardModifiers modifiers, bool isPress, bool autoRepeat); void switchLed(int, bool); diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp index 4932087c5f..4ceaf98055 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp @@ -113,7 +113,7 @@ void QEvdevKeyboardManager::addKeyboard(const QString &deviceNode) #endif QEvdevKeyboardHandler *keyboard; - keyboard = QEvdevKeyboardHandler::create(deviceNode, m_spec); + keyboard = QEvdevKeyboardHandler::create(deviceNode, m_spec, m_defaultKeymapFile); if (keyboard) m_keyboards.insert(deviceNode, keyboard); else @@ -132,4 +132,28 @@ void QEvdevKeyboardManager::removeKeyboard(const QString &deviceNode) } } +void QEvdevKeyboardManager::loadKeymap(const QString &file) +{ + m_defaultKeymapFile = file; + + if (file.isEmpty()) { + // Restore the default, which is either the built-in keymap or + // the one given in the plugin spec. + QString keymapFromSpec; + foreach (const QString &arg, m_spec.split(QLatin1Char(':'))) { + if (arg.startsWith(QLatin1String("keymap="))) + keymapFromSpec = arg.mid(7); + } + foreach (QEvdevKeyboardHandler *handler, m_keyboards) { + if (keymapFromSpec.isEmpty()) + handler->unloadKeymap(); + else + handler->loadKeymap(keymapFromSpec); + } + } else { + foreach (QEvdevKeyboardHandler *handler, m_keyboards) + handler->loadKeymap(file); + } +} + QT_END_NAMESPACE diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager_p.h b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager_p.h index 0b1ccc23ab..c59de3ca09 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager_p.h +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager_p.h @@ -70,6 +70,8 @@ public: QEvdevKeyboardManager(const QString &key, const QString &specification, QObject *parent = 0); ~QEvdevKeyboardManager(); + void loadKeymap(const QString &file); + private slots: void addKeyboard(const QString &deviceNode = QString()); void removeKeyboard(const QString &deviceNode); @@ -78,6 +80,7 @@ private: QString m_spec; QHash<QString,QEvdevKeyboardHandler*> m_keyboards; QDeviceDiscovery *m_deviceDiscovery; + QString m_defaultKeymapFile; }; QT_END_NAMESPACE |