From e910dcb9ed699acc70a6d3983863276cec2b16de Mon Sep 17 00:00:00 2001 From: Akseli Lahtinen Date: Mon, 2 Sep 2024 14:23:59 +0000 Subject: [PATCH] input.cpp: initialize m_touchpadsEnabled in addInputDevice m_touchpadsEnabled gets initialized to true in input.h, and the actual status of the device is not evaluated until the toggleTouchpads setting is pressed. This fixes the issue by removing m_touchpadsEnabled and refactoring the toggling method. OSD is handled by their respective enable/disable Touchpads methods. BUG:486763 --- src/input.cpp | 66 +++++++++++++++++++++++++++++++++++++-------------- src/input.h | 1 - 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index bd8b5ef325..f09fca2c36 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -3222,40 +3222,70 @@ void InputRedirection::updateAvailableInputDevices() void InputRedirection::toggleTouchpads() { - bool changed = false; - m_touchpadsEnabled = !m_touchpadsEnabled; + bool enabled = true; for (InputDevice *device : std::as_const(m_inputDevices)) { if (!device->isTouchpad()) { continue; } - const bool old = device->isEnabled(); - device->setEnabled(m_touchpadsEnabled); - if (old != device->isEnabled()) { - changed = true; + + if (!device->isEnabled()) { + enabled = false; + break; } } - if (changed) { - // send OSD message - QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"), - QStringLiteral("/org/kde/osdService"), - QStringLiteral("org.kde.osdService"), - QStringLiteral("touchpadEnabledChanged")); - msg.setArguments({m_touchpadsEnabled}); - QDBusConnection::sessionBus().asyncCall(msg); + + if (enabled) { + disableTouchpads(); + } else { + enableTouchpads(); } } void InputRedirection::enableTouchpads() { - if (!m_touchpadsEnabled) { - toggleTouchpads(); + bool changed = false; + for (InputDevice *device : std::as_const(m_inputDevices)) { + if (!device->isTouchpad()) { + continue; + } + if (device->isEnabled()) { + continue; + } + device->setEnabled(true); + changed = true; + } + // send OSD message + if (changed) { + QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"), + QStringLiteral("/org/kde/osdService"), + QStringLiteral("org.kde.osdService"), + QStringLiteral("touchpadEnabledChanged")); + msg.setArguments({true}); + QDBusConnection::sessionBus().asyncCall(msg); } } void InputRedirection::disableTouchpads() { - if (m_touchpadsEnabled) { - toggleTouchpads(); + bool changed = false; + for (InputDevice *device : std::as_const(m_inputDevices)) { + if (!device->isTouchpad()) { + continue; + } + if (!device->isEnabled()) { + continue; + } + device->setEnabled(false); + changed = true; + } + // send OSD message + if (changed) { + QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"), + QStringLiteral("/org/kde/osdService"), + QStringLiteral("org.kde.osdService"), + QStringLiteral("touchpadEnabledChanged")); + msg.setArguments({false}); + QDBusConnection::sessionBus().asyncCall(msg); } } diff --git a/src/input.h b/src/input.h index dfe2d0ffe3..aac4f51d88 100644 --- a/src/input.h +++ b/src/input.h @@ -350,7 +350,6 @@ private: bool m_hasPointer = false; bool m_hasTouch = false; bool m_hasTabletModeSwitch = false; - bool m_touchpadsEnabled = true; KWIN_SINGLETON(InputRedirection) friend InputRedirection *input();