Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
4
#
include
"qevdevkeyboardmanager_p.h"
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
15
QT_BEGIN_NAMESPACE
16
17
using
namespace
Qt::StringLiterals;
18
19
QEvdevKeyboardManager
::
QEvdevKeyboardManager
(
const
QString &key,
const
QString &specification, QObject *parent)
20
:
QObject
(
parent
)
21
{
22
Q_UNUSED(key);
23
24
25
QString spec = qEnvironmentVariable(
"QT_QPA_EVDEV_KEYBOARD_PARAMETERS"
);
26
27
if
(spec.isEmpty())
28
spec = specification;
29
30
auto
parsed = QEvdevUtil::parseSpecification(spec);
31
m_spec = std::move(parsed.spec);
32
33
// add all keyboards for devices specified in the argument list
34
for
(
const
QString &device : std::as_const(parsed.devices))
35
addKeyboard(device);
36
37
if
(parsed.devices.isEmpty()) {
38
qCDebug
(qLcEvdevKey,
"evdevkeyboard: Using device discovery"
);
39
if
(
auto
deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Keyboard,
this
)) {
40
// scan and add already connected keyboards
41
const
QStringList devices = deviceDiscovery->scanConnectedDevices();
42
for
(
const
QString &device : devices)
43
addKeyboard(device);
44
45
connect(deviceDiscovery, &QDeviceDiscovery::deviceDetected,
46
this
, &QEvdevKeyboardManager::addKeyboard);
47
connect(deviceDiscovery, &QDeviceDiscovery::deviceRemoved,
48
this
, &QEvdevKeyboardManager::removeKeyboard);
49
}
50
}
51
}
52
53
QEvdevKeyboardManager
::~
QEvdevKeyboardManager
()
54
{
55
}
56
57
void
QEvdevKeyboardManager
::
addKeyboard
(
const
QString &deviceNode)
58
{
59
qCDebug
(qLcEvdevKey,
"Adding keyboard at %ls"
, qUtf16Printable(deviceNode));
60
auto
keyboard = QEvdevKeyboardHandler::create(deviceNode, m_spec, m_defaultKeymapFile);
61
if
(keyboard) {
62
m_keyboards.add(deviceNode, std::move(keyboard));
63
updateDeviceCount();
64
}
else
{
65
qWarning(
"Failed to open keyboard device %ls"
, qUtf16Printable(deviceNode));
66
}
67
}
68
69
void
QEvdevKeyboardManager
::
removeKeyboard
(
const
QString &deviceNode)
70
{
71
if
(m_keyboards.remove(deviceNode)) {
72
qCDebug
(qLcEvdevKey,
"Removing keyboard at %ls"
, qUtf16Printable(deviceNode));
73
updateDeviceCount();
74
}
75
}
76
77
void
QEvdevKeyboardManager
::updateDeviceCount()
78
{
79
QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount(
80
QInputDeviceManager::DeviceTypeKeyboard, m_keyboards.count());
81
}
82
83
void
QEvdevKeyboardManager
::
loadKeymap
(
const
QString &file)
84
{
85
m_defaultKeymapFile = file;
86
87
if
(file.isEmpty()) {
88
// Restore the default, which is either the built-in keymap or
89
// the one given in the plugin spec.
90
QString keymapFromSpec;
91
const
auto
specs = QStringView{m_spec}.split(u':');
92
for
(
const
auto
&arg : specs) {
93
if
(arg.startsWith(
"keymap="_L1
))
94
keymapFromSpec = arg.mid(7).toString();
95
}
96
for
(
const
auto
&keyboard : m_keyboards) {
97
if
(keymapFromSpec.isEmpty())
98
keyboard.handler->unloadKeymap();
99
else
100
keyboard.handler->loadKeymap(keymapFromSpec);
101
}
102
}
else
{
103
for
(
const
auto
&keyboard : m_keyboards)
104
keyboard.handler->loadKeymap(file);
105
}
106
}
107
108
void
QEvdevKeyboardManager
::
switchLang
()
109
{
110
for
(
const
auto
&keyboard : m_keyboards)
111
keyboard.handler->switchLang();
112
}
113
114
QT_END_NAMESPACE
QEvdevKeyboardManager
Definition
qevdevkeyboardmanager_p.h:30
QEvdevKeyboardManager::removeKeyboard
void removeKeyboard(const QString &deviceNode)
Definition
qevdevkeyboardmanager.cpp:69
QEvdevKeyboardManager::QEvdevKeyboardManager
QEvdevKeyboardManager(const QString &key, const QString &specification, QObject *parent=nullptr)
Definition
qevdevkeyboardmanager.cpp:19
QEvdevKeyboardManager::addKeyboard
void addKeyboard(const QString &deviceNode=QString())
Definition
qevdevkeyboardmanager.cpp:57
QEvdevKeyboardManager::loadKeymap
void loadKeymap(const QString &file)
Definition
qevdevkeyboardmanager.cpp:83
QEvdevKeyboardManager::~QEvdevKeyboardManager
~QEvdevKeyboardManager()
Definition
qevdevkeyboardmanager.cpp:53
QEvdevKeyboardManager::switchLang
void switchLang()
Definition
qevdevkeyboardmanager.cpp:108
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qCDebug
#define qCDebug(category,...)
Definition
qloggingcategory.h:162
qtbase
src
platformsupport
input
evdevkeyboard
qevdevkeyboardmanager.cpp
Generated on
for Qt by
1.18.0