Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||
2 | ** | - | ||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||
5 | ** | - | ||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||
7 | ** | - | ||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||
9 | ** Commercial License Usage | - | ||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||
16 | ** | - | ||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||
25 | ** | - | ||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||
29 | ** | - | ||||||
30 | ** $QT_END_LICENSE$ | - | ||||||
31 | ** | - | ||||||
32 | ****************************************************************************/ | - | ||||||
33 | - | |||||||
34 | #include "qevdevkeyboardmanager_p.h" | - | ||||||
35 | - | |||||||
36 | #include <QStringList> | - | ||||||
37 | #include <QCoreApplication> | - | ||||||
38 | #include <QLoggingCategory> | - | ||||||
39 | - | |||||||
40 | #include <private/qguiapplication_p.h> | - | ||||||
41 | #include <private/qinputdevicemanager_p_p.h> | - | ||||||
42 | - | |||||||
43 | QT_BEGIN_NAMESPACE | - | ||||||
44 | - | |||||||
45 | Q_DECLARE_LOGGING_CATEGORY(qLcEvdevKey) | - | ||||||
46 | - | |||||||
47 | QEvdevKeyboardManager::QEvdevKeyboardManager(const QString &key, const QString &specification, QObject *parent) | - | ||||||
48 | : QObject(parent) | - | ||||||
49 | { | - | ||||||
50 | Q_UNUSED(key); | - | ||||||
51 | - | |||||||
52 | - | |||||||
53 | QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_EVDEV_KEYBOARD_PARAMETERS")); | - | ||||||
54 | - | |||||||
55 | if (spec.isEmpty())
| 0 | ||||||
56 | spec = specification; never executed: spec = specification; | 0 | ||||||
57 | - | |||||||
58 | QStringList args = spec.split(QLatin1Char(':')); | - | ||||||
59 | QStringList devices; | - | ||||||
60 | - | |||||||
61 | foreach (const QString &arg, args) { | - | ||||||
62 | if (arg.startsWith(QLatin1String("/dev/"))) {
| 0 | ||||||
63 | // if device is specified try to use it | - | ||||||
64 | devices.append(arg); | - | ||||||
65 | args.removeAll(arg); | - | ||||||
66 | } never executed: end of block | 0 | ||||||
67 | } never executed: end of block | 0 | ||||||
68 | - | |||||||
69 | // build new specification without /dev/ elements | - | ||||||
70 | m_spec = args.join(QLatin1Char(':')); | - | ||||||
71 | - | |||||||
72 | // add all keyboards for devices specified in the argument list | - | ||||||
73 | foreach (const QString &device, devices) | - | ||||||
74 | addKeyboard(device); never executed: addKeyboard(device); | 0 | ||||||
75 | - | |||||||
76 | if (devices.isEmpty()) {
| 0 | ||||||
77 | qCDebug(qLcEvdevKey) << "evdevkeyboard: Using device discovery"; never executed: QMessageLogger(__FILE__, 77, __PRETTY_FUNCTION__, qLcEvdevKey().categoryName()).debug() << "evdevkeyboard: Using device discovery";
| 0 | ||||||
78 | m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Keyboard, this); | - | ||||||
79 | if (m_deviceDiscovery) {
| 0 | ||||||
80 | // scan and add already connected keyboards | - | ||||||
81 | QStringList devices = m_deviceDiscovery->scanConnectedDevices(); | - | ||||||
82 | foreach (const QString &device, devices) { | - | ||||||
83 | addKeyboard(device); | - | ||||||
84 | } never executed: end of block | 0 | ||||||
85 | - | |||||||
86 | connect(m_deviceDiscovery, SIGNAL(deviceDetected(QString)), this, SLOT(addKeyboard(QString))); | - | ||||||
87 | connect(m_deviceDiscovery, SIGNAL(deviceRemoved(QString)), this, SLOT(removeKeyboard(QString))); | - | ||||||
88 | } never executed: end of block | 0 | ||||||
89 | } never executed: end of block | 0 | ||||||
90 | } never executed: end of block | 0 | ||||||
91 | - | |||||||
92 | QEvdevKeyboardManager::~QEvdevKeyboardManager() | - | ||||||
93 | { | - | ||||||
94 | qDeleteAll(m_keyboards); | - | ||||||
95 | m_keyboards.clear(); | - | ||||||
96 | } never executed: end of block | 0 | ||||||
97 | - | |||||||
98 | void QEvdevKeyboardManager::addKeyboard(const QString &deviceNode) | - | ||||||
99 | { | - | ||||||
100 | qCDebug(qLcEvdevKey) << "Adding keyboard at" << deviceNode; never executed: QMessageLogger(__FILE__, 100, __PRETTY_FUNCTION__, qLcEvdevKey().categoryName()).debug() << "Adding keyboard at" << deviceNode;
| 0 | ||||||
101 | QEvdevKeyboardHandler *keyboard; | - | ||||||
102 | keyboard = QEvdevKeyboardHandler::create(deviceNode, m_spec, m_defaultKeymapFile); | - | ||||||
103 | if (keyboard) {
| 0 | ||||||
104 | m_keyboards.insert(deviceNode, keyboard); | - | ||||||
105 | QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( | - | ||||||
106 | QInputDeviceManager::DeviceTypeKeyboard, m_keyboards.count()); | - | ||||||
107 | } else { never executed: end of block | 0 | ||||||
108 | qWarning("Failed to open keyboard device %s", qPrintable(deviceNode)); | - | ||||||
109 | } never executed: end of block | 0 | ||||||
110 | } | - | ||||||
111 | - | |||||||
112 | void QEvdevKeyboardManager::removeKeyboard(const QString &deviceNode) | - | ||||||
113 | { | - | ||||||
114 | if (m_keyboards.contains(deviceNode)) {
| 0 | ||||||
115 | qCDebug(qLcEvdevKey) << "Removing keyboard at" << deviceNode; never executed: QMessageLogger(__FILE__, 115, __PRETTY_FUNCTION__, qLcEvdevKey().categoryName()).debug() << "Removing keyboard at" << deviceNode;
| 0 | ||||||
116 | QEvdevKeyboardHandler *keyboard = m_keyboards.value(deviceNode); | - | ||||||
117 | m_keyboards.remove(deviceNode); | - | ||||||
118 | QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( | - | ||||||
119 | QInputDeviceManager::DeviceTypeKeyboard, m_keyboards.count()); | - | ||||||
120 | delete keyboard; | - | ||||||
121 | } never executed: end of block | 0 | ||||||
122 | } never executed: end of block | 0 | ||||||
123 | - | |||||||
124 | void QEvdevKeyboardManager::loadKeymap(const QString &file) | - | ||||||
125 | { | - | ||||||
126 | m_defaultKeymapFile = file; | - | ||||||
127 | - | |||||||
128 | if (file.isEmpty()) {
| 0 | ||||||
129 | // Restore the default, which is either the built-in keymap or | - | ||||||
130 | // the one given in the plugin spec. | - | ||||||
131 | QString keymapFromSpec; | - | ||||||
132 | foreach (const QString &arg, m_spec.split(QLatin1Char(':'))) { | - | ||||||
133 | if (arg.startsWith(QLatin1String("keymap=")))
| 0 | ||||||
134 | keymapFromSpec = arg.mid(7); never executed: keymapFromSpec = arg.mid(7); | 0 | ||||||
135 | } never executed: end of block | 0 | ||||||
136 | foreach (QEvdevKeyboardHandler *handler, m_keyboards) { | - | ||||||
137 | if (keymapFromSpec.isEmpty())
| 0 | ||||||
138 | handler->unloadKeymap(); never executed: handler->unloadKeymap(); | 0 | ||||||
139 | else | - | ||||||
140 | handler->loadKeymap(keymapFromSpec); never executed: handler->loadKeymap(keymapFromSpec); | 0 | ||||||
141 | } | - | ||||||
142 | } else { never executed: end of block | 0 | ||||||
143 | foreach (QEvdevKeyboardHandler *handler, m_keyboards) | - | ||||||
144 | handler->loadKeymap(file); never executed: handler->loadKeymap(file); | 0 | ||||||
145 | } never executed: end of block | 0 | ||||||
146 | } | - | ||||||
147 | - | |||||||
148 | QT_END_NAMESPACE | - | ||||||
Source code | Switch to Preprocessed file |