From 0ad5e1626832d80952ef02bfe0457cf61b2f698e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 8 Jun 2019 12:00:05 +0200 Subject: QEvdev: use printf-style qCDebug()/qWarning() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also use qUtf16Printable() and qErrnoWarning (removing explicit errno, where present). Saves 6.6KiB in text size on optimized Linux AMD64 GCC 9.1 build across all .so's that link to QtInputSupport.a. Change-Id: I1def2cfabd2eed65390099cd1d06f8061a9355be Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Mårten Nordheim --- src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp') diff --git a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp index 90949408ac..da4b6e5172 100644 --- a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp +++ b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp @@ -82,7 +82,7 @@ QEvdevTabletManager::QEvdevTabletManager(const QString &key, const QString &spec // when no devices specified, use device discovery to scan and monitor if (devices.isEmpty()) { - qCDebug(qLcEvdevTablet) << "evdevtablet: Using device discovery"; + qCDebug(qLcEvdevTablet, "evdevtablet: Using device discovery"); m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Tablet, this); if (m_deviceDiscovery) { const QStringList devices = m_deviceDiscovery->scanConnectedDevices(); @@ -104,7 +104,7 @@ QEvdevTabletManager::~QEvdevTabletManager() void QEvdevTabletManager::addDevice(const QString &deviceNode) { - qCDebug(qLcEvdevTablet) << "Adding device at" << deviceNode; + qCDebug(qLcEvdevTablet, "Adding device at %ls", qUtf16Printable(deviceNode)); QEvdevTabletHandlerThread *handler; handler = new QEvdevTabletHandlerThread(deviceNode, m_spec); if (handler) { @@ -112,14 +112,14 @@ void QEvdevTabletManager::addDevice(const QString &deviceNode) QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( QInputDeviceManager::DeviceTypeTablet, m_activeDevices.count()); } else { - qWarning("evdevtablet: Failed to open tablet device %s", qPrintable(deviceNode)); + qWarning("evdevtablet: Failed to open tablet device %ls", qUtf16Printable(deviceNode)); } } void QEvdevTabletManager::removeDevice(const QString &deviceNode) { if (m_activeDevices.contains(deviceNode)) { - qCDebug(qLcEvdevTablet) << "Removing device at" << deviceNode; + qCDebug(qLcEvdevTablet, "Removing device at %ls", qUtf16Printable(deviceNode)); QEvdevTabletHandlerThread *handler = m_activeDevices.value(deviceNode); m_activeDevices.remove(deviceNode); QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( -- cgit v1.2.3 From 3f5d27bfda7b6d486d20869b6ce4a4362087d0c9 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 8 Jun 2019 12:00:05 +0200 Subject: QEvdev: Extract Method updateDeviceCount() The code is noisy and repeats, so wrap it in a function. Change-Id: I5e6e924e22b0bc631eb8176de96c49066b1c9029 Reviewed-by: Allan Sandfeld Jensen --- .../input/evdevtablet/qevdevtabletmanager.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp') diff --git a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp index da4b6e5172..eedde9a96e 100644 --- a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp +++ b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp @@ -109,8 +109,7 @@ void QEvdevTabletManager::addDevice(const QString &deviceNode) handler = new QEvdevTabletHandlerThread(deviceNode, m_spec); if (handler) { m_activeDevices.insert(deviceNode, handler); - QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( - QInputDeviceManager::DeviceTypeTablet, m_activeDevices.count()); + updateDeviceCount(); } else { qWarning("evdevtablet: Failed to open tablet device %ls", qUtf16Printable(deviceNode)); } @@ -122,10 +121,15 @@ void QEvdevTabletManager::removeDevice(const QString &deviceNode) qCDebug(qLcEvdevTablet, "Removing device at %ls", qUtf16Printable(deviceNode)); QEvdevTabletHandlerThread *handler = m_activeDevices.value(deviceNode); m_activeDevices.remove(deviceNode); - QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( - QInputDeviceManager::DeviceTypeTablet, m_activeDevices.count()); + updateDeviceCount(); delete handler; } } +void QEvdevTabletManager::updateDeviceCount() +{ + QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( + QInputDeviceManager::DeviceTypeTablet, m_activeDevices.count()); +} + QT_END_NAMESPACE -- cgit v1.2.3 From 3bc10fb9bb930c4e1baf52f9d0ba97616e8e77f6 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 8 Jun 2019 12:00:05 +0200 Subject: QEvdev: Replace manual memory management with unique_ptr Make create() return, and m_mice/m_keyboards/etc store, handlers by unique_ptr. In most cases, we can't use qt_make_unique(), since the ctor we're calling is marked as private. Since QHash can't hold move-only types, use a std::vector<{QString, unique_ptr}> instead. As this pattern repeats in all four QEvdev*Manager classes, create a small class template. Saves almost 6KiB on optimized Linux AMD64 GCC 9.1 builds across all .so's that link to QtInputSupport.a. Change-Id: I8f62b6b629d6e1855314c0a4fb4fc069db9ae0ce Reviewed-by: Allan Sandfeld Jensen --- .../input/evdevtablet/qevdevtabletmanager.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp') diff --git a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp index eedde9a96e..d503476aad 100644 --- a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp +++ b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp @@ -46,6 +46,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -99,16 +100,14 @@ QEvdevTabletManager::QEvdevTabletManager(const QString &key, const QString &spec QEvdevTabletManager::~QEvdevTabletManager() { - qDeleteAll(m_activeDevices); } void QEvdevTabletManager::addDevice(const QString &deviceNode) { qCDebug(qLcEvdevTablet, "Adding device at %ls", qUtf16Printable(deviceNode)); - QEvdevTabletHandlerThread *handler; - handler = new QEvdevTabletHandlerThread(deviceNode, m_spec); + auto handler = qt_make_unique(deviceNode, m_spec); if (handler) { - m_activeDevices.insert(deviceNode, handler); + m_activeDevices.add(deviceNode, std::move(handler)); updateDeviceCount(); } else { qWarning("evdevtablet: Failed to open tablet device %ls", qUtf16Printable(deviceNode)); @@ -117,12 +116,9 @@ void QEvdevTabletManager::addDevice(const QString &deviceNode) void QEvdevTabletManager::removeDevice(const QString &deviceNode) { - if (m_activeDevices.contains(deviceNode)) { + if (m_activeDevices.remove(deviceNode)) { qCDebug(qLcEvdevTablet, "Removing device at %ls", qUtf16Printable(deviceNode)); - QEvdevTabletHandlerThread *handler = m_activeDevices.value(deviceNode); - m_activeDevices.remove(deviceNode); updateDeviceCount(); - delete handler; } } -- cgit v1.2.3 From f1404c0ed1f89df931210a843727a1fd4eaef6a8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 12 Jun 2019 23:41:36 +0200 Subject: QEvdev: Extract Method parseSpecification() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All four manager classes contained roughly the same code in their ctors that parsed out devices from a colon-separated string. Extract shared code, and port the parsing to QStringRef (later to be ported to QStringView). Saves ~2.4KiB on optimized Linux GCC 9.1 AMD64 builds across all .so's that link to libQtInputSupport.a. Change-Id: I3db826ee2b422cfc02f8d49bd21985a03b6c0935 Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Mårten Nordheim --- .../input/evdevtablet/qevdevtabletmanager.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp') diff --git a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp index d503476aad..74d6b19e99 100644 --- a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp +++ b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp @@ -40,6 +40,8 @@ #include "qevdevtabletmanager_p.h" #include "qevdevtablethandler_p.h" +#include + #include #include #include @@ -65,24 +67,14 @@ QEvdevTabletManager::QEvdevTabletManager(const QString &key, const QString &spec if (spec.isEmpty()) spec = specification; - QStringList args = spec.split(QLatin1Char(':')); - QStringList devices; - - foreach (const QString &arg, args) { - if (arg.startsWith(QLatin1String("/dev/"))) { - devices.append(arg); - args.removeAll(arg); - } - } - - // build new specification without /dev/ elements - m_spec = args.join(QLatin1Char(':')); + auto parsed = QEvdevUtil::parseSpecification(spec); + m_spec = std::move(parsed.spec); - foreach (const QString &device, devices) + for (const QString &device : qAsConst(parsed.devices)) addDevice(device); // when no devices specified, use device discovery to scan and monitor - if (devices.isEmpty()) { + if (parsed.devices.isEmpty()) { qCDebug(qLcEvdevTablet, "evdevtablet: Using device discovery"); m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Tablet, this); if (m_deviceDiscovery) { -- cgit v1.2.3 From 779f1ff9fad916ce7beb7dfbf3a96b0207c01319 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 12 Jun 2019 23:58:36 +0200 Subject: QEvdev: remove m_deviceDiscovery members MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They were never referenced outside the classes' ctor and, worse, remained uninitialized if the specification string contained devices. Change-Id: I977a156acf10190428da00fe128fee70cff8f98d Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Mårten Nordheim --- src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp') diff --git a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp index 74d6b19e99..d9888c5b97 100644 --- a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp +++ b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp @@ -76,15 +76,14 @@ QEvdevTabletManager::QEvdevTabletManager(const QString &key, const QString &spec // when no devices specified, use device discovery to scan and monitor if (parsed.devices.isEmpty()) { qCDebug(qLcEvdevTablet, "evdevtablet: Using device discovery"); - m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Tablet, this); - if (m_deviceDiscovery) { - const QStringList devices = m_deviceDiscovery->scanConnectedDevices(); + if (auto deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Tablet, this)) { + const QStringList devices = deviceDiscovery->scanConnectedDevices(); for (const QString &device : devices) addDevice(device); - connect(m_deviceDiscovery, &QDeviceDiscovery::deviceDetected, + connect(deviceDiscovery, &QDeviceDiscovery::deviceDetected, this, &QEvdevTabletManager::addDevice); - connect(m_deviceDiscovery, &QDeviceDiscovery::deviceRemoved, + connect(deviceDiscovery, &QDeviceDiscovery::deviceRemoved, this, &QEvdevTabletManager::removeDevice); } } -- cgit v1.2.3