Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qevdevkeyboardmanager.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtInputSupport/private/qevdevutil_p.h>
7
8#include <QStringList>
9#include <QCoreApplication>
10#include <QLoggingCategory>
11
12#include <private/qguiapplication_p.h>
13#include <private/qinputdevicemanager_p_p.h>
14
16
17using namespace Qt::StringLiterals;
18
20
22 : QObject(parent)
23{
25
26
27 QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_EVDEV_KEYBOARD_PARAMETERS"));
28
29 if (spec.isEmpty())
30 spec = specification;
31
32 auto parsed = QEvdevUtil::parseSpecification(spec);
33 m_spec = std::move(parsed.spec);
34
35 // add all keyboards for devices specified in the argument list
36 for (const QString &device : std::as_const(parsed.devices))
37 addKeyboard(device);
38
39 if (parsed.devices.isEmpty()) {
40 qCDebug(qLcEvdevKey, "evdevkeyboard: Using device discovery");
41 if (auto deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Keyboard, this)) {
42 // scan and add already connected keyboards
43 const QStringList devices = deviceDiscovery->scanConnectedDevices();
44 for (const QString &device : devices)
45 addKeyboard(device);
46
51 }
52 }
53}
54
58
60{
61 qCDebug(qLcEvdevKey, "Adding keyboard at %ls", qUtf16Printable(deviceNode));
62 auto keyboard = QEvdevKeyboardHandler::create(deviceNode, m_spec, m_defaultKeymapFile);
63 if (keyboard) {
64 m_keyboards.add(deviceNode, std::move(keyboard));
65 updateDeviceCount();
66 } else {
67 qWarning("Failed to open keyboard device %ls", qUtf16Printable(deviceNode));
68 }
69}
70
72{
73 if (m_keyboards.remove(deviceNode)) {
74 qCDebug(qLcEvdevKey, "Removing keyboard at %ls", qUtf16Printable(deviceNode));
75 updateDeviceCount();
76 }
77}
78
79void QEvdevKeyboardManager::updateDeviceCount()
80{
83}
84
86{
87 m_defaultKeymapFile = file;
88
89 if (file.isEmpty()) {
90 // Restore the default, which is either the built-in keymap or
91 // the one given in the plugin spec.
92 QString keymapFromSpec;
93 const auto specs = QStringView{m_spec}.split(u':');
94 for (const auto &arg : specs) {
95 if (arg.startsWith("keymap="_L1))
96 keymapFromSpec = arg.mid(7).toString();
97 }
98 for (const auto &keyboard : m_keyboards) {
99 if (keymapFromSpec.isEmpty())
100 keyboard.handler->unloadKeymap();
101 else
102 keyboard.handler->loadKeymap(keymapFromSpec);
103 }
104 } else {
105 for (const auto &keyboard : m_keyboards)
106 keyboard.handler->loadKeymap(file);
107 }
108}
109
111{
112 for (const auto &keyboard : m_keyboards)
113 keyboard.handler->switchLang();
114}
115
IOBluetoothDevice * device
void deviceDetected(const QString &deviceNode)
static QDeviceDiscovery * create(QDeviceTypes type, QObject *parent=nullptr)
void deviceRemoved(const QString &deviceNode)
static std::unique_ptr< QEvdevKeyboardHandler > create(const QString &device, const QString &specification, const QString &defaultKeymapFile=QString())
void removeKeyboard(const QString &deviceNode)
void addKeyboard(const QString &deviceNode=QString())
void loadKeymap(const QString &file)
static QInputDeviceManager * inputDeviceManager()
static QInputDeviceManagerPrivate * get(QInputDeviceManager *mgr)
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore
\inmodule QtCore
Definition qstringview.h:78
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QStringList split(const QString &sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the string into substrings wherever sep occurs, and returns the list of those strings.
Definition qstring.cpp:8218
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5949
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
void add(const QString &deviceNode, std::unique_ptr< Handler > handler)
bool remove(const QString &deviceNode)
ParsedSpecification parseSpecification(const QString &specification)
Combined button and popup list for selecting options.
EGLDeviceEXT * devices
#define qWarning
Definition qlogging.h:166
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLuint64 key
SSL_CTX int void * arg
#define qUtf16Printable(string)
Definition qstring.h:1543
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
#define Q_UNUSED(x)
QFile file
[0]
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)