diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-03-03 01:00:24 +0100 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-03-03 01:00:25 +0100 |
commit | 84e15d6f485fe0e9a4549d57ef39dbc3d18eeaa9 (patch) | |
tree | b02e4541aac42302504b244f856062bda902cd0d /src/plugins | |
parent | c6153660e458ee3790a446a327d29e622defee49 (diff) | |
parent | 607338f98feaa2561340c7ff4249d470b36d0503 (diff) |
Merge remote-tracking branch 'origin/5.13' into dev
Change-Id: Ic0037eac1d85a0e60e7b1a590d49b5ee6205bfc8
Diffstat (limited to 'src/plugins')
13 files changed, 141 insertions, 2019 deletions
diff --git a/src/plugins/platforminputcontexts/compose/compose.pro b/src/plugins/platforminputcontexts/compose/compose.pro index 68bc2c3466..2e2f8600c3 100644 --- a/src/plugins/platforminputcontexts/compose/compose.pro +++ b/src/plugins/platforminputcontexts/compose/compose.pro @@ -3,18 +3,14 @@ TARGET = composeplatforminputcontextplugin QT += core-private gui-private SOURCES += $$PWD/qcomposeplatforminputcontextmain.cpp \ - $$PWD/qcomposeplatforminputcontext.cpp \ - $$PWD/generator/qtablegenerator.cpp \ + $$PWD/qcomposeplatforminputcontext.cpp -HEADERS += $$PWD/qcomposeplatforminputcontext.h \ - $$PWD/generator/qtablegenerator.h \ +HEADERS += $$PWD/qcomposeplatforminputcontext.h QMAKE_USE_PRIVATE += xkbcommon include($$OUT_PWD/../../../gui/qtgui-config.pri) -DEFINES += X11_PREFIX='\\"$$QMAKE_X11_PREFIX\\"' - OTHER_FILES += $$PWD/compose.json PLUGIN_TYPE = platforminputcontexts diff --git a/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp b/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp deleted file mode 100644 index b5a0a5bbeb..0000000000 --- a/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp +++ /dev/null @@ -1,658 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/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 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtablegenerator.h" - -#include <QtCore/QByteArray> -#include <QtCore/QTextCodec> -#include <QtCore/QDebug> -#include <QtCore/QDir> -#include <QtCore/QStringList> -#include <QtCore/QString> -#include <QtCore/QSaveFile> -#include <QtCore/QStandardPaths> -#include <private/qcore_unix_p.h> - -#include <algorithm> - -#include <xkbcommon/xkbcommon.h> - -#include <locale.h> // LC_CTYPE -#include <string.h> // strchr, strncmp, etc. -#include <strings.h> // strncasecmp -#include <clocale> // LC_CTYPE - -static const quint32 SupportedCacheVersion = 1; - -/* - In short on how and why the "Compose" file is cached: - - The "Compose" file is large, for en_US it's likely located at: - /usr/share/X11/locale/en_US.UTF-8/Compose - and it has about 6000 string lines. - Q(Gui)Applications parse this file each time they're created. On modern CPUs - it incurs a 4-10 ms startup penalty of each Qt gui app, on older CPUs - - tens of ms or more. - Since the "Compose" file (almost) never changes using a pre-parsed - cache file instead of the "Compose" file is a good idea to improve Qt5 - application startup time by about 5+ ms (or tens of ms on older CPUs). - - The cache file contains the contents of the QComposeCacheFileHeader struct at the - beginning followed by the pre-parsed contents of the "Compose" file. - - struct QComposeCacheFileHeader stores - (a) The cache version - in the unlikely event that some day one might need - to break compatibility. - (b) The (cache) file size. - (c) The lastModified field tracks if anything changed since the last time - the cache file was saved. - If anything did change then we read the compose file and save (cache) it - in binary/pre-parsed format, which should happen extremely rarely if at all. -*/ - -struct QComposeCacheFileHeader -{ - quint32 cacheVersion; - // The compiler will add 4 padding bytes anyway. - // Reserve them explicitly to possibly use in the future. - quint32 reserved; - quint64 fileSize; - qint64 lastModified; -}; - -// localHostName() copied from qtbase/src/corelib/io/qlockfile_unix.cpp -static QByteArray localHostName() -{ - QByteArray hostName(512, Qt::Uninitialized); - if (gethostname(hostName.data(), hostName.size()) == -1) - return QByteArray(); - hostName.truncate(strlen(hostName.data())); - return hostName; -} - -/* - Reads metadata about the Compose file. Later used to determine if the - compose cache should be updated. The fileSize field will be zero on failure. -*/ -static QComposeCacheFileHeader readFileMetadata(const QString &path) -{ - quint64 fileSize = 0; - qint64 lastModified = 0; - const QByteArray pathBytes = QFile::encodeName(path); - QT_STATBUF st; - if (QT_STAT(pathBytes.data(), &st) == 0) { - lastModified = st.st_mtime; - fileSize = st.st_size; - } - QComposeCacheFileHeader info = { 0, 0, fileSize, lastModified }; - return info; -} - -static const QString getCacheFilePath() -{ - QFile machineIdFile("/var/lib/dbus/machine-id"); - QString machineId; - if (machineIdFile.exists()) { - if (machineIdFile.open(QIODevice::ReadOnly)) - machineId = QString::fromLatin1(machineIdFile.readAll().trimmed()); - } - if (machineId.isEmpty()) - machineId = localHostName(); - const QString dirPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation); - - if (QSysInfo::ByteOrder == QSysInfo::BigEndian) - return dirPath + QLatin1String("/qt_compose_cache_big_endian_") + machineId; - return dirPath + QLatin1String("/qt_compose_cache_little_endian_") + machineId; -} - -// Returns empty vector on failure -static QVector<QComposeTableElement> loadCache(const QComposeCacheFileHeader &composeInfo) -{ - QVector<QComposeTableElement> vec; - const QString cacheFilePath = getCacheFilePath(); - QFile inputFile(cacheFilePath); - - if (!inputFile.open(QIODevice::ReadOnly)) - return vec; - QComposeCacheFileHeader cacheInfo; - // use a "buffer" variable to make the line after this one more readable. - char *buffer = reinterpret_cast<char*>(&cacheInfo); - - if (inputFile.read(buffer, sizeof cacheInfo) != sizeof cacheInfo) - return vec; - if (cacheInfo.fileSize == 0) - return vec; - // using "!=" just in case someone replaced with a backup that existed before - if (cacheInfo.lastModified != composeInfo.lastModified) - return vec; - if (cacheInfo.cacheVersion != SupportedCacheVersion) - return vec; - const QByteArray pathBytes = QFile::encodeName(cacheFilePath); - QT_STATBUF st; - if (QT_STAT(pathBytes.data(), &st) != 0) - return vec; - const off_t fileSize = st.st_size; - if (fileSize > 1024 * 1024 * 5) { - // The cache file size is usually about 150KB, so if its size is over - // say 5MB then somebody inflated the file, abort. - return vec; - } - const off_t bufferSize = fileSize - (sizeof cacheInfo); - const size_t elemSize = sizeof (struct QComposeTableElement); - const int elemCount = bufferSize / elemSize; - const QByteArray ba = inputFile.read(bufferSize); - const char *data = ba.data(); - // Since we know the number of the (many) elements and their size in - // advance calling vector.reserve(..) seems reasonable. - vec.reserve(elemCount); - - for (int i = 0; i < elemCount; i++) { - const QComposeTableElement *elem = - reinterpret_cast<const QComposeTableElement*>(data + (i * elemSize)); - vec.push_back(*elem); - } - return vec; -} - -// Returns true on success, false otherwise. -static bool saveCache(const QComposeCacheFileHeader &info, const QVector<QComposeTableElement> &vec) -{ - const QString filePath = getCacheFilePath(); -#if QT_CONFIG(temporaryfile) - QSaveFile outputFile(filePath); -#else - QFile outputFile(filePath); -#endif - if (!outputFile.open(QIODevice::WriteOnly)) - return false; - const char *data = reinterpret_cast<const char*>(&info); - - if (outputFile.write(data, sizeof info) != sizeof info) - return false; - data = reinterpret_cast<const char*>(vec.constData()); - const qint64 size = vec.size() * (sizeof (struct QComposeTableElement)); - - if (outputFile.write(data, size) != size) - return false; -#if QT_CONFIG(temporaryfile) - return outputFile.commit(); -#else - return true; -#endif -} - -TableGenerator::TableGenerator() : m_state(NoErrors), - m_systemComposeDir(QString()) -{ - initPossibleLocations(); - QString composeFilePath = findComposeFile(); -#ifdef DEBUG_GENERATOR -// don't use cache when in debug mode. - if (!composeFilePath.isEmpty()) - qDebug() << "Using Compose file from: " << composeFilePath; -#else - QComposeCacheFileHeader fileInfo = readFileMetadata(composeFilePath); - if (fileInfo.fileSize != 0) - m_composeTable = loadCache(fileInfo); -#endif - if (m_composeTable.isEmpty() && cleanState()) { - if (composeFilePath.isEmpty()) { - m_state = MissingComposeFile; - } else { - QFile composeFile(composeFilePath); - composeFile.open(QIODevice::ReadOnly); - parseComposeFile(&composeFile); - orderComposeTable(); - if (m_composeTable.isEmpty()) { - m_state = EmptyTable; -#ifndef DEBUG_GENERATOR -// don't save cache when in debug mode - } else { - fileInfo.cacheVersion = SupportedCacheVersion; - saveCache(fileInfo, m_composeTable); -#endif - } - } - } -#ifdef DEBUG_GENERATOR - printComposeTable(); -#endif -} - -void TableGenerator::initPossibleLocations() -{ - // Compose files come as a part of Xlib library. Xlib doesn't provide - // a mechanism how to retrieve the location of these files reliably, since it was - // never meant for external software to parse compose tables directly. Best we - // can do is to hardcode search paths. To add an extra system path use - // the QTCOMPOSE environment variable - m_possibleLocations.reserve(7); - if (qEnvironmentVariableIsSet("QTCOMPOSE")) - m_possibleLocations.append(QString::fromLocal8Bit(qgetenv("QTCOMPOSE"))); - m_possibleLocations.append(QStringLiteral("/usr/share/X11/locale")); - m_possibleLocations.append(QStringLiteral("/usr/local/share/X11/locale")); - m_possibleLocations.append(QStringLiteral("/usr/lib/X11/locale")); - m_possibleLocations.append(QStringLiteral("/usr/local/lib/X11/locale")); - m_possibleLocations.append(QStringLiteral(X11_PREFIX "/share/X11/locale")); - m_possibleLocations.append(QStringLiteral(X11_PREFIX "/lib/X11/locale")); -} - -QString TableGenerator::findComposeFile() -{ - // check if XCOMPOSEFILE points to a Compose file - if (qEnvironmentVariableIsSet("XCOMPOSEFILE")) { - const QString path = QFile::decodeName(qgetenv("XCOMPOSEFILE")); - if (QFile::exists(path)) - return path; - else - qWarning("$XCOMPOSEFILE doesn't point to an existing file"); - } - - // check if user’s home directory has a file named .XCompose - if (cleanState()) { - QString path = qgetenv("HOME") + QLatin1String("/.XCompose"); - if (QFile::exists(path)) - return path; - } - - // check for the system provided compose files - if (cleanState()) { - QString table = composeTableForLocale(); - if (cleanState()) { - if (table.isEmpty()) - // no table mappings for the system's locale in the compose.dir - m_state = UnsupportedLocale; - else { - QString path = QDir(systemComposeDir()).filePath(table); - if (QFile::exists(path)) - return path; - } - } - } - return QString(); -} - -QString TableGenerator::composeTableForLocale() -{ - QByteArray loc = locale().toUpper().toUtf8(); - QString table = readLocaleMappings(loc); - if (table.isEmpty()) - table = readLocaleMappings(readLocaleAliases(loc)); - return table; -} - -bool TableGenerator::findSystemComposeDir() -{ - bool found = false; - for (int i = 0; i < m_possibleLocations.size(); ++i) { - QString path = m_possibleLocations.at(i); - if (QFile::exists(path + QLatin1String("/compose.dir"))) { - m_systemComposeDir = path; - found = true; - break; - } - } - - if (!found) { - // should we ask to report this in the qt bug tracker? - m_state = UnknownSystemComposeDir; - qWarning("Qt Warning: Could not find a location of the system's Compose files. " - "Consider setting the QTCOMPOSE environment variable."); - } - - return found; -} - -QString TableGenerator::systemComposeDir() -{ - if (m_systemComposeDir.isNull() - && !findSystemComposeDir()) { - return QLatin1String("$QTCOMPOSE"); - } - - return m_systemComposeDir; -} - -QString TableGenerator::locale() const -{ - char *name = setlocale(LC_CTYPE, (char *)0); - return QLatin1String(name); -} - -QString TableGenerator::readLocaleMappings(const QByteArray &locale) -{ - QString file; - if (locale.isEmpty()) - return file; - - QFile mappings(systemComposeDir() + QLatin1String("/compose.dir")); - if (mappings.open(QIODevice::ReadOnly)) { - const int localeNameLength = locale.size(); - const char * const localeData = locale.constData(); - - char l[1024]; - // formating of compose.dir has some inconsistencies - while (!mappings.atEnd()) { - int read = mappings.readLine(l, sizeof(l)); - if (read <= 0) - break; - - char *line = l; - if (*line >= 'a' && *line <= 'z') { - // file name - while (*line && *line != ':' && *line != ' ' && *line != '\t') - ++line; - if (!*line) - continue; - const char * const composeFileNameEnd = line; - *line = '\0'; - ++line; - - // locale name - while (*line && (*line == ' ' || *line == '\t')) - ++line; - const char * const lc = line; - while (*line && *line != ' ' && *line != '\t' && *line != '\n') - ++line; - *line = '\0'; - if (localeNameLength == (line - lc) && !strncasecmp(lc, localeData, line - lc)) { - file = QString::fromLocal8Bit(l, composeFileNameEnd - l); - break; - } - } - } - mappings.close(); - } - return file; -} - -QByteArray TableGenerator::readLocaleAliases(const QByteArray &locale) -{ - QFile aliases(systemComposeDir() + QLatin1String("/locale.alias")); - QByteArray fullLocaleName; - if (aliases.open(QIODevice::ReadOnly)) { - while (!aliases.atEnd()) { - char l[1024]; - int read = aliases.readLine(l, sizeof(l)); - char *line = l; - if (read && ((*line >= 'a' && *line <= 'z') || - (*line >= 'A' && *line <= 'Z'))) { - const char *alias = line; - while (*line && *line != ':' && *line != ' ' && *line != '\t') - ++line; - if (!*line) - continue; - *line = 0; - if (locale.size() == (line - alias) - && !strncasecmp(alias, locale.constData(), line - alias)) { - // found a match for alias, read the real locale name - ++line; - while (*line && (*line == ' ' || *line == '\t')) - ++line; - const char *fullName = line; - while (*line && *line != ' ' && *line != '\t' && *line != '\n') - ++line; - *line = 0; - fullLocaleName = fullName; -#ifdef DEBUG_GENERATOR - qDebug() << "Alias for: " << alias << "is: " << fullLocaleName; - break; -#endif - } - } - } - aliases.close(); - } - return fullLocaleName; -} - -bool TableGenerator::processFile(const QString &composeFileName) -{ - QFile composeFile(composeFileName); - if (composeFile.open(QIODevice::ReadOnly)) { - parseComposeFile(&composeFile); - return true; - } - qWarning() << QString(QLatin1String("Qt Warning: Compose file: \"%1\" can't be found")) - .arg(composeFile.fileName()); - return false; -} - -TableGenerator::~TableGenerator() -{ -} - -QVector<QComposeTableElement> TableGenerator::composeTable() const -{ - return m_composeTable; -} - -void TableGenerator::parseComposeFile(QFile *composeFile) -{ -#ifdef DEBUG_GENERATOR - qDebug() << "TableGenerator::parseComposeFile: " << composeFile->fileName(); -#endif - - char line[1024]; - while (!composeFile->atEnd()) { - composeFile->readLine(line, sizeof(line)); - if (*line == '<') - parseKeySequence(line); - else if (!strncmp(line, "include", 7)) - parseIncludeInstruction(QString::fromLocal8Bit(line)); - } - - composeFile->close(); -} - -void TableGenerator::parseIncludeInstruction(QString line) -{ - // Parse something that looks like: - // include "/usr/share/X11/locale/en_US.UTF-8/Compose" - QString quote = QStringLiteral("\""); - line.remove(0, line.indexOf(quote) + 1); - line.chop(line.length() - line.indexOf(quote)); - - // expand substitutions if present - line.replace(QLatin1String("%H"), QString(qgetenv("HOME"))); - line.replace(QLatin1String("%L"), systemComposeDir() + QLatin1Char('/') + composeTableForLocale()); - line.replace(QLatin1String("%S"), systemComposeDir()); - - processFile(line); -} - -ushort TableGenerator::keysymToUtf8(quint32 sym) -{ - QByteArray chars; - int bytes; - chars.resize(8); - bytes = xkb_keysym_to_utf8(sym, chars.data(), chars.size()); - if (bytes == -1) - qWarning("TableGenerator::keysymToUtf8 - buffer too small"); - - chars.resize(bytes-1); - -#ifdef DEBUG_GENERATOR - QTextCodec *codec = QTextCodec::codecForLocale(); - qDebug() << QString("keysym - 0x%1 : utf8 - %2").arg(QString::number(sym, 16)) - .arg(codec->toUnicode(chars)); -#endif - return QString::fromUtf8(chars).at(0).unicode(); -} - -static inline int fromBase8(const char *s, const char *end) -{ - int result = 0; - while (*s && s != end) { - if (*s < '0' || *s > '7') - return 0; - result *= 8; - result += *s - '0'; - ++s; - } - return result; -} - -static inline int fromBase16(const char *s, const char *end) -{ - int result = 0; - while (*s && s != end) { - result *= 16; - if (*s >= '0' && *s <= '9') - result += *s - '0'; - else if (*s >= 'a' && *s <= 'f') - result += *s - 'a' + 10; - else if (*s >= 'A' && *s <= 'F') - result += *s - 'A' + 10; - else - return 0; - ++s; - } - return result; -} - -void TableGenerator::parseKeySequence(char *line) -{ - // we are interested in the lines with the following format: - // <Multi_key> <numbersign> <S> : "♬" U266c # BEAMED SIXTEENTH NOTE - char *keysEnd = strchr(line, ':'); - if (!keysEnd) - return; - - QComposeTableElement elem; - // find the composed value - strings may be direct text encoded in the locale - // for which the compose file is to be used, or an escaped octal or hexadecimal - // character code. Octal codes are specified as "\123" and hexadecimal codes as "\0x123a". - char *composeValue = strchr(keysEnd, '"'); - if (!composeValue) - return; - ++composeValue; - - char *composeValueEnd = strchr(composeValue, '"'); - if (!composeValueEnd) - return; - - // if composed value is a quotation mark adjust the end pointer - if (composeValueEnd[1] == '"') - ++composeValueEnd; - - if (*composeValue == '\\' && composeValue[1] >= '0' && composeValue[1] <= '9') { - // handle octal and hex code values - char detectBase = composeValue[2]; - if (detectBase == 'x') { - // hexadecimal character code - elem.value = keysymToUtf8(fromBase16(composeValue + 3, composeValueEnd)); - } else { - // octal character code - elem.value = keysymToUtf8(fromBase8(composeValue + 1, composeValueEnd)); - } - } else { - // handle direct text encoded in the locale - if (*composeValue == '\\') - ++composeValue; - elem.value = QString::fromLocal8Bit(composeValue, composeValueEnd - composeValue).at(0).unicode(); - ++composeValue; - } - -#ifdef DEBUG_GENERATOR - // find the comment - elem.comment = QString::fromLocal8Bit(composeValueEnd + 1).trimmed(); -#endif - - // find the key sequence and convert to X11 keysym - char *k = line; - const char *kend = keysEnd; - - for (int i = 0; i < QT_KEYSEQUENCE_MAX_LEN; i++) { - // find the next pair of angle brackets and get the contents within - while (k < kend && *k != '<') - ++k; - char *sym = ++k; - while (k < kend && *k != '>') - ++k; - *k = '\0'; - if (k < kend) { - elem.keys[i] = xkb_keysym_from_name(sym, (xkb_keysym_flags)0); - if (elem.keys[i] == XKB_KEY_NoSymbol) { - if (!strcmp(sym, "dead_inverted_breve")) - elem.keys[i] = XKB_KEY_dead_invertedbreve; - else if (!strcmp(sym, "dead_double_grave")) - elem.keys[i] = XKB_KEY_dead_doublegrave; -#ifdef DEBUG_GENERATOR - else - qWarning() << QString("Qt Warning - invalid keysym: %1").arg(sym); -#endif - } - } else { - elem.keys[i] = 0; - } - } - m_composeTable.append(elem); -} - -void TableGenerator::printComposeTable() const -{ -#ifdef DEBUG_GENERATOR -# ifndef QT_NO_DEBUG_STREAM - if (m_composeTable.isEmpty()) - return; - - QDebug ds = qDebug() << "output:\n"; - ds.nospace(); - const int tableSize = m_composeTable.size(); - for (int i = 0; i < tableSize; ++i) { - const QComposeTableElement &elem = m_composeTable.at(i); - ds << "{ {"; - for (int j = 0; j < QT_KEYSEQUENCE_MAX_LEN; j++) { - ds << hex << showbase << elem.keys[j] << ", "; - } - ds << "}, " << hex << showbase << elem.value << ", \"\" }, // " << elem.comment << " \n"; - } -# endif -#endif -} - -void TableGenerator::orderComposeTable() -{ - // Stable-sorting to ensure that the item that appeared before the other in the - // original container will still appear first after the sort. This property is - // needed to handle the cases when user re-defines already defined key sequence - std::stable_sort(m_composeTable.begin(), m_composeTable.end(), ByKeys()); -} - diff --git a/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.h b/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.h deleted file mode 100644 index 4f58358f4e..0000000000 --- a/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.h +++ /dev/null @@ -1,145 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/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 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTABLEGENERATOR_H -#define QTABLEGENERATOR_H - -#include <QtCore/QVector> -#include <QtCore/QFile> -#include <QtCore/QMap> -#include <QtCore/QString> - -#include <algorithm> - -static Q_CONSTEXPR int QT_KEYSEQUENCE_MAX_LEN = 6; - -//#define DEBUG_GENERATOR - -/* Whenever QComposeTableElement gets modified supportedCacheVersion - from qtablegenerator.cpp must be bumped. */ -struct QComposeTableElement { - uint keys[QT_KEYSEQUENCE_MAX_LEN]; - uint value; -#ifdef DEBUG_GENERATOR - QString comment; -#endif -}; - -#ifndef DEBUG_GENERATOR -QT_BEGIN_NAMESPACE -Q_DECLARE_TYPEINFO(QComposeTableElement, Q_PRIMITIVE_TYPE); -QT_END_NAMESPACE -#endif - -struct ByKeys -{ - using uint_array = uint[QT_KEYSEQUENCE_MAX_LEN]; - using result_type = bool; - - bool operator()(const uint_array &lhs, const uint_array &rhs) const Q_DECL_NOTHROW - { - return std::lexicographical_compare(lhs, lhs + QT_KEYSEQUENCE_MAX_LEN, - rhs, rhs + QT_KEYSEQUENCE_MAX_LEN); - } - - bool operator()(const uint_array &lhs, const QComposeTableElement &rhs) const Q_DECL_NOTHROW - { - return operator()(lhs, rhs.keys); - } - - bool operator()(const QComposeTableElement &lhs, const uint_array &rhs) const Q_DECL_NOTHROW - { - return operator()(lhs.keys, rhs); - } - - bool operator()(const QComposeTableElement &lhs, const QComposeTableElement &rhs) const Q_DECL_NOTHROW - { - return operator()(lhs.keys, rhs.keys); - } -}; - -class TableGenerator -{ - -public: - enum TableState - { - UnsupportedLocale, - EmptyTable, - UnknownSystemComposeDir, - MissingComposeFile, - NoErrors - }; - - TableGenerator(); - ~TableGenerator(); - - void parseComposeFile(QFile *composeFile); - void printComposeTable() const; - void orderComposeTable(); - - QVector<QComposeTableElement> composeTable() const; - TableState tableState() const { return m_state; } - -protected: - bool processFile(const QString &composeFileName); - void parseKeySequence(char *line); - void parseIncludeInstruction(QString line); - - QString findComposeFile(); - bool findSystemComposeDir(); - QString systemComposeDir(); - QString composeTableForLocale(); - - ushort keysymToUtf8(quint32 sym); - - QString readLocaleMappings(const QByteArray &locale); - QByteArray readLocaleAliases(const QByteArray &locale); - void initPossibleLocations(); - bool cleanState() const { return m_state == NoErrors; } - QString locale() const; - -private: - QVector<QComposeTableElement> m_composeTable; - TableState m_state; - QString m_systemComposeDir; - QList<QString> m_possibleLocations; -}; - -#endif // QTABLEGENERATOR_H diff --git a/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp b/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp index 81a730232c..6b9687c22d 100644 --- a/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp +++ b/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the plugins of the Qt Toolkit. @@ -36,131 +36,100 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - #include "qcomposeplatforminputcontext.h" #include <QtCore/QCoreApplication> #include <QtGui/QKeyEvent> -#include <QtCore/QDebug> -#include <algorithm> +#include <locale.h> QT_BEGIN_NAMESPACE -//#define DEBUG_COMPOSING +Q_LOGGING_CATEGORY(lcXkbCompose, "qt.xkb.compose") -static const int ignoreKeys[] = { - Qt::Key_Shift, - Qt::Key_Control, - Qt::Key_Meta, - Qt::Key_Alt, - Qt::Key_CapsLock, - Qt::Key_Super_L, - Qt::Key_Super_R, - Qt::Key_Hyper_L, - Qt::Key_Hyper_R, - Qt::Key_Mode_switch -}; +QComposeInputContext::QComposeInputContext() +{ + setObjectName(QStringLiteral("QComposeInputContext")); + qCDebug(lcXkbCompose, "using xkb compose input context"); +} -static const int composingKeys[] = { - Qt::Key_Multi_key, - Qt::Key_Dead_Grave, - Qt::Key_Dead_Acute, - Qt::Key_Dead_Circumflex, - Qt::Key_Dead_Tilde, - Qt::Key_Dead_Macron, - Qt::Key_Dead_Breve, - Qt::Key_Dead_Abovedot, - Qt::Key_Dead_Diaeresis, - Qt::Key_Dead_Abovering, - Qt::Key_Dead_Doubleacute, - Qt::Key_Dead_Caron, - Qt::Key_Dead_Cedilla, - Qt::Key_Dead_Ogonek, - Qt::Key_Dead_Iota, - Qt::Key_Dead_Voiced_Sound, - Qt::Key_Dead_Semivoiced_Sound, - Qt::Key_Dead_Belowdot, - Qt::Key_Dead_Hook, - Qt::Key_Dead_Horn, - Qt::Key_Dead_Stroke, - Qt::Key_Dead_Abovecomma, - Qt::Key_Dead_Abovereversedcomma, - Qt::Key_Dead_Doublegrave, - Qt::Key_Dead_Belowring, - Qt::Key_Dead_Belowmacron, - Qt::Key_Dead_Belowcircumflex, - Qt::Key_Dead_Belowtilde, - Qt::Key_Dead_Belowbreve, - Qt::Key_Dead_Belowdiaeresis, - Qt::Key_Dead_Invertedbreve, - Qt::Key_Dead_Belowcomma, - Qt::Key_Dead_Currency, - Qt::Key_Dead_a, - Qt::Key_Dead_A, - Qt::Key_Dead_e, - Qt::Key_Dead_E, - Qt::Key_Dead_i, - Qt::Key_Dead_I, - Qt::Key_Dead_o, - Qt::Key_Dead_O, - Qt::Key_Dead_u, - Qt::Key_Dead_U, - Qt::Key_Dead_Small_Schwa, - Qt::Key_Dead_Capital_Schwa, - Qt::Key_Dead_Greek, - Qt::Key_Dead_Lowline, - Qt::Key_Dead_Aboveverticalline, - Qt::Key_Dead_Belowverticalline, - Qt::Key_Dead_Longsolidusoverlay -}; +QComposeInputContext::~QComposeInputContext() +{ + xkb_compose_state_unref(m_composeState); + xkb_compose_table_unref(m_composeTable); +} -QComposeInputContext::QComposeInputContext() - : m_tableState(TableGenerator::EmptyTable) - , m_compositionTableInitialized(false) +void QComposeInputContext::ensureInitialized() { - clearComposeBuffer(); + if (m_initialized) + return; + + if (!m_XkbContext) { + qCWarning(lcXkbCompose) << "error: xkb context has not been set on" << metaObject()->className(); + return; + } + + m_initialized = true; + const char *const locale = setlocale(LC_CTYPE, ""); + qCDebug(lcXkbCompose) << "detected locale (LC_CTYPE):" << locale; + + m_composeTable = xkb_compose_table_new_from_locale(m_XkbContext, locale, XKB_COMPOSE_COMPILE_NO_FLAGS); + if (m_composeTable) + m_composeState = xkb_compose_state_new(m_composeTable, XKB_COMPOSE_STATE_NO_FLAGS); + + if (!m_composeTable) { + qCWarning(lcXkbCompose, "failed to create compose table"); + return; + } + if (!m_composeState) { + qCWarning(lcXkbCompose, "failed to create compose state"); + return; + } } bool QComposeInputContext::filterEvent(const QEvent *event) { - const QKeyEvent *keyEvent = (const QKeyEvent *)event; - // should pass only the key presses - if (keyEvent->type() != QEvent::KeyPress) { + auto keyEvent = static_cast<const QKeyEvent *>(event); + if (keyEvent->type() != QEvent::KeyPress) return false; - } - // if there were errors when generating the compose table input - // context should not try to filter anything, simply return false - if (m_compositionTableInitialized && (m_tableState & TableGenerator::NoErrors) != TableGenerator::NoErrors) + if (!inputMethodAccepted()) return false; - int keyval = keyEvent->key(); - int keysym = 0; + // lazy initialization - we don't want to do this on an app startup + ensureInitialized(); - if (ignoreKey(keyval)) + if (!m_composeTable || !m_composeState) return false; - if (!composeKey(keyval) && keyEvent->text().isEmpty()) - return false; + xkb_compose_state_feed(m_composeState, keyEvent->nativeVirtualKey()); - keysym = keyEvent->nativeVirtualKey(); + switch (xkb_compose_state_get_status(m_composeState)) { + case XKB_COMPOSE_COMPOSING: + return true; + case XKB_COMPOSE_CANCELLED: + reset(); + return false; + case XKB_COMPOSE_COMPOSED: + { + const int size = xkb_compose_state_get_utf8(m_composeState, nullptr, 0); + QVarLengthArray<char, 32> buffer(size + 1); + xkb_compose_state_get_utf8(m_composeState, buffer.data(), buffer.size()); + QString composedText = QString::fromUtf8(buffer.constData()); - int nCompose = 0; - while (nCompose < QT_KEYSEQUENCE_MAX_LEN && m_composeBuffer[nCompose] != 0) - nCompose++; + QInputMethodEvent event; + event.setCommitString(composedText); + QCoreApplication::sendEvent(m_focusObject, &event); - if (nCompose == QT_KEYSEQUENCE_MAX_LEN) { reset(); - nCompose = 0; - } - - m_composeBuffer[nCompose] = keysym; - // check sequence - if (checkComposeTable()) return true; - - return false; + } + case XKB_COMPOSE_NOTHING: + return false; + default: + Q_UNREACHABLE(); + return false; + } } bool QComposeInputContext::isValid() const @@ -175,7 +144,8 @@ void QComposeInputContext::setFocusObject(QObject *object) void QComposeInputContext::reset() { - clearComposeBuffer(); + if (m_composeState) + xkb_compose_state_reset(m_composeState); } void QComposeInputContext::update(Qt::InputMethodQueries q) @@ -183,125 +153,4 @@ void QComposeInputContext::update(Qt::InputMethodQueries q) QPlatformInputContext::update(q); } -static bool isDuplicate(const QComposeTableElement &lhs, const QComposeTableElement &rhs) -{ - return std::equal(lhs.keys, lhs.keys + QT_KEYSEQUENCE_MAX_LEN, - QT_MAKE_CHECKED_ARRAY_ITERATOR(rhs.keys, QT_KEYSEQUENCE_MAX_LEN)); -} - -bool QComposeInputContext::checkComposeTable() -{ - if (!m_compositionTableInitialized) { - TableGenerator reader; - m_tableState = reader.tableState(); - - m_compositionTableInitialized = true; - if ((m_tableState & TableGenerator::NoErrors) == TableGenerator::NoErrors) { - m_composeTable = reader.composeTable(); - } else { -#ifdef DEBUG_COMPOSING - qDebug( "### FAILED_PARSING ###" ); -#endif - // if we have errors, don' try to look things up anyways. - reset(); - return false; - } - } - Q_ASSERT(!m_composeTable.isEmpty()); - QVector<QComposeTableElement>::const_iterator it = - std::lower_bound(m_composeTable.constBegin(), m_composeTable.constEnd(), m_composeBuffer, ByKeys()); - - // prevent dereferencing an 'end' iterator, which would result in a crash - if (it == m_composeTable.constEnd()) - it -= 1; - - QComposeTableElement elem = *it; - // would be nicer if qLowerBound had API that tells if the item was actually found - if (m_composeBuffer[0] != elem.keys[0]) { -#ifdef DEBUG_COMPOSING - qDebug( "### no match ###" ); -#endif - reset(); - return false; - } - // check if compose buffer is matched - for (int i=0; i < QT_KEYSEQUENCE_MAX_LEN; i++) { - - // check if partial match - if (m_composeBuffer[i] == 0 && elem.keys[i]) { -#ifdef DEBUG_COMPOSING - qDebug("### partial match ###"); -#endif - return true; - } - - if (m_composeBuffer[i] != elem.keys[i]) { -#ifdef DEBUG_COMPOSING - qDebug("### different entry ###"); -#endif - reset(); - return i != 0; - } - } -#ifdef DEBUG_COMPOSING - qDebug("### match exactly ###"); -#endif - - // check if the key sequence is overwriten - see the comment in - // TableGenerator::orderComposeTable() - int next = 1; - do { - // if we are at the end of the table, then we have nothing to do here - if (it + next != m_composeTable.constEnd()) { - QComposeTableElement nextElem = *(it + next); - if (isDuplicate(elem, nextElem)) { - elem = nextElem; - next++; - continue; - } else { - break; - } - } - break; - } while (true); - - commitText(elem.value); - reset(); - - return true; -} - -void QComposeInputContext::commitText(uint character) const -{ - QInputMethodEvent event; - event.setCommitString(QChar(character)); - QCoreApplication::sendEvent(m_focusObject, &event); -} - -bool QComposeInputContext::ignoreKey(int keyval) const -{ - for (uint i = 0; i < (sizeof(ignoreKeys) / sizeof(ignoreKeys[0])); i++) - if (keyval == ignoreKeys[i]) - return true; - - return false; -} - -bool QComposeInputContext::composeKey(int keyval) const -{ - for (uint i = 0; i < (sizeof(composingKeys) / sizeof(composingKeys[0])); i++) - if (keyval == composingKeys[i]) - return true; - - return false; -} - -void QComposeInputContext::clearComposeBuffer() -{ - for (uint i=0; i < (sizeof(m_composeBuffer) / sizeof(int)); i++) - m_composeBuffer[i] = 0; -} - -QComposeInputContext::~QComposeInputContext() {} - QT_END_NAMESPACE diff --git a/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.h b/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.h index 4830959665..b1de1b1094 100644 --- a/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.h +++ b/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the plugins of the Qt Toolkit. @@ -36,24 +36,24 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - #ifndef QCOMPOSEPLATFORMINPUTCONTEXT_H #define QCOMPOSEPLATFORMINPUTCONTEXT_H -#include <qpa/qplatforminputcontext.h> +#include <QtCore/QLoggingCategory> -#include <QtCore/QList> +#include <qpa/qplatforminputcontext.h> -#include "generator/qtablegenerator.h" +#include <xkbcommon/xkbcommon-compose.h> QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(lcXkbCompose) + class QEvent; class QComposeInputContext : public QPlatformInputContext { Q_OBJECT - public: QComposeInputContext(); ~QComposeInputContext(); @@ -62,21 +62,22 @@ public: void setFocusObject(QObject *object) override; void reset() override; void update(Qt::InputMethodQueries) override; + bool filterEvent(const QEvent *event) override; + // This invokable is called from QXkbCommon::setXkbContext(). + Q_INVOKABLE void setXkbContext(struct xkb_context *context) { m_XkbContext = context; } + protected: - void clearComposeBuffer(); - bool ignoreKey(int keyval) const; - bool composeKey(int keyval) const; - bool checkComposeTable(); - void commitText(uint character) const; + void ensureInitialized(); private: - QObject *m_focusObject; - QVector<QComposeTableElement> m_composeTable; - uint m_composeBuffer[QT_KEYSEQUENCE_MAX_LEN]; - TableGenerator::TableState m_tableState; - bool m_compositionTableInitialized; + bool m_initialized = false; + xkb_context *m_context = nullptr; + xkb_compose_table *m_composeTable = nullptr; + xkb_compose_state *m_composeState = nullptr; + QObject *m_focusObject = nullptr; + struct xkb_context *m_XkbContext = nullptr; }; QT_END_NAMESPACE diff --git a/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontextmain.cpp b/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontextmain.cpp index 6b33df65b9..d062d4fd6a 100644 --- a/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontextmain.cpp +++ b/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontextmain.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the plugins of the Qt Toolkit. @@ -61,7 +61,7 @@ QComposeInputContext *QComposePlatformInputContextPlugin::create(const QString & if (system.compare(system, QLatin1String("compose"), Qt::CaseInsensitive) == 0 || system.compare(system, QLatin1String("xim"), Qt::CaseInsensitive) == 0) return new QComposeInputContext; - return 0; + return nullptr; } QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index 37cfbc13ec..6ae429b24e 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -565,10 +565,15 @@ static void quitQtAndroidPlugin(JNIEnv *env, jclass /*clazz*/) static void terminateQt(JNIEnv *env, jclass /*clazz*/) { // QAndroidEventDispatcherStopper is stopped when the user uses the task manager to kill the application - if (!QAndroidEventDispatcherStopper::instance()->stopped()) { - sem_wait(&m_terminateSemaphore); - sem_destroy(&m_terminateSemaphore); + if (QAndroidEventDispatcherStopper::instance()->stopped()) { + QAndroidEventDispatcherStopper::instance()->startAll(); + QCoreApplication::quit(); + QAndroidEventDispatcherStopper::instance()->goingToStop(false); } + + sem_wait(&m_terminateSemaphore); + sem_destroy(&m_terminateSemaphore); + env->DeleteGlobalRef(m_applicationClass); env->DeleteGlobalRef(m_classLoaderObject); if (m_resourcesObj) @@ -588,10 +593,7 @@ static void terminateQt(JNIEnv *env, jclass /*clazz*/) m_androidPlatformIntegration = nullptr; delete m_androidAssetsFileEngineHandler; m_androidAssetsFileEngineHandler = nullptr; - - if (!QAndroidEventDispatcherStopper::instance()->stopped()) { - sem_post(&m_exitSemaphore); - } + sem_post(&m_exitSemaphore); } static void setSurface(JNIEnv *env, jobject /*thiz*/, jint id, jobject jSurface, jint w, jint h) diff --git a/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp index 3e1cfe305d..3de5d30623 100644 --- a/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp +++ b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp @@ -47,6 +47,7 @@ #include <QSurfaceFormat> #include <QtGui/private/qwindow_p.h> +#include <QtGui/qguiapplication.h> #include <qpa/qwindowsysteminterface.h> #include <qpa/qplatformscreen.h> @@ -121,7 +122,7 @@ void QAndroidPlatformOpenGLWindow::setGeometry(const QRect &rect) EGLSurface QAndroidPlatformOpenGLWindow::eglSurface(EGLConfig config) { - if (QAndroidEventDispatcherStopper::stopped()) + if (QAndroidEventDispatcherStopper::stopped() || QGuiApplication::applicationState() == Qt::ApplicationSuspended) return m_eglSurface; QMutexLocker lock(&m_surfaceMutex); diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index ed9e87a036..a70c7db923 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -357,6 +357,8 @@ void QXcbIntegration::initialize() m_inputContext.reset(QPlatformInputContextFactory::create(icStr)); if (!m_inputContext && icStr != defaultInputContext && icStr != QLatin1String("none")) m_inputContext.reset(QPlatformInputContextFactory::create(defaultInputContext)); + + defaultConnection()->keyboard()->initialize(); } void QXcbIntegration::moveToScreen(QWindow *window, int screen) diff --git a/src/plugins/platforms/xcb/qxcbkeyboard.cpp b/src/plugins/platforms/xcb/qxcbkeyboard.cpp index c5dc7b21ad..d0e02ecdd1 100644 --- a/src/plugins/platforms/xcb/qxcbkeyboard.cpp +++ b/src/plugins/platforms/xcb/qxcbkeyboard.cpp @@ -39,7 +39,6 @@ #include "qxcbkeyboard.h" #include "qxcbwindow.h" #include "qxcbscreen.h" -#include "qxcbxkbcommon.h" #include <qpa/qwindowsysteminterface.h> #include <qpa/qplatforminputcontext.h> @@ -49,404 +48,20 @@ #include <QtCore/QMetaEnum> #include <private/qguiapplication_p.h> -#include <private/qmakearray_p.h> -#include <xkbcommon/xkbcommon-keysyms.h> +#if QT_CONFIG(xkb) +#include <xkbcommon/xkbcommon-x11.h> +#endif #if QT_CONFIG(xcb_xinput) #include <xcb/xinput.h> #endif -QT_BEGIN_NAMESPACE - -typedef struct xkb2qt -{ - unsigned int xkb; - unsigned int qt; - - constexpr bool operator <=(const xkb2qt &that) const noexcept - { - return xkb <= that.xkb; - } - - constexpr bool operator <(const xkb2qt &that) const noexcept - { - return xkb < that.xkb; - } -} xkb2qt_t; -template<std::size_t Xkb, std::size_t Qt> -struct Xkb2Qt -{ - using Type = xkb2qt_t; - static constexpr Type data() noexcept { return Type{Xkb, Qt}; } -}; - -static constexpr const auto KeyTbl = qMakeArray( - QSortedData< - // misc keys - - Xkb2Qt<XKB_KEY_Escape, Qt::Key_Escape>, - Xkb2Qt<XKB_KEY_Tab, Qt::Key_Tab>, - Xkb2Qt<XKB_KEY_ISO_Left_Tab, Qt::Key_Backtab>, - Xkb2Qt<XKB_KEY_BackSpace, Qt::Key_Backspace>, - Xkb2Qt<XKB_KEY_Return, Qt::Key_Return>, - Xkb2Qt<XKB_KEY_Insert, Qt::Key_Insert>, - Xkb2Qt<XKB_KEY_Delete, Qt::Key_Delete>, - Xkb2Qt<XKB_KEY_Clear, Qt::Key_Delete>, - Xkb2Qt<XKB_KEY_Pause, Qt::Key_Pause>, - Xkb2Qt<XKB_KEY_Print, Qt::Key_Print>, - Xkb2Qt<0x1005FF60, Qt::Key_SysReq>, // hardcoded Sun SysReq - Xkb2Qt<0x1007ff00, Qt::Key_SysReq>, // hardcoded X386 SysReq - - // cursor movement - - Xkb2Qt<XKB_KEY_Home, Qt::Key_Home>, - Xkb2Qt<XKB_KEY_End, Qt::Key_End>, - Xkb2Qt<XKB_KEY_Left, Qt::Key_Left>, - Xkb2Qt<XKB_KEY_Up, Qt::Key_Up>, - Xkb2Qt<XKB_KEY_Right, Qt::Key_Right>, - Xkb2Qt<XKB_KEY_Down, Qt::Key_Down>, - Xkb2Qt<XKB_KEY_Prior, Qt::Key_PageUp>, - Xkb2Qt<XKB_KEY_Next, Qt::Key_PageDown>, - - // modifiers - - Xkb2Qt<XKB_KEY_Shift_L, Qt::Key_Shift>, - Xkb2Qt<XKB_KEY_Shift_R, Qt::Key_Shift>, - Xkb2Qt<XKB_KEY_Shift_Lock, Qt::Key_Shift>, - Xkb2Qt<XKB_KEY_Control_L, Qt::Key_Control>, - Xkb2Qt<XKB_KEY_Control_R, Qt::Key_Control>, - Xkb2Qt<XKB_KEY_Meta_L, Qt::Key_Meta>, - Xkb2Qt<XKB_KEY_Meta_R, Qt::Key_Meta>, - Xkb2Qt<XKB_KEY_Alt_L, Qt::Key_Alt>, - Xkb2Qt<XKB_KEY_Alt_R, Qt::Key_Alt>, - Xkb2Qt<XKB_KEY_Caps_Lock, Qt::Key_CapsLock>, - Xkb2Qt<XKB_KEY_Num_Lock, Qt::Key_NumLock>, - Xkb2Qt<XKB_KEY_Scroll_Lock, Qt::Key_ScrollLock>, - Xkb2Qt<XKB_KEY_Super_L, Qt::Key_Super_L>, - Xkb2Qt<XKB_KEY_Super_R, Qt::Key_Super_R>, - Xkb2Qt<XKB_KEY_Menu, Qt::Key_Menu>, - Xkb2Qt<XKB_KEY_Hyper_L, Qt::Key_Hyper_L>, - Xkb2Qt<XKB_KEY_Hyper_R, Qt::Key_Hyper_R>, - Xkb2Qt<XKB_KEY_Help, Qt::Key_Help>, - Xkb2Qt<0x1000FF74, Qt::Key_Backtab>, // hardcoded HP backtab - Xkb2Qt<0x1005FF10, Qt::Key_F11>, // hardcoded Sun F36 (labeled F11) - Xkb2Qt<0x1005FF11, Qt::Key_F12>, // hardcoded Sun F37 (labeled F12) - - // numeric and function keypad keys - - Xkb2Qt<XKB_KEY_KP_Space, Qt::Key_Space>, - Xkb2Qt<XKB_KEY_KP_Tab, Qt::Key_Tab>, - Xkb2Qt<XKB_KEY_KP_Enter, Qt::Key_Enter>, - //Xkb2Qt<XKB_KEY_KP_F1, Qt::Key_F1>, - //Xkb2Qt<XKB_KEY_KP_F2, Qt::Key_F2>, - //Xkb2Qt<XKB_KEY_KP_F3, Qt::Key_F3>, - //Xkb2Qt<XKB_KEY_KP_F4, Qt::Key_F4>, - Xkb2Qt<XKB_KEY_KP_Home, Qt::Key_Home>, - Xkb2Qt<XKB_KEY_KP_Left, Qt::Key_Left>, - Xkb2Qt<XKB_KEY_KP_Up, Qt::Key_Up>, - Xkb2Qt<XKB_KEY_KP_Right, Qt::Key_Right>, - Xkb2Qt<XKB_KEY_KP_Down, Qt::Key_Down>, - Xkb2Qt<XKB_KEY_KP_Prior, Qt::Key_PageUp>, - Xkb2Qt<XKB_KEY_KP_Next, Qt::Key_PageDown>, - Xkb2Qt<XKB_KEY_KP_End, Qt::Key_End>, - Xkb2Qt<XKB_KEY_KP_Begin, Qt::Key_Clear>, - Xkb2Qt<XKB_KEY_KP_Insert, Qt::Key_Insert>, - Xkb2Qt<XKB_KEY_KP_Delete, Qt::Key_Delete>, - Xkb2Qt<XKB_KEY_KP_Equal, Qt::Key_Equal>, - Xkb2Qt<XKB_KEY_KP_Multiply, Qt::Key_Asterisk>, - Xkb2Qt<XKB_KEY_KP_Add, Qt::Key_Plus>, - Xkb2Qt<XKB_KEY_KP_Separator, Qt::Key_Comma>, - Xkb2Qt<XKB_KEY_KP_Subtract, Qt::Key_Minus>, - Xkb2Qt<XKB_KEY_KP_Decimal, Qt::Key_Period>, - Xkb2Qt<XKB_KEY_KP_Divide, Qt::Key_Slash>, - - // special non-XF86 function keys - - Xkb2Qt<XKB_KEY_Undo, Qt::Key_Undo>, - Xkb2Qt<XKB_KEY_Redo, Qt::Key_Redo>, - Xkb2Qt<XKB_KEY_Find, Qt::Key_Find>, - Xkb2Qt<XKB_KEY_Cancel, Qt::Key_Cancel>, - - // International input method support keys - - // International & multi-key character composition - Xkb2Qt<XKB_KEY_ISO_Level3_Shift, Qt::Key_AltGr>, - Xkb2Qt<XKB_KEY_Multi_key, Qt::Key_Multi_key>, - Xkb2Qt<XKB_KEY_Codeinput, Qt::Key_Codeinput>, - Xkb2Qt<XKB_KEY_SingleCandidate, Qt::Key_SingleCandidate>, - Xkb2Qt<XKB_KEY_MultipleCandidate, Qt::Key_MultipleCandidate>, - Xkb2Qt<XKB_KEY_PreviousCandidate, Qt::Key_PreviousCandidate>, - - // Misc Functions - Xkb2Qt<XKB_KEY_Mode_switch, Qt::Key_Mode_switch>, - Xkb2Qt<XKB_KEY_script_switch, Qt::Key_Mode_switch>, - - // Japanese keyboard support - Xkb2Qt<XKB_KEY_Kanji, Qt::Key_Kanji>, - Xkb2Qt<XKB_KEY_Muhenkan, Qt::Key_Muhenkan>, - //Xkb2Qt<XKB_KEY_Henkan_Mode, Qt::Key_Henkan_Mode>, - Xkb2Qt<XKB_KEY_Henkan_Mode, Qt::Key_Henkan>, - Xkb2Qt<XKB_KEY_Henkan, Qt::Key_Henkan>, - Xkb2Qt<XKB_KEY_Romaji, Qt::Key_Romaji>, - Xkb2Qt<XKB_KEY_Hiragana, Qt::Key_Hiragana>, - Xkb2Qt<XKB_KEY_Katakana, Qt::Key_Katakana>, - Xkb2Qt<XKB_KEY_Hiragana_Katakana, Qt::Key_Hiragana_Katakana>, - Xkb2Qt<XKB_KEY_Zenkaku, Qt::Key_Zenkaku>, - Xkb2Qt<XKB_KEY_Hankaku, Qt::Key_Hankaku>, - Xkb2Qt<XKB_KEY_Zenkaku_Hankaku, Qt::Key_Zenkaku_Hankaku>, - Xkb2Qt<XKB_KEY_Touroku, Qt::Key_Touroku>, - Xkb2Qt<XKB_KEY_Massyo, Qt::Key_Massyo>, - Xkb2Qt<XKB_KEY_Kana_Lock, Qt::Key_Kana_Lock>, - Xkb2Qt<XKB_KEY_Kana_Shift, Qt::Key_Kana_Shift>, - Xkb2Qt<XKB_KEY_Eisu_Shift, Qt::Key_Eisu_Shift>, - Xkb2Qt<XKB_KEY_Eisu_toggle, Qt::Key_Eisu_toggle>, - //Xkb2Qt<XKB_KEY_Kanji_Bangou, Qt::Key_Kanji_Bangou>, - //Xkb2Qt<XKB_KEY_Zen_Koho, Qt::Key_Zen_Koho>, - //Xkb2Qt<XKB_KEY_Mae_Koho, Qt::Key_Mae_Koho>, - Xkb2Qt<XKB_KEY_Kanji_Bangou, Qt::Key_Codeinput>, - Xkb2Qt<XKB_KEY_Zen_Koho, Qt::Key_MultipleCandidate>, - Xkb2Qt<XKB_KEY_Mae_Koho, Qt::Key_PreviousCandidate>, - - // Korean keyboard support - Xkb2Qt<XKB_KEY_Hangul, Qt::Key_Hangul>, - Xkb2Qt<XKB_KEY_Hangul_Start, Qt::Key_Hangul_Start>, - Xkb2Qt<XKB_KEY_Hangul_End, Qt::Key_Hangul_End>, - Xkb2Qt<XKB_KEY_Hangul_Hanja, Qt::Key_Hangul_Hanja>, - Xkb2Qt<XKB_KEY_Hangul_Jamo, Qt::Key_Hangul_Jamo>, - Xkb2Qt<XKB_KEY_Hangul_Romaja, Qt::Key_Hangul_Romaja>, - //Xkb2Qt<XKB_KEY_Hangul_Codeinput, Qt::Key_Hangul_Codeinput>, - Xkb2Qt<XKB_KEY_Hangul_Codeinput, Qt::Key_Codeinput>, - Xkb2Qt<XKB_KEY_Hangul_Jeonja, Qt::Key_Hangul_Jeonja>, - Xkb2Qt<XKB_KEY_Hangul_Banja, Qt::Key_Hangul_Banja>, - Xkb2Qt<XKB_KEY_Hangul_PreHanja, Qt::Key_Hangul_PreHanja>, - Xkb2Qt<XKB_KEY_Hangul_PostHanja, Qt::Key_Hangul_PostHanja>, - //Xkb2Qt<XKB_KEY_Hangul_SingleCandidate,Qt::Key_Hangul_SingleCandidate>, - //Xkb2Qt<XKB_KEY_Hangul_MultipleCandidate,Qt::Key_Hangul_MultipleCandidate>, - //Xkb2Qt<XKB_KEY_Hangul_PreviousCandidate,Qt::Key_Hangul_PreviousCandidate>, - Xkb2Qt<XKB_KEY_Hangul_SingleCandidate, Qt::Key_SingleCandidate>, - Xkb2Qt<XKB_KEY_Hangul_MultipleCandidate,Qt::Key_MultipleCandidate>, - Xkb2Qt<XKB_KEY_Hangul_PreviousCandidate,Qt::Key_PreviousCandidate>, - Xkb2Qt<XKB_KEY_Hangul_Special, Qt::Key_Hangul_Special>, - //Xkb2Qt<XKB_KEY_Hangul_switch, Qt::Key_Hangul_switch>, - Xkb2Qt<XKB_KEY_Hangul_switch, Qt::Key_Mode_switch>, - - // dead keys - Xkb2Qt<XKB_KEY_dead_grave, Qt::Key_Dead_Grave>, - Xkb2Qt<XKB_KEY_dead_acute, Qt::Key_Dead_Acute>, - Xkb2Qt<XKB_KEY_dead_circumflex, Qt::Key_Dead_Circumflex>, - Xkb2Qt<XKB_KEY_dead_tilde, Qt::Key_Dead_Tilde>, - Xkb2Qt<XKB_KEY_dead_macron, Qt::Key_Dead_Macron>, - Xkb2Qt<XKB_KEY_dead_breve, Qt::Key_Dead_Breve>, - Xkb2Qt<XKB_KEY_dead_abovedot, Qt::Key_Dead_Abovedot>, - Xkb2Qt<XKB_KEY_dead_diaeresis, Qt::Key_Dead_Diaeresis>, - Xkb2Qt<XKB_KEY_dead_abovering, Qt::Key_Dead_Abovering>, - Xkb2Qt<XKB_KEY_dead_doubleacute, Qt::Key_Dead_Doubleacute>, - Xkb2Qt<XKB_KEY_dead_caron, Qt::Key_Dead_Caron>, - Xkb2Qt<XKB_KEY_dead_cedilla, Qt::Key_Dead_Cedilla>, - Xkb2Qt<XKB_KEY_dead_ogonek, Qt::Key_Dead_Ogonek>, - Xkb2Qt<XKB_KEY_dead_iota, Qt::Key_Dead_Iota>, - Xkb2Qt<XKB_KEY_dead_voiced_sound, Qt::Key_Dead_Voiced_Sound>, - Xkb2Qt<XKB_KEY_dead_semivoiced_sound, Qt::Key_Dead_Semivoiced_Sound>, - Xkb2Qt<XKB_KEY_dead_belowdot, Qt::Key_Dead_Belowdot>, - Xkb2Qt<XKB_KEY_dead_hook, Qt::Key_Dead_Hook>, - Xkb2Qt<XKB_KEY_dead_horn, Qt::Key_Dead_Horn>, - Xkb2Qt<XKB_KEY_dead_stroke, Qt::Key_Dead_Stroke>, - Xkb2Qt<XKB_KEY_dead_abovecomma, Qt::Key_Dead_Abovecomma>, - Xkb2Qt<XKB_KEY_dead_abovereversedcomma, Qt::Key_Dead_Abovereversedcomma>, - Xkb2Qt<XKB_KEY_dead_doublegrave, Qt::Key_Dead_Doublegrave>, - Xkb2Qt<XKB_KEY_dead_belowring, Qt::Key_Dead_Belowring>, - Xkb2Qt<XKB_KEY_dead_belowmacron, Qt::Key_Dead_Belowmacron>, - Xkb2Qt<XKB_KEY_dead_belowcircumflex, Qt::Key_Dead_Belowcircumflex>, - Xkb2Qt<XKB_KEY_dead_belowtilde, Qt::Key_Dead_Belowtilde>, - Xkb2Qt<XKB_KEY_dead_belowbreve, Qt::Key_Dead_Belowbreve>, - Xkb2Qt<XKB_KEY_dead_belowdiaeresis, Qt::Key_Dead_Belowdiaeresis>, - Xkb2Qt<XKB_KEY_dead_invertedbreve, Qt::Key_Dead_Invertedbreve>, - Xkb2Qt<XKB_KEY_dead_belowcomma, Qt::Key_Dead_Belowcomma>, - Xkb2Qt<XKB_KEY_dead_currency, Qt::Key_Dead_Currency>, - Xkb2Qt<XKB_KEY_dead_a, Qt::Key_Dead_a>, - Xkb2Qt<XKB_KEY_dead_A, Qt::Key_Dead_A>, - Xkb2Qt<XKB_KEY_dead_e, Qt::Key_Dead_e>, - Xkb2Qt<XKB_KEY_dead_E, Qt::Key_Dead_E>, - Xkb2Qt<XKB_KEY_dead_i, Qt::Key_Dead_i>, - Xkb2Qt<XKB_KEY_dead_I, Qt::Key_Dead_I>, - Xkb2Qt<XKB_KEY_dead_o, Qt::Key_Dead_o>, - Xkb2Qt<XKB_KEY_dead_O, Qt::Key_Dead_O>, - Xkb2Qt<XKB_KEY_dead_u, Qt::Key_Dead_u>, - Xkb2Qt<XKB_KEY_dead_U, Qt::Key_Dead_U>, - Xkb2Qt<XKB_KEY_dead_small_schwa, Qt::Key_Dead_Small_Schwa>, - Xkb2Qt<XKB_KEY_dead_capital_schwa, Qt::Key_Dead_Capital_Schwa>, - Xkb2Qt<XKB_KEY_dead_greek, Qt::Key_Dead_Greek>, - Xkb2Qt<XKB_KEY_dead_lowline, Qt::Key_Dead_Lowline>, - Xkb2Qt<XKB_KEY_dead_aboveverticalline, Qt::Key_Dead_Aboveverticalline>, - Xkb2Qt<XKB_KEY_dead_belowverticalline, Qt::Key_Dead_Belowverticalline>, - Xkb2Qt<XKB_KEY_dead_longsolidusoverlay, Qt::Key_Dead_Longsolidusoverlay>, - - // Special keys from X.org - This include multimedia keys, - // wireless/bluetooth/uwb keys, special launcher keys, etc. - Xkb2Qt<XKB_KEY_XF86Back, Qt::Key_Back>, - Xkb2Qt<XKB_KEY_XF86Forward, Qt::Key_Forward>, - Xkb2Qt<XKB_KEY_XF86Stop, Qt::Key_Stop>, - Xkb2Qt<XKB_KEY_XF86Refresh, Qt::Key_Refresh>, - Xkb2Qt<XKB_KEY_XF86Favorites, Qt::Key_Favorites>, - Xkb2Qt<XKB_KEY_XF86AudioMedia, Qt::Key_LaunchMedia>, - Xkb2Qt<XKB_KEY_XF86OpenURL, Qt::Key_OpenUrl>, - Xkb2Qt<XKB_KEY_XF86HomePage, Qt::Key_HomePage>, - Xkb2Qt<XKB_KEY_XF86Search, Qt::Key_Search>, - Xkb2Qt<XKB_KEY_XF86AudioLowerVolume, Qt::Key_VolumeDown>, - Xkb2Qt<XKB_KEY_XF86AudioMute, Qt::Key_VolumeMute>, - Xkb2Qt<XKB_KEY_XF86AudioRaiseVolume, Qt::Key_VolumeUp>, - Xkb2Qt<XKB_KEY_XF86AudioPlay, Qt::Key_MediaPlay>, - Xkb2Qt<XKB_KEY_XF86AudioStop, Qt::Key_MediaStop>, - Xkb2Qt<XKB_KEY_XF86AudioPrev, Qt::Key_MediaPrevious>, - Xkb2Qt<XKB_KEY_XF86AudioNext, Qt::Key_MediaNext>, - Xkb2Qt<XKB_KEY_XF86AudioRecord, Qt::Key_MediaRecord>, - Xkb2Qt<XKB_KEY_XF86AudioPause, Qt::Key_MediaPause>, - Xkb2Qt<XKB_KEY_XF86Mail, Qt::Key_LaunchMail>, - Xkb2Qt<XKB_KEY_XF86MyComputer, Qt::Key_Launch0>, // ### Qt 6: remap properly - Xkb2Qt<XKB_KEY_XF86Calculator, Qt::Key_Launch1>, - Xkb2Qt<XKB_KEY_XF86Memo, Qt::Key_Memo>, - Xkb2Qt<XKB_KEY_XF86ToDoList, Qt::Key_ToDoList>, - Xkb2Qt<XKB_KEY_XF86Calendar, Qt::Key_Calendar>, - Xkb2Qt<XKB_KEY_XF86PowerDown, Qt::Key_PowerDown>, - Xkb2Qt<XKB_KEY_XF86ContrastAdjust, Qt::Key_ContrastAdjust>, - Xkb2Qt<XKB_KEY_XF86Standby, Qt::Key_Standby>, - Xkb2Qt<XKB_KEY_XF86MonBrightnessUp, Qt::Key_MonBrightnessUp>, - Xkb2Qt<XKB_KEY_XF86MonBrightnessDown, Qt::Key_MonBrightnessDown>, - Xkb2Qt<XKB_KEY_XF86KbdLightOnOff, Qt::Key_KeyboardLightOnOff>, - Xkb2Qt<XKB_KEY_XF86KbdBrightnessUp, Qt::Key_KeyboardBrightnessUp>, - Xkb2Qt<XKB_KEY_XF86KbdBrightnessDown, Qt::Key_KeyboardBrightnessDown>, - Xkb2Qt<XKB_KEY_XF86PowerOff, Qt::Key_PowerOff>, - Xkb2Qt<XKB_KEY_XF86WakeUp, Qt::Key_WakeUp>, - Xkb2Qt<XKB_KEY_XF86Eject, Qt::Key_Eject>, - Xkb2Qt<XKB_KEY_XF86ScreenSaver, Qt::Key_ScreenSaver>, - Xkb2Qt<XKB_KEY_XF86WWW, Qt::Key_WWW>, - Xkb2Qt<XKB_KEY_XF86Sleep, Qt::Key_Sleep>, - Xkb2Qt<XKB_KEY_XF86LightBulb, Qt::Key_LightBulb>, - Xkb2Qt<XKB_KEY_XF86Shop, Qt::Key_Shop>, - Xkb2Qt<XKB_KEY_XF86History, Qt::Key_History>, - Xkb2Qt<XKB_KEY_XF86AddFavorite, Qt::Key_AddFavorite>, - Xkb2Qt<XKB_KEY_XF86HotLinks, Qt::Key_HotLinks>, - Xkb2Qt<XKB_KEY_XF86BrightnessAdjust, Qt::Key_BrightnessAdjust>, - Xkb2Qt<XKB_KEY_XF86Finance, Qt::Key_Finance>, - Xkb2Qt<XKB_KEY_XF86Community, Qt::Key_Community>, - Xkb2Qt<XKB_KEY_XF86AudioRewind, Qt::Key_AudioRewind>, - Xkb2Qt<XKB_KEY_XF86BackForward, Qt::Key_BackForward>, - Xkb2Qt<XKB_KEY_XF86ApplicationLeft, Qt::Key_ApplicationLeft>, - Xkb2Qt<XKB_KEY_XF86ApplicationRight, Qt::Key_ApplicationRight>, - Xkb2Qt<XKB_KEY_XF86Book, Qt::Key_Book>, - Xkb2Qt<XKB_KEY_XF86CD, Qt::Key_CD>, - Xkb2Qt<XKB_KEY_XF86Calculater, Qt::Key_Calculator>, - Xkb2Qt<XKB_KEY_XF86Clear, Qt::Key_Clear>, - Xkb2Qt<XKB_KEY_XF86ClearGrab, Qt::Key_ClearGrab>, - Xkb2Qt<XKB_KEY_XF86Close, Qt::Key_Close>, - Xkb2Qt<XKB_KEY_XF86Copy, Qt::Key_Copy>, - Xkb2Qt<XKB_KEY_XF86Cut, Qt::Key_Cut>, - Xkb2Qt<XKB_KEY_XF86Display, Qt::Key_Display>, - Xkb2Qt<XKB_KEY_XF86DOS, Qt::Key_DOS>, - Xkb2Qt<XKB_KEY_XF86Documents, Qt::Key_Documents>, - Xkb2Qt<XKB_KEY_XF86Excel, Qt::Key_Excel>, - Xkb2Qt<XKB_KEY_XF86Explorer, Qt::Key_Explorer>, - Xkb2Qt<XKB_KEY_XF86Game, Qt::Key_Game>, - Xkb2Qt<XKB_KEY_XF86Go, Qt::Key_Go>, - Xkb2Qt<XKB_KEY_XF86iTouch, Qt::Key_iTouch>, - Xkb2Qt<XKB_KEY_XF86LogOff, Qt::Key_LogOff>, - Xkb2Qt<XKB_KEY_XF86Market, Qt::Key_Market>, - Xkb2Qt<XKB_KEY_XF86Meeting, Qt::Key_Meeting>, - Xkb2Qt<XKB_KEY_XF86MenuKB, Qt::Key_MenuKB>, - Xkb2Qt<XKB_KEY_XF86MenuPB, Qt::Key_MenuPB>, - Xkb2Qt<XKB_KEY_XF86MySites, Qt::Key_MySites>, - Xkb2Qt<XKB_KEY_XF86New, Qt::Key_New>, - Xkb2Qt<XKB_KEY_XF86News, Qt::Key_News>, - Xkb2Qt<XKB_KEY_XF86OfficeHome, Qt::Key_OfficeHome>, - Xkb2Qt<XKB_KEY_XF86Open, Qt::Key_Open>, - Xkb2Qt<XKB_KEY_XF86Option, Qt::Key_Option>, - Xkb2Qt<XKB_KEY_XF86Paste, Qt::Key_Paste>, - Xkb2Qt<XKB_KEY_XF86Phone, Qt::Key_Phone>, - Xkb2Qt<XKB_KEY_XF86Reply, Qt::Key_Reply>, - Xkb2Qt<XKB_KEY_XF86Reload, Qt::Key_Reload>, - Xkb2Qt<XKB_KEY_XF86RotateWindows, Qt::Key_RotateWindows>, - Xkb2Qt<XKB_KEY_XF86RotationPB, Qt::Key_RotationPB>, - Xkb2Qt<XKB_KEY_XF86RotationKB, Qt::Key_RotationKB>, - Xkb2Qt<XKB_KEY_XF86Save, Qt::Key_Save>, - Xkb2Qt<XKB_KEY_XF86Send, Qt::Key_Send>, - Xkb2Qt<XKB_KEY_XF86Spell, Qt::Key_Spell>, - Xkb2Qt<XKB_KEY_XF86SplitScreen, Qt::Key_SplitScreen>, - Xkb2Qt<XKB_KEY_XF86Support, Qt::Key_Support>, - Xkb2Qt<XKB_KEY_XF86TaskPane, Qt::Key_TaskPane>, - Xkb2Qt<XKB_KEY_XF86Terminal, Qt::Key_Terminal>, - Xkb2Qt<XKB_KEY_XF86Tools, Qt::Key_Tools>, - Xkb2Qt<XKB_KEY_XF86Travel, Qt::Key_Travel>, - Xkb2Qt<XKB_KEY_XF86Video, Qt::Key_Video>, - Xkb2Qt<XKB_KEY_XF86Word, Qt::Key_Word>, - Xkb2Qt<XKB_KEY_XF86Xfer, Qt::Key_Xfer>, - Xkb2Qt<XKB_KEY_XF86ZoomIn, Qt::Key_ZoomIn>, - Xkb2Qt<XKB_KEY_XF86ZoomOut, Qt::Key_ZoomOut>, - Xkb2Qt<XKB_KEY_XF86Away, Qt::Key_Away>, - Xkb2Qt<XKB_KEY_XF86Messenger, Qt::Key_Messenger>, - Xkb2Qt<XKB_KEY_XF86WebCam, Qt::Key_WebCam>, - Xkb2Qt<XKB_KEY_XF86MailForward, Qt::Key_MailForward>, - Xkb2Qt<XKB_KEY_XF86Pictures, Qt::Key_Pictures>, - Xkb2Qt<XKB_KEY_XF86Music, Qt::Key_Music>, - Xkb2Qt<XKB_KEY_XF86Battery, Qt::Key_Battery>, - Xkb2Qt<XKB_KEY_XF86Bluetooth, Qt::Key_Bluetooth>, - Xkb2Qt<XKB_KEY_XF86WLAN, Qt::Key_WLAN>, - Xkb2Qt<XKB_KEY_XF86UWB, Qt::Key_UWB>, - Xkb2Qt<XKB_KEY_XF86AudioForward, Qt::Key_AudioForward>, - Xkb2Qt<XKB_KEY_XF86AudioRepeat, Qt::Key_AudioRepeat>, - Xkb2Qt<XKB_KEY_XF86AudioRandomPlay, Qt::Key_AudioRandomPlay>, - Xkb2Qt<XKB_KEY_XF86Subtitle, Qt::Key_Subtitle>, - Xkb2Qt<XKB_KEY_XF86AudioCycleTrack, Qt::Key_AudioCycleTrack>, - Xkb2Qt<XKB_KEY_XF86Time, Qt::Key_Time>, - Xkb2Qt<XKB_KEY_XF86Select, Qt::Key_Select>, - Xkb2Qt<XKB_KEY_XF86View, Qt::Key_View>, - Xkb2Qt<XKB_KEY_XF86TopMenu, Qt::Key_TopMenu>, - Xkb2Qt<XKB_KEY_XF86Red, Qt::Key_Red>, - Xkb2Qt<XKB_KEY_XF86Green, Qt::Key_Green>, - Xkb2Qt<XKB_KEY_XF86Yellow, Qt::Key_Yellow>, - Xkb2Qt<XKB_KEY_XF86Blue, Qt::Key_Blue>, - Xkb2Qt<XKB_KEY_XF86Bluetooth, Qt::Key_Bluetooth>, - Xkb2Qt<XKB_KEY_XF86Suspend, Qt::Key_Suspend>, - Xkb2Qt<XKB_KEY_XF86Hibernate, Qt::Key_Hibernate>, - Xkb2Qt<XKB_KEY_XF86TouchpadToggle, Qt::Key_TouchpadToggle>, - Xkb2Qt<XKB_KEY_XF86TouchpadOn, Qt::Key_TouchpadOn>, - Xkb2Qt<XKB_KEY_XF86TouchpadOff, Qt::Key_TouchpadOff>, - Xkb2Qt<XKB_KEY_XF86AudioMicMute, Qt::Key_MicMute>, - Xkb2Qt<XKB_KEY_XF86Launch0, Qt::Key_Launch2>, // ### Qt 6: remap properly - Xkb2Qt<XKB_KEY_XF86Launch1, Qt::Key_Launch3>, - Xkb2Qt<XKB_KEY_XF86Launch2, Qt::Key_Launch4>, - Xkb2Qt<XKB_KEY_XF86Launch3, Qt::Key_Launch5>, - Xkb2Qt<XKB_KEY_XF86Launch4, Qt::Key_Launch6>, - Xkb2Qt<XKB_KEY_XF86Launch5, Qt::Key_Launch7>, - Xkb2Qt<XKB_KEY_XF86Launch6, Qt::Key_Launch8>, - Xkb2Qt<XKB_KEY_XF86Launch7, Qt::Key_Launch9>, - Xkb2Qt<XKB_KEY_XF86Launch8, Qt::Key_LaunchA>, - Xkb2Qt<XKB_KEY_XF86Launch9, Qt::Key_LaunchB>, - Xkb2Qt<XKB_KEY_XF86LaunchA, Qt::Key_LaunchC>, - Xkb2Qt<XKB_KEY_XF86LaunchB, Qt::Key_LaunchD>, - Xkb2Qt<XKB_KEY_XF86LaunchC, Qt::Key_LaunchE>, - Xkb2Qt<XKB_KEY_XF86LaunchD, Qt::Key_LaunchF>, - Xkb2Qt<XKB_KEY_XF86LaunchE, Qt::Key_LaunchG>, - Xkb2Qt<XKB_KEY_XF86LaunchF, Qt::Key_LaunchH> - >::Data{} -); - -// Possible modifier states. -static const Qt::KeyboardModifiers ModsTbl[] = { - Qt::NoModifier, // 0 - Qt::ShiftModifier, // 1 - Qt::ControlModifier, // 2 - Qt::ControlModifier | Qt::ShiftModifier, // 3 - Qt::AltModifier, // 4 - Qt::AltModifier | Qt::ShiftModifier, // 5 - Qt::AltModifier | Qt::ControlModifier, // 6 - Qt::AltModifier | Qt::ShiftModifier | Qt::ControlModifier, // 7 - Qt::NoModifier // Fall-back to raw Key_*, for non-latin1 kb layouts -}; +QT_BEGIN_NAMESPACE Qt::KeyboardModifiers QXcbKeyboard::translateModifiers(int s) const { - Qt::KeyboardModifiers ret = 0; + Qt::KeyboardModifiers ret = Qt::NoModifier; if (s & XCB_MOD_MASK_SHIFT) ret |= Qt::ShiftModifier; if (s & XCB_MOD_MASK_CONTROL) @@ -473,7 +88,7 @@ static xcb_keysym_t getUnshiftedXKey(xcb_keysym_t unshifted, xcb_keysym_t shifte xcb_keysym_t xlower; xcb_keysym_t xupper; - xkbcommon_XConvertCase(unshifted, &xlower, &xupper); + QXkbCommon::xkbcommon_XConvertCase(unshifted, &xlower, &xupper); if (xlower != xupper // Check if symbol is cased && unshifted == xupper) { // Unshifted must be upper case @@ -805,7 +420,12 @@ void QXcbKeyboard::updateKeymap() updateXKBMods(); - checkForLatinLayout(); + QXkbCommon::verifyHasLatinLayout(m_xkbKeymap.get()); +} + +QList<int> QXcbKeyboard::possibleKeys(const QKeyEvent *event) const +{ + return QXkbCommon::possibleKeys(m_xkbState.get(), event, m_superAsMeta, m_hyperAsMeta); } #if QT_CONFIG(xkb) @@ -918,272 +538,6 @@ void QXcbKeyboard::updateXKBMods() xkb_mods.mod5 = xkb_keymap_mod_get_index(m_xkbKeymap.get(), "Mod5"); } -static bool isLatin(xkb_keysym_t sym) -{ - return ((sym >= 'a' && sym <= 'z') || (sym >= 'A' && sym <= 'Z')); -} - -void QXcbKeyboard::checkForLatinLayout() const -{ - const xkb_layout_index_t layoutCount = xkb_keymap_num_layouts(m_xkbKeymap.get()); - const xcb_keycode_t minKeycode = xkb_keymap_min_keycode(m_xkbKeymap.get()); - const xcb_keycode_t maxKeycode = xkb_keymap_max_keycode(m_xkbKeymap.get()); - - const xkb_keysym_t *keysyms = nullptr; - int nrLatinKeys = 0; - for (xkb_layout_index_t layout = 0; layout < layoutCount; ++layout) { - for (xcb_keycode_t code = minKeycode; code < maxKeycode; ++code) { - xkb_keymap_key_get_syms_by_level(m_xkbKeymap.get(), code, layout, 0, &keysyms); - if (keysyms && isLatin(keysyms[0])) - nrLatinKeys++; - if (nrLatinKeys > 10) // arbitrarily chosen threshold - return; - } - } - // This means that lookupLatinKeysym() will not find anything and latin - // key shortcuts might not work. This is a bug in the affected desktop - // environment. Usually can be solved via system settings by adding e.g. 'us' - // layout to the list of seleced layouts, or by using command line, "setxkbmap - // -layout rus,en". The position of latin key based layout in the list of the - // selected layouts is irrelevant. Properly functioning desktop environments - // handle this behind the scenes, even if no latin key based layout has been - // explicitly listed in the selected layouts. - qCWarning(lcQpaKeyboard, "no keyboard layouts with latin keys present"); -} - -xkb_keysym_t QXcbKeyboard::lookupLatinKeysym(xkb_keycode_t keycode) const -{ - xkb_layout_index_t layout; - xkb_keysym_t sym = XKB_KEY_NoSymbol; - const xkb_layout_index_t layoutCount = xkb_keymap_num_layouts_for_key(m_xkbKeymap.get(), keycode); - const xkb_layout_index_t currentLayout = xkb_state_key_get_layout(m_xkbState.get(), keycode); - // Look at user layouts in the order in which they are defined in system - // settings to find a latin keysym. - for (layout = 0; layout < layoutCount; ++layout) { - if (layout == currentLayout) - continue; - const xkb_keysym_t *syms; - xkb_level_index_t level = xkb_state_key_get_level(m_xkbState.get(), keycode, layout); - if (xkb_keymap_key_get_syms_by_level(m_xkbKeymap.get(), keycode, layout, level, &syms) != 1) - continue; - if (isLatin(syms[0])) { - sym = syms[0]; - break; - } - } - - if (sym == XKB_KEY_NoSymbol) - return sym; - - xkb_mod_mask_t latchedMods = xkb_state_serialize_mods(m_xkbState.get(), XKB_STATE_MODS_LATCHED); - xkb_mod_mask_t lockedMods = xkb_state_serialize_mods(m_xkbState.get(), XKB_STATE_MODS_LOCKED); - - // Check for uniqueness, consider the following setup: - // setxkbmap -layout us,ru,us -variant dvorak,, -option 'grp:ctrl_alt_toggle' (set 'ru' as active). - // In this setup, the user would expect to trigger a ctrl+q shortcut by pressing ctrl+<physical x key>, - // because "US dvorak" is higher up in the layout settings list. This check verifies that an obtained - // 'sym' can not be acquired by any other layout higher up in the user's layout list. If it can be acquired - // then the obtained key is not unique. This prevents ctrl+<physical q key> from generating a ctrl+q - // shortcut in the above described setup. We don't want ctrl+<physical x key> and ctrl+<physical q key> to - // generate the same shortcut event in this case. - const xcb_keycode_t minKeycode = xkb_keymap_min_keycode(m_xkbKeymap.get()); - const xcb_keycode_t maxKeycode = xkb_keymap_max_keycode(m_xkbKeymap.get()); - ScopedXKBState state(xkb_state_new(m_xkbKeymap.get())); - for (xkb_layout_index_t prevLayout = 0; prevLayout < layout; ++prevLayout) { - xkb_state_update_mask(state.get(), 0, latchedMods, lockedMods, 0, 0, prevLayout); - for (xcb_keycode_t code = minKeycode; code < maxKeycode; ++code) { - xkb_keysym_t prevSym = xkb_state_key_get_one_sym(state.get(), code); - if (prevSym == sym) { - sym = XKB_KEY_NoSymbol; - break; - } - } - } - - return sym; -} - -static const char *qtKeyName(int qtKey) -{ - int keyEnumIndex = qt_getQtMetaObject()->indexOfEnumerator("Key"); - QMetaEnum keyEnum = qt_getQtMetaObject()->enumerator(keyEnumIndex); - return keyEnum.valueToKey(qtKey); -} - -QList<int> QXcbKeyboard::possibleKeys(const QKeyEvent *event) const -{ - // turn off the modifier bits which doesn't participate in shortcuts - Qt::KeyboardModifiers notNeeded = Qt::KeypadModifier | Qt::GroupSwitchModifier; - Qt::KeyboardModifiers modifiers = event->modifiers() &= ~notNeeded; - // create a fresh kb state and test against the relevant modifier combinations - struct xkb_state *kb_state = xkb_state_new(m_xkbKeymap.get()); - if (!kb_state) { - qWarning("QXcbKeyboard: failed to compile xkb keymap!"); - return QList<int>(); - } - // get kb state from the master xkb_state and update the temporary kb_state - xkb_layout_index_t lockedLayout = xkb_state_serialize_layout(m_xkbState.get(), XKB_STATE_LAYOUT_LOCKED); - xkb_mod_mask_t latchedMods = xkb_state_serialize_mods(m_xkbState.get(), XKB_STATE_MODS_LATCHED); - xkb_mod_mask_t lockedMods = xkb_state_serialize_mods(m_xkbState.get(), XKB_STATE_MODS_LOCKED); - xkb_mod_mask_t depressedMods = xkb_state_serialize_mods(m_xkbState.get(), XKB_STATE_MODS_DEPRESSED); - - xkb_state_update_mask(kb_state, depressedMods, latchedMods, lockedMods, 0, 0, lockedLayout); - quint32 keycode = event->nativeScanCode(); - // handle shortcuts for level three and above - xkb_layout_index_t layoutIndex = xkb_state_key_get_layout(kb_state, keycode); - xkb_level_index_t levelIndex = 0; - if (layoutIndex != XKB_LAYOUT_INVALID) { - levelIndex = xkb_state_key_get_level(kb_state, keycode, layoutIndex); - if (levelIndex == XKB_LEVEL_INVALID) - levelIndex = 0; - } - if (levelIndex <= 1) - xkb_state_update_mask(kb_state, 0, latchedMods, lockedMods, 0, 0, lockedLayout); - - xkb_keysym_t sym = xkb_state_key_get_one_sym(kb_state, keycode); - if (sym == XKB_KEY_NoSymbol) { - xkb_state_unref(kb_state); - return QList<int>(); - } - - QList<int> result; - int baseQtKey = keysymToQtKey(sym, modifiers, kb_state, keycode); - if (baseQtKey) - result += (baseQtKey + modifiers); - - xkb_mod_index_t shiftMod = xkb_keymap_mod_get_index(m_xkbKeymap.get(), "Shift"); - xkb_mod_index_t altMod = xkb_keymap_mod_get_index(m_xkbKeymap.get(), "Alt"); - xkb_mod_index_t controlMod = xkb_keymap_mod_get_index(m_xkbKeymap.get(), "Control"); - xkb_mod_index_t metaMod = xkb_keymap_mod_get_index(m_xkbKeymap.get(), "Meta"); - - Q_ASSERT(shiftMod < 32); - Q_ASSERT(altMod < 32); - Q_ASSERT(controlMod < 32); - - xkb_mod_mask_t depressed; - int qtKey = 0; - // obtain a list of possible shortcuts for the given key event - for (uint i = 1; i < sizeof(ModsTbl) / sizeof(*ModsTbl) ; ++i) { - Qt::KeyboardModifiers neededMods = ModsTbl[i]; - if ((modifiers & neededMods) == neededMods) { - if (i == 8) { - if (isLatin(baseQtKey)) - continue; - // add a latin key as a fall back key - sym = lookupLatinKeysym(keycode); - } else { - depressed = 0; - if (neededMods & Qt::AltModifier) - depressed |= (1 << altMod); - if (neededMods & Qt::ShiftModifier) - depressed |= (1 << shiftMod); - if (neededMods & Qt::ControlModifier) - depressed |= (1 << controlMod); - if (metaMod < 32 && neededMods & Qt::MetaModifier) - depressed |= (1 << metaMod); - xkb_state_update_mask(kb_state, depressed, latchedMods, lockedMods, 0, 0, lockedLayout); - sym = xkb_state_key_get_one_sym(kb_state, keycode); - } - if (sym == XKB_KEY_NoSymbol) - continue; - - Qt::KeyboardModifiers mods = modifiers & ~neededMods; - qtKey = keysymToQtKey(sym, mods, kb_state, keycode); - if (!qtKey || qtKey == baseQtKey) - continue; - - // catch only more specific shortcuts, i.e. Ctrl+Shift+= also generates Ctrl++ and +, - // but Ctrl++ is more specific than +, so we should skip the last one - bool ambiguous = false; - for (int shortcut : qAsConst(result)) { - if (int(shortcut & ~Qt::KeyboardModifierMask) == qtKey && (shortcut & mods) == mods) { - ambiguous = true; - break; - } - } - if (ambiguous) - continue; - - result += (qtKey + mods); - } - } - xkb_state_unref(kb_state); - return result; -} - -int QXcbKeyboard::keysymToQtKey(xcb_keysym_t keysym, Qt::KeyboardModifiers modifiers, - struct xkb_state *state, xcb_keycode_t code) const -{ - int qtKey = 0; - - // lookup from direct mapping - if (keysym >= XKB_KEY_F1 && keysym <= XKB_KEY_F35) { - // function keys - qtKey = Qt::Key_F1 + (keysym - XKB_KEY_F1); - } else if (keysym >= XKB_KEY_KP_0 && keysym <= XKB_KEY_KP_9) { - // numeric keypad keys - qtKey = Qt::Key_0 + (keysym - XKB_KEY_KP_0); - } else if (isLatin(keysym)) { - qtKey = xkbcommon_xkb_keysym_to_upper(keysym); - } else { - // check if we have a direct mapping - xkb2qt_t searchKey{keysym, 0}; - auto it = std::lower_bound(KeyTbl.cbegin(), KeyTbl.cend(), searchKey); - if (it != KeyTbl.end() && !(searchKey < *it)) - qtKey = it->qt; - } - - QString text; - bool fromUnicode = qtKey == 0; - if (fromUnicode) { // lookup from unicode - if (modifiers & Qt::ControlModifier) { - // Control modifier changes the text to ASCII control character, therefore we - // can't use this text to map keysym to a qt key. We can use the same keysym - // (it is not affectd by transformation) to obtain untransformed text. For details - // see "Appendix A. Default Symbol Transformations" in the XKB specification. - text = lookupStringNoKeysymTransformations(keysym); - } else { - text = lookupString(state, code); - } - if (!text.isEmpty()) { - if (text.unicode()->isDigit()) { - // Ensures that also non-latin digits are mapped to corresponding qt keys, - // e.g CTRL + ۲ (arabic two), is mapped to CTRL + Qt::Key_2. - qtKey = Qt::Key_0 + text.unicode()->digitValue(); - } else { - qtKey = text.unicode()->toUpper().unicode(); - } - } - } - - if (rmod_masks.meta) { - // translate Super/Hyper keys to Meta if we're using them as the MetaModifier - if (rmod_masks.meta == rmod_masks.super && (qtKey == Qt::Key_Super_L - || qtKey == Qt::Key_Super_R)) { - qtKey = Qt::Key_Meta; - } else if (rmod_masks.meta == rmod_masks.hyper && (qtKey == Qt::Key_Hyper_L - || qtKey == Qt::Key_Hyper_R)) { - qtKey = Qt::Key_Meta; - } - } - - if (Q_UNLIKELY(lcQpaKeyboard().isDebugEnabled())) { - char keysymName[64]; - xkb_keysym_get_name(keysym, keysymName, sizeof(keysymName)); - QString keysymInHex = QString(QStringLiteral("0x%1")).arg(keysym, 0, 16); - if (qtKeyName(qtKey)) { - qCDebug(lcQpaKeyboard).nospace() << "keysym: " << keysymName << "(" - << keysymInHex << ") mapped to Qt::" << qtKeyName(qtKey) << " | text: " << text - << " | qt key: " << qtKey << " mapped from unicode number: " << fromUnicode; - } else { - qCDebug(lcQpaKeyboard).nospace() << "no Qt::Key for keysym: " << keysymName - << "(" << keysymInHex << ") | text: " << text << " | qt key: " << qtKey; - } - } - - return qtKey; -} - QXcbKeyboard::QXcbKeyboard(QXcbConnection *connection) : QXcbObject(connection) { @@ -1211,6 +565,12 @@ QXcbKeyboard::~QXcbKeyboard() xcb_key_symbols_free(m_key_symbols); } +void QXcbKeyboard::initialize() +{ + auto inputContext = QGuiApplicationPrivate::platformIntegration()->inputContext(); + QXkbCommon::setXkbContext(inputContext, m_xkbContext.get()); +} + void QXcbKeyboard::selectEvents() { #if QT_CONFIG(xkb) @@ -1514,6 +874,12 @@ void QXcbKeyboard::resolveMaskConflicts() rmod_masks.meta = rmod_masks.hyper; } } + + // translate Super/Hyper keys to Meta if we're using them as the MetaModifier + if (rmod_masks.meta && rmod_masks.meta == rmod_masks.super) + m_superAsMeta = true; + if (rmod_masks.meta && rmod_masks.meta == rmod_masks.hyper) + m_hyperAsMeta = true; } void QXcbKeyboard::handleKeyEvent(xcb_window_t sourceWindow, QEvent::Type type, xcb_keycode_t code, @@ -1529,7 +895,7 @@ void QXcbKeyboard::handleKeyEvent(xcb_window_t sourceWindow, QEvent::Type type, if (type == QEvent::KeyPress) targetWindow->updateNetWmUserTime(time); - ScopedXKBState sendEventState; + QXkbCommon::ScopedXKBState sendEventState; if (fromSendEvent) { // Have a temporary keyboard state filled in from state // this way we allow for synthetic events to have different state @@ -1546,30 +912,13 @@ void QXcbKeyboard::handleKeyEvent(xcb_window_t sourceWindow, QEvent::Type type, struct xkb_state *xkbState = fromSendEvent ? sendEventState.get() : m_xkbState.get(); xcb_keysym_t sym = xkb_state_key_get_one_sym(xkbState, code); - QString text = lookupString(xkbState, code); + QString text = QXkbCommon::lookupString(xkbState, code); Qt::KeyboardModifiers modifiers = translateModifiers(state); - if (sym >= XKB_KEY_KP_Space && sym <= XKB_KEY_KP_9) + if (QXkbCommon::isKeypad(sym)) modifiers |= Qt::KeypadModifier; - // Note 1: All standard key sequences on linux (as defined in platform theme) - // that use a latin character also contain a control modifier, which is why - // checking for Qt::ControlModifier is sufficient here. It is possible to - // override QPlatformTheme::keyBindings() and provide custom sequences for - // QKeySequence::StandardKey. Custom sequences probably should respect this - // convention (alternatively, we could test against other modifiers here). - // Note 2: The possibleKeys() shorcut mechanism is not affected by this value - // adjustment and does its own thing. - xcb_keysym_t latinKeysym = XKB_KEY_NoSymbol; - if (modifiers & Qt::ControlModifier) { - // With standard shortcuts we should prefer a latin character, this is - // in checks like "event == QKeySequence::Copy". - if (!isLatin(sym)) - latinKeysym = lookupLatinKeysym(code); - } - - int qtcode = keysymToQtKey(latinKeysym != XKB_KEY_NoSymbol ? latinKeysym : sym, - modifiers, xkbState, code); + int qtcode = QXkbCommon::keysymToQtKey(sym, modifiers, xkbState, code, m_superAsMeta, m_hyperAsMeta); if (type == QEvent::KeyPress) { if (m_isAutoRepeat && m_autoRepeatCode != code) @@ -1611,28 +960,6 @@ void QXcbKeyboard::handleKeyEvent(xcb_window_t sourceWindow, QEvent::Type type, } } -QString QXcbKeyboard::lookupString(struct xkb_state *state, xcb_keycode_t code) const -{ - QVarLengthArray<char, 32> chars(32); - const int size = xkb_state_key_get_utf8(state, code, chars.data(), chars.size()); - if (Q_UNLIKELY(size + 1 > chars.size())) { // +1 for NUL - chars.resize(size + 1); - xkb_state_key_get_utf8(state, code, chars.data(), chars.size()); - } - return QString::fromUtf8(chars.constData(), size); -} - -QString QXcbKeyboard::lookupStringNoKeysymTransformations(xkb_keysym_t keysym) const -{ - QVarLengthArray<char, 32> chars(32); - const int size = xkb_keysym_to_utf8(keysym, chars.data(), chars.size()); - if (Q_UNLIKELY(size > chars.size())) { - chars.resize(size); - xkb_keysym_to_utf8(keysym, chars.data(), chars.size()); - } - return QString::fromUtf8(chars.constData(), size); -} - static bool fromSendEvent(const void *event) { // From X11 protocol: Every event contains an 8-bit type code. The most diff --git a/src/plugins/platforms/xcb/qxcbkeyboard.h b/src/plugins/platforms/xcb/qxcbkeyboard.h index f8490592b7..e35c82ad24 100644 --- a/src/plugins/platforms/xcb/qxcbkeyboard.h +++ b/src/plugins/platforms/xcb/qxcbkeyboard.h @@ -50,16 +50,12 @@ #endif #include <xkbcommon/xkbcommon.h> -#if QT_CONFIG(xkb) -#include <xkbcommon/xkbcommon-x11.h> -#endif +#include <QtXkbCommonSupport/private/qxkbcommon_p.h> #include <QEvent> QT_BEGIN_NAMESPACE -class QWindow; - class QXcbKeyboard : public QXcbObject { public: @@ -67,6 +63,7 @@ public: ~QXcbKeyboard(); + void initialize(); void selectEvents(); void handleKeyPressEvent(const xcb_key_press_event_t *event); @@ -75,7 +72,7 @@ public: Qt::KeyboardModifiers translateModifiers(int s) const; void updateKeymap(xcb_mapping_notify_event_t *event); void updateKeymap(); - QList<int> possibleKeys(const QKeyEvent *e) const; + QList<int> possibleKeys(const QKeyEvent *event) const; // when XKEYBOARD not present on the X server void updateXKBMods(); @@ -96,10 +93,6 @@ protected: quint16 state, xcb_timestamp_t time, bool fromSendEvent); void resolveMaskConflicts(); - QString lookupString(struct xkb_state *state, xcb_keycode_t code) const; - QString lookupStringNoKeysymTransformations(xkb_keysym_t keysym) const; - int keysymToQtKey(xcb_keysym_t keysym, Qt::KeyboardModifiers modifiers, - struct xkb_state *state, xcb_keycode_t code) const; typedef QMap<xcb_keysym_t, int> KeysymModifierMap; struct xkb_keymap *keymapFromCore(const KeysymModifierMap &keysymMods); @@ -111,9 +104,6 @@ protected: void updateVModMapping(); void updateVModToRModMapping(); - xkb_keysym_t lookupLatinKeysym(xkb_keycode_t keycode) const; - void checkForLatinLayout() const; - private: bool m_config = false; bool m_isAutoRepeat = false; @@ -148,22 +138,12 @@ private: int core_device_id; #endif - struct XKBStateDeleter { - void operator()(struct xkb_state *state) const { return xkb_state_unref(state); } - }; - struct XKBKeymapDeleter { - void operator()(struct xkb_keymap *keymap) const { return xkb_keymap_unref(keymap); } - }; - struct XKBContextDeleter { - void operator()(struct xkb_context *context) const { return xkb_context_unref(context); } - }; - using ScopedXKBState = std::unique_ptr<struct xkb_state, XKBStateDeleter>; - using ScopedXKBKeymap = std::unique_ptr<struct xkb_keymap, XKBKeymapDeleter>; - using ScopedXKBContext = std::unique_ptr<struct xkb_context, XKBContextDeleter>; + QXkbCommon::ScopedXKBState m_xkbState; + QXkbCommon::ScopedXKBKeymap m_xkbKeymap; + QXkbCommon::ScopedXKBContext m_xkbContext; - ScopedXKBState m_xkbState; - ScopedXKBKeymap m_xkbKeymap; - ScopedXKBContext m_xkbContext; + bool m_superAsMeta = false; + bool m_hyperAsMeta = false; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/qxcbxkbcommon.h b/src/plugins/platforms/xcb/qxcbxkbcommon.h deleted file mode 100644 index 422c0c0f12..0000000000 --- a/src/plugins/platforms/xcb/qxcbxkbcommon.h +++ /dev/null @@ -1,233 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/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 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/* XConvertCase was copied from src/3rdparty/xkbcommon/src/keysym.c, - which contains the following license information: - - Copyright 1985, 1987, 1990, 1998 The Open Group - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - Except as contained in this notice, the names of the authors or their - institutions shall not be used in advertising or otherwise to promote the - sale, use or other dealings in this Software without prior written - authorization from the authors. - - - - Copyright © 2009 Dan Nicholson - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice (including the next - paragraph) shall be included in all copies or substantial portions of the - Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -/* - The following code modifications were applied: - - XConvertCase() was renamed to xkbcommon_XConvertCase(), to not confuse it - with Xlib's XConvertCase(). - - UCSConvertCase() was renamed to qt_UCSConvertCase() and function's body was - replaced to use Qt APIs for doing case conversion, which should give us better - results instead of using the less complete version from keysym.c -*/ - -#include <xkbcommon/xkbcommon.h> -#include <QtCore/QChar> - -QT_BEGIN_NAMESPACE - -static void qt_UCSConvertCase(uint32_t code, xkb_keysym_t *lower, xkb_keysym_t *upper) -{ - *lower = QChar::toLower(code); - *upper = QChar::toUpper(code); -} - -void xkbcommon_XConvertCase(xkb_keysym_t sym, xkb_keysym_t *lower, xkb_keysym_t *upper) -{ - /* Latin 1 keysym */ - if (sym < 0x100) { - qt_UCSConvertCase(sym, lower, upper); - return; - } - - /* Unicode keysym */ - if ((sym & 0xff000000) == 0x01000000) { - qt_UCSConvertCase((sym & 0x00ffffff), lower, upper); - *upper |= 0x01000000; - *lower |= 0x01000000; - return; - } - - /* Legacy keysym */ - - *lower = sym; - *upper = sym; - - switch (sym >> 8) { - case 1: /* Latin 2 */ - /* Assume the KeySym is a legal value (ignore discontinuities) */ - if (sym == XKB_KEY_Aogonek) - *lower = XKB_KEY_aogonek; - else if (sym >= XKB_KEY_Lstroke && sym <= XKB_KEY_Sacute) - *lower += (XKB_KEY_lstroke - XKB_KEY_Lstroke); - else if (sym >= XKB_KEY_Scaron && sym <= XKB_KEY_Zacute) - *lower += (XKB_KEY_scaron - XKB_KEY_Scaron); - else if (sym >= XKB_KEY_Zcaron && sym <= XKB_KEY_Zabovedot) - *lower += (XKB_KEY_zcaron - XKB_KEY_Zcaron); - else if (sym == XKB_KEY_aogonek) - *upper = XKB_KEY_Aogonek; - else if (sym >= XKB_KEY_lstroke && sym <= XKB_KEY_sacute) - *upper -= (XKB_KEY_lstroke - XKB_KEY_Lstroke); - else if (sym >= XKB_KEY_scaron && sym <= XKB_KEY_zacute) - *upper -= (XKB_KEY_scaron - XKB_KEY_Scaron); - else if (sym >= XKB_KEY_zcaron && sym <= XKB_KEY_zabovedot) - *upper -= (XKB_KEY_zcaron - XKB_KEY_Zcaron); - else if (sym >= XKB_KEY_Racute && sym <= XKB_KEY_Tcedilla) - *lower += (XKB_KEY_racute - XKB_KEY_Racute); - else if (sym >= XKB_KEY_racute && sym <= XKB_KEY_tcedilla) - *upper -= (XKB_KEY_racute - XKB_KEY_Racute); - break; - case 2: /* Latin 3 */ - /* Assume the KeySym is a legal value (ignore discontinuities) */ - if (sym >= XKB_KEY_Hstroke && sym <= XKB_KEY_Hcircumflex) - *lower += (XKB_KEY_hstroke - XKB_KEY_Hstroke); - else if (sym >= XKB_KEY_Gbreve && sym <= XKB_KEY_Jcircumflex) - *lower += (XKB_KEY_gbreve - XKB_KEY_Gbreve); - else if (sym >= XKB_KEY_hstroke && sym <= XKB_KEY_hcircumflex) - *upper -= (XKB_KEY_hstroke - XKB_KEY_Hstroke); - else if (sym >= XKB_KEY_gbreve && sym <= XKB_KEY_jcircumflex) - *upper -= (XKB_KEY_gbreve - XKB_KEY_Gbreve); - else if (sym >= XKB_KEY_Cabovedot && sym <= XKB_KEY_Scircumflex) - *lower += (XKB_KEY_cabovedot - XKB_KEY_Cabovedot); - else if (sym >= XKB_KEY_cabovedot && sym <= XKB_KEY_scircumflex) - *upper -= (XKB_KEY_cabovedot - XKB_KEY_Cabovedot); - break; - case 3: /* Latin 4 */ - /* Assume the KeySym is a legal value (ignore discontinuities) */ - if (sym >= XKB_KEY_Rcedilla && sym <= XKB_KEY_Tslash) - *lower += (XKB_KEY_rcedilla - XKB_KEY_Rcedilla); - else if (sym >= XKB_KEY_rcedilla && sym <= XKB_KEY_tslash) - *upper -= (XKB_KEY_rcedilla - XKB_KEY_Rcedilla); - else if (sym == XKB_KEY_ENG) - *lower = XKB_KEY_eng; - else if (sym == XKB_KEY_eng) - *upper = XKB_KEY_ENG; - else if (sym >= XKB_KEY_Amacron && sym <= XKB_KEY_Umacron) - *lower += (XKB_KEY_amacron - XKB_KEY_Amacron); - else if (sym >= XKB_KEY_amacron && sym <= XKB_KEY_umacron) - *upper -= (XKB_KEY_amacron - XKB_KEY_Amacron); - break; - case 6: /* Cyrillic */ - /* Assume the KeySym is a legal value (ignore discontinuities) */ - if (sym >= XKB_KEY_Serbian_DJE && sym <= XKB_KEY_Serbian_DZE) - *lower -= (XKB_KEY_Serbian_DJE - XKB_KEY_Serbian_dje); - else if (sym >= XKB_KEY_Serbian_dje && sym <= XKB_KEY_Serbian_dze) - *upper += (XKB_KEY_Serbian_DJE - XKB_KEY_Serbian_dje); - else if (sym >= XKB_KEY_Cyrillic_YU && sym <= XKB_KEY_Cyrillic_HARDSIGN) - *lower -= (XKB_KEY_Cyrillic_YU - XKB_KEY_Cyrillic_yu); - else if (sym >= XKB_KEY_Cyrillic_yu && sym <= XKB_KEY_Cyrillic_hardsign) - *upper += (XKB_KEY_Cyrillic_YU - XKB_KEY_Cyrillic_yu); - break; - case 7: /* Greek */ - /* Assume the KeySym is a legal value (ignore discontinuities) */ - if (sym >= XKB_KEY_Greek_ALPHAaccent && sym <= XKB_KEY_Greek_OMEGAaccent) - *lower += (XKB_KEY_Greek_alphaaccent - XKB_KEY_Greek_ALPHAaccent); - else if (sym >= XKB_KEY_Greek_alphaaccent && sym <= XKB_KEY_Greek_omegaaccent && - sym != XKB_KEY_Greek_iotaaccentdieresis && - sym != XKB_KEY_Greek_upsilonaccentdieresis) - *upper -= (XKB_KEY_Greek_alphaaccent - XKB_KEY_Greek_ALPHAaccent); - else if (sym >= XKB_KEY_Greek_ALPHA && sym <= XKB_KEY_Greek_OMEGA) - *lower += (XKB_KEY_Greek_alpha - XKB_KEY_Greek_ALPHA); - else if (sym >= XKB_KEY_Greek_alpha && sym <= XKB_KEY_Greek_omega && - sym != XKB_KEY_Greek_finalsmallsigma) - *upper -= (XKB_KEY_Greek_alpha - XKB_KEY_Greek_ALPHA); - break; - case 0x13: /* Latin 9 */ - if (sym == XKB_KEY_OE) - *lower = XKB_KEY_oe; - else if (sym == XKB_KEY_oe) - *upper = XKB_KEY_OE; - else if (sym == XKB_KEY_Ydiaeresis) - *lower = XKB_KEY_ydiaeresis; - break; - } -} - -xkb_keysym_t xkbcommon_xkb_keysym_to_upper(xkb_keysym_t ks) -{ - xkb_keysym_t lower, upper; - - xkbcommon_XConvertCase(ks, &lower, &upper); - - return upper; -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/xcb_qpa_lib.pro b/src/plugins/platforms/xcb/xcb_qpa_lib.pro index db3d6629b3..34c671c8c7 100644 --- a/src/plugins/platforms/xcb/xcb_qpa_lib.pro +++ b/src/plugins/platforms/xcb/xcb_qpa_lib.pro @@ -6,7 +6,8 @@ QT += \ core-private gui-private \ service_support-private theme_support-private \ fontdatabase_support-private \ - edid_support-private + edid_support-private \ + xkbcommon_support-private qtHaveModule(linuxaccessibility_support-private): \ QT += linuxaccessibility_support-private @@ -52,7 +53,6 @@ HEADERS = \ qxcbimage.h \ qxcbxsettings.h \ qxcbsystemtraytracker.h \ - qxcbxkbcommon.h \ qxcbeventqueue.h \ qxcbeventdispatcher.h \ qxcbconnection_basic.h \ |