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/evdevmouse/qevdevmousemanager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp') diff --git a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp index ae81bca00f..038ff7db43 100644 --- a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp +++ b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp @@ -86,7 +86,7 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif addMouse(device); if (devices.isEmpty()) { - qCDebug(qLcEvdevMouse) << "evdevmouse: Using device discovery"; + qCDebug(qLcEvdevMouse, "evdevmouse: Using device discovery"); m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Mouse | QDeviceDiscovery::Device_Touchpad, this); if (m_deviceDiscovery) { // scan and add already connected keyboards @@ -159,7 +159,7 @@ void QEvdevMouseManager::handleWheelEvent(QPoint delta) void QEvdevMouseManager::addMouse(const QString &deviceNode) { - qCDebug(qLcEvdevMouse) << "Adding mouse at" << deviceNode; + qCDebug(qLcEvdevMouse, "Adding mouse at %ls", qUtf16Printable(deviceNode)); QEvdevMouseHandler *handler = QEvdevMouseHandler::create(deviceNode, m_spec); if (handler) { connect(handler, &QEvdevMouseHandler::handleMouseEvent, @@ -170,14 +170,14 @@ void QEvdevMouseManager::addMouse(const QString &deviceNode) QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( QInputDeviceManager::DeviceTypePointer, m_mice.count()); } else { - qWarning("evdevmouse: Failed to open mouse device %s", qPrintable(deviceNode)); + qWarning("evdevmouse: Failed to open mouse device %ls", qUtf16Printable(deviceNode)); } } void QEvdevMouseManager::removeMouse(const QString &deviceNode) { if (m_mice.contains(deviceNode)) { - qCDebug(qLcEvdevMouse) << "Removing mouse at" << deviceNode; + qCDebug(qLcEvdevMouse, "Removing mouse at %ls", qUtf16Printable(deviceNode)); QEvdevMouseHandler *handler = m_mice.value(deviceNode); m_mice.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 --- src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp') diff --git a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp index 038ff7db43..7abca215da 100644 --- a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp +++ b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp @@ -167,8 +167,7 @@ void QEvdevMouseManager::addMouse(const QString &deviceNode) connect(handler, &QEvdevMouseHandler::handleWheelEvent, this, &QEvdevMouseManager::handleWheelEvent); m_mice.insert(deviceNode, handler); - QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( - QInputDeviceManager::DeviceTypePointer, m_mice.count()); + updateDeviceCount(); } else { qWarning("evdevmouse: Failed to open mouse device %ls", qUtf16Printable(deviceNode)); } @@ -180,10 +179,15 @@ void QEvdevMouseManager::removeMouse(const QString &deviceNode) qCDebug(qLcEvdevMouse, "Removing mouse at %ls", qUtf16Printable(deviceNode)); QEvdevMouseHandler *handler = m_mice.value(deviceNode); m_mice.remove(deviceNode); - QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( - QInputDeviceManager::DeviceTypePointer, m_mice.count()); + updateDeviceCount(); delete handler; } } +void QEvdevMouseManager::updateDeviceCount() +{ + QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( + QInputDeviceManager::DeviceTypePointer, m_mice.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/evdevmouse/qevdevmousemanager.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp') diff --git a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp index 7abca215da..0873981436 100644 --- a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp +++ b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp @@ -111,8 +111,6 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif QEvdevMouseManager::~QEvdevMouseManager() { - qDeleteAll(m_mice); - m_mice.clear(); } void QEvdevMouseManager::clampPosition() @@ -160,13 +158,13 @@ void QEvdevMouseManager::handleWheelEvent(QPoint delta) void QEvdevMouseManager::addMouse(const QString &deviceNode) { qCDebug(qLcEvdevMouse, "Adding mouse at %ls", qUtf16Printable(deviceNode)); - QEvdevMouseHandler *handler = QEvdevMouseHandler::create(deviceNode, m_spec); + auto handler = QEvdevMouseHandler::create(deviceNode, m_spec); if (handler) { - connect(handler, &QEvdevMouseHandler::handleMouseEvent, + connect(handler.get(), &QEvdevMouseHandler::handleMouseEvent, this, &QEvdevMouseManager::handleMouseEvent); - connect(handler, &QEvdevMouseHandler::handleWheelEvent, + connect(handler.get(), &QEvdevMouseHandler::handleWheelEvent, this, &QEvdevMouseManager::handleWheelEvent); - m_mice.insert(deviceNode, handler); + m_mice.add(deviceNode, std::move(handler)); updateDeviceCount(); } else { qWarning("evdevmouse: Failed to open mouse device %ls", qUtf16Printable(deviceNode)); @@ -175,12 +173,9 @@ void QEvdevMouseManager::addMouse(const QString &deviceNode) void QEvdevMouseManager::removeMouse(const QString &deviceNode) { - if (m_mice.contains(deviceNode)) { + if (m_mice.remove(deviceNode)) { qCDebug(qLcEvdevMouse, "Removing mouse at %ls", qUtf16Printable(deviceNode)); - QEvdevMouseHandler *handler = m_mice.value(deviceNode); - m_mice.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/evdevmouse/qevdevmousemanager.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp') diff --git a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp index 0873981436..f64ba908e8 100644 --- a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp +++ b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp @@ -39,6 +39,8 @@ #include "qevdevmousemanager_p.h" +#include + #include #include #include @@ -63,29 +65,22 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif if (spec.isEmpty()) spec = specification; - QStringList args = spec.split(QLatin1Char(':')); - QStringList devices; + auto parsed = QEvdevUtil::parseSpecification(spec); + m_spec = std::move(parsed.spec); - foreach (const QString &arg, args) { - if (arg.startsWith(QLatin1String("/dev/"))) { - // if device is specified try to use it - devices.append(arg); - args.removeAll(arg); - } else if (arg.startsWith(QLatin1String("xoffset="))) { + for (const QStringRef &arg : qAsConst(parsed.args)) { + if (arg.startsWith(QLatin1String("xoffset="))) { m_xoffset = arg.mid(8).toInt(); } else if (arg.startsWith(QLatin1String("yoffset="))) { m_yoffset = arg.mid(8).toInt(); } } - // build new specification without /dev/ elements - m_spec = args.join(QLatin1Char(':')); - // add all mice for devices specified in the argument list - foreach (const QString &device, devices) + for (const QString &device : qAsConst(parsed.devices)) addMouse(device); - if (devices.isEmpty()) { + if (parsed.devices.isEmpty()) { qCDebug(qLcEvdevMouse, "evdevmouse: Using device discovery"); m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Mouse | QDeviceDiscovery::Device_Touchpad, 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/evdevmouse/qevdevmousemanager.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp') diff --git a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp index f64ba908e8..0c19294905 100644 --- a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp +++ b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp @@ -82,16 +82,15 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif if (parsed.devices.isEmpty()) { qCDebug(qLcEvdevMouse, "evdevmouse: Using device discovery"); - m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Mouse | QDeviceDiscovery::Device_Touchpad, this); - if (m_deviceDiscovery) { + if (auto deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Mouse | QDeviceDiscovery::Device_Touchpad, this)) { // scan and add already connected keyboards - const QStringList devices = m_deviceDiscovery->scanConnectedDevices(); + const QStringList devices = deviceDiscovery->scanConnectedDevices(); for (const QString &device : devices) addMouse(device); - connect(m_deviceDiscovery, &QDeviceDiscovery::deviceDetected, + connect(deviceDiscovery, &QDeviceDiscovery::deviceDetected, this, &QEvdevMouseManager::addMouse); - connect(m_deviceDiscovery, &QDeviceDiscovery::deviceRemoved, + connect(deviceDiscovery, &QDeviceDiscovery::deviceRemoved, this, &QEvdevMouseManager::removeMouse); } } -- cgit v1.2.3