qevdevkeyboardmanager.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9