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()
{
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);
}
}

View file

@ -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();