From 186354ee513b13dafa77978cb4c10321950600de Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 17 Jun 2014 12:28:15 +0200 Subject: [PATCH] Add a way to access loadKeymap on eglfs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ChangeLog][QtGui] Keymaps are now changeable at runtime when using eglfs Task-number: QTBUG-39583 Change-Id: I93480da72c1d1d1db1914298fe624cae02b0b2d0 Reviewed-by: Jørgen Lind Reviewed-by: Will Wagner --- .../eglfsfunctions/eglfsfunctions.pri | 1 + .../eglfsfunctions/qeglfsfunctions.h | 67 +++++++++++++++++++ .../eglfsfunctions/qeglfsfunctions.qdoc | 63 +++++++++++++++++ src/platformheaders/platformheaders.pro | 1 + .../qeglplatformintegration.cpp | 31 ++++++++- .../qeglplatformintegration_p.h | 6 ++ .../evdevkeyboard/qevdevkeyboardhandler.cpp | 6 +- .../evdevkeyboard/qevdevkeyboardhandler_p.h | 9 ++- .../evdevkeyboard/qevdevkeyboardmanager.cpp | 26 ++++++- .../evdevkeyboard/qevdevkeyboardmanager_p.h | 3 + 10 files changed, 205 insertions(+), 8 deletions(-) create mode 100644 src/platformheaders/eglfsfunctions/eglfsfunctions.pri create mode 100644 src/platformheaders/eglfsfunctions/qeglfsfunctions.h create mode 100644 src/platformheaders/eglfsfunctions/qeglfsfunctions.qdoc diff --git a/src/platformheaders/eglfsfunctions/eglfsfunctions.pri b/src/platformheaders/eglfsfunctions/eglfsfunctions.pri new file mode 100644 index 0000000000..e4e645f5a5 --- /dev/null +++ b/src/platformheaders/eglfsfunctions/eglfsfunctions.pri @@ -0,0 +1 @@ +HEADERS += $$PWD/qeglfsfunctions.h diff --git a/src/platformheaders/eglfsfunctions/qeglfsfunctions.h b/src/platformheaders/eglfsfunctions/qeglfsfunctions.h new file mode 100644 index 0000000000..702d0b2f8c --- /dev/null +++ b/src/platformheaders/eglfsfunctions/qeglfsfunctions.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QEGLFSFUNCTIONS_H +#define QEGLFSFUNCTIONS_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QEglFSFunctions +{ +public: + typedef void (*LoadKeymapType)(const QString &filename); + static QByteArray loadKeymapTypeIdentifier() { return QByteArrayLiteral("EglFSLoadKeymap"); } + + static void loadKeymap(const QString &filename) + { + LoadKeymapType func = reinterpret_cast(QGuiApplication::platformFunction(loadKeymapTypeIdentifier())); + if (func) + func(filename); + } +}; + + +QT_END_NAMESPACE + +#endif // QEGLFSFUNCTIONS_H diff --git a/src/platformheaders/eglfsfunctions/qeglfsfunctions.qdoc b/src/platformheaders/eglfsfunctions/qeglfsfunctions.qdoc new file mode 100644 index 0000000000..16abd32f38 --- /dev/null +++ b/src/platformheaders/eglfsfunctions/qeglfsfunctions.qdoc @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \class QEglFSFunctions + \inmodule QtPlatformHeaders + + \brief The QEglFSFunctions class is an inline class containing + platform-specific functionality for the eglfs platform plugin that is + typically used on systems running Embedded Linux or Android. +*/ + +/*! + \typedef QEglFSFunctions::LoadKeymapType + + Function type for loadKeymap. +*/ + +/*! + \fn QByteArray QEglFSFunctions::loadKeymapTypeIdentifier() + + \return the identifier that can be passed to + QGuiApplication::platformFunction() to query the entry point for the + loadKeymap function implementation. +*/ + +/*! + \fn void QEglFSFunctions::loadKeymap(const QString &filename) + + Loads and switches to the keymap from \a filename. When \a filename is + empty, the default keymap, which is either the built-on one or the keymap + given in the plugin specification, is restored. + + \note This is functional only when the evdev keyboard support code is + compiled in to the platform plugin. When using external generic plugins via + the \c{-plugin} argument, or when the environment variable + \c{QT_QPA_EGLFS_DISABLE_INPUT} is set or when building Qt without evdev + support, this function will have no effect. +*/ diff --git a/src/platformheaders/platformheaders.pro b/src/platformheaders/platformheaders.pro index f99afc4998..a3132ecf23 100644 --- a/src/platformheaders/platformheaders.pro +++ b/src/platformheaders/platformheaders.pro @@ -5,6 +5,7 @@ MODULE_INCNAME = QtPlatformHeaders include(nativecontexts/nativecontexts.pri) include(xcbfunctions/xcbfunctions.pri) +include(eglfsfunctions/eglfsfunctions.pri) QMAKE_DOCS = $$PWD/doc/qtplatformheaders.qdocconf diff --git a/src/platformsupport/eglconvenience/qeglplatformintegration.cpp b/src/platformsupport/eglconvenience/qeglplatformintegration.cpp index 4e4860db9a..3c2dba3626 100644 --- a/src/platformsupport/eglconvenience/qeglplatformintegration.cpp +++ b/src/platformsupport/eglconvenience/qeglplatformintegration.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -57,6 +58,8 @@ #include #endif +#include + #include "qeglplatformintegration_p.h" #include "qeglplatformcontext_p.h" #include "qeglplatformwindow_p.h" @@ -93,7 +96,8 @@ QEGLPlatformIntegration::QEGLPlatformIntegration() m_display(EGL_NO_DISPLAY), m_inputContext(0), m_fontDb(new QGenericUnixFontDatabase), - m_services(new QGenericUnixServices) + m_services(new QGenericUnixServices), + m_kbdMgr(0) { } @@ -314,10 +318,33 @@ QPlatformNativeInterface::NativeResourceForContextFunction QEGLPlatformIntegrati return 0; } +QFunctionPointer QEGLPlatformIntegration::platformFunction(const QByteArray &function) const +{ +#if !defined(QT_NO_EVDEV) && (!defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_NO_SDK)) + if (function == QEglFSFunctions::loadKeymapTypeIdentifier()) + return QFunctionPointer(loadKeymapStatic); +#endif + + return 0; +} + +void QEGLPlatformIntegration::loadKeymapStatic(const QString &filename) +{ +#if !defined(QT_NO_EVDEV) && (!defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_NO_SDK)) + QEGLPlatformIntegration *self = static_cast(QGuiApplicationPrivate::platformIntegration()); + if (self->m_kbdMgr) + self->m_kbdMgr->loadKeymap(filename); + else + qWarning("QEGLPlatformIntegration: Cannot load keymap, no keyboard handler found"); +#else + Q_UNUSED(filename); +#endif +} + void QEGLPlatformIntegration::createInputHandlers() { #if !defined(QT_NO_EVDEV) && (!defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_NO_SDK)) - new QEvdevKeyboardManager(QLatin1String("EvdevKeyboard"), QString() /* spec */, this); + m_kbdMgr = new QEvdevKeyboardManager(QLatin1String("EvdevKeyboard"), QString() /* spec */, this); QEvdevMouseManager *mouseMgr = new QEvdevMouseManager(QLatin1String("EvdevMouse"), QString() /* spec */, this); Q_FOREACH (QScreen *screen, QGuiApplication::screens()) { QEGLPlatformCursor *cursor = static_cast(screen->handle()->cursor()); diff --git a/src/platformsupport/eglconvenience/qeglplatformintegration_p.h b/src/platformsupport/eglconvenience/qeglplatformintegration_p.h index 9d4207e005..36f79e2997 100644 --- a/src/platformsupport/eglconvenience/qeglplatformintegration_p.h +++ b/src/platformsupport/eglconvenience/qeglplatformintegration_p.h @@ -53,6 +53,7 @@ class QEGLPlatformScreen; class QEGLPlatformWindow; class QEGLPlatformContext; class QFbVtHandler; +class QEvdevKeyboardManager; class QEGLPlatformIntegration : public QPlatformIntegration, public QPlatformNativeInterface { @@ -85,6 +86,8 @@ public: void *nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context) Q_DECL_OVERRIDE; NativeResourceForContextFunction nativeResourceFunctionForContext(const QByteArray &resource) Q_DECL_OVERRIDE; + QFunctionPointer platformFunction(const QByteArray &function) const Q_DECL_OVERRIDE; + protected: virtual QEGLPlatformScreen *createScreen() const = 0; virtual QEGLPlatformWindow *createWindow(QWindow *window) const = 0; @@ -101,12 +104,15 @@ protected: void createInputHandlers(); private: + static void loadKeymapStatic(const QString &filename); + QEGLPlatformScreen *m_screen; EGLDisplay m_display; QPlatformInputContext *m_inputContext; QScopedPointer m_fontDb; QScopedPointer m_services; QScopedPointer m_vtHandler; + QEvdevKeyboardManager *m_kbdMgr; }; QT_END_NAMESPACE diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp index 0841544208..72de73db7e 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; diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h index 1065b05d51..164b1c3863 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h @@ -145,7 +145,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) { @@ -161,13 +163,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 37c60c035c..e7a07f17a4 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager_p.h +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager_p.h @@ -59,6 +59,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); @@ -67,6 +69,7 @@ private: QString m_spec; QHash m_keyboards; QDeviceDiscovery *m_deviceDiscovery; + QString m_defaultKeymapFile; }; QT_END_NAMESPACE