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
This commit is contained in:
Akseli Lahtinen 2024-09-02 14:23:59 +00:00 committed by Vlad Zahorodnii
parent d67ebc950c
commit e910dcb9ed
2 changed files with 48 additions and 19 deletions

View file

@ -3222,40 +3222,70 @@ void InputRedirection::updateAvailableInputDevices()
void InputRedirection::toggleTouchpads() void InputRedirection::toggleTouchpads()
{ {
bool changed = false; bool enabled = true;
m_touchpadsEnabled = !m_touchpadsEnabled;
for (InputDevice *device : std::as_const(m_inputDevices)) { for (InputDevice *device : std::as_const(m_inputDevices)) {
if (!device->isTouchpad()) { if (!device->isTouchpad()) {
continue; continue;
} }
const bool old = device->isEnabled();
device->setEnabled(m_touchpadsEnabled); if (!device->isEnabled()) {
if (old != device->isEnabled()) { enabled = false;
changed = true; break;
} }
} }
if (changed) {
// send OSD message if (enabled) {
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"), disableTouchpads();
QStringLiteral("/org/kde/osdService"), } else {
QStringLiteral("org.kde.osdService"), enableTouchpads();
QStringLiteral("touchpadEnabledChanged"));
msg.setArguments({m_touchpadsEnabled});
QDBusConnection::sessionBus().asyncCall(msg);
} }
} }
void InputRedirection::enableTouchpads() void InputRedirection::enableTouchpads()
{ {
if (!m_touchpadsEnabled) { bool changed = false;
toggleTouchpads(); 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() void InputRedirection::disableTouchpads()
{ {
if (m_touchpadsEnabled) { bool changed = false;
toggleTouchpads(); 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);
} }
} }

View file

@ -350,7 +350,6 @@ private:
bool m_hasPointer = false; bool m_hasPointer = false;
bool m_hasTouch = false; bool m_hasTouch = false;
bool m_hasTabletModeSwitch = false; bool m_hasTabletModeSwitch = false;
bool m_touchpadsEnabled = true;
KWIN_SINGLETON(InputRedirection) KWIN_SINGLETON(InputRedirection)
friend InputRedirection *input(); friend InputRedirection *input();