diff --git a/input.h b/input.h --- a/input.h +++ b/input.h @@ -267,6 +267,7 @@ private: void setupLibInput(); + void setupTouchpadShortcuts(); void setupLibInputWithScreens(); void setupWorkspace(); void reconfigure(); diff --git a/input.cpp b/input.cpp --- a/input.cpp +++ b/input.cpp @@ -50,6 +50,8 @@ #include #include #include +#include + //screenlocker #include // Qt @@ -1430,6 +1432,8 @@ KWIN_SINGLETON_FACTORY(InputRedirection) +static const QString s_touchpadComponent = QStringLiteral("kcm_touchpad"); + InputRedirection::InputRedirection(QObject *parent) : QObject(parent) , m_keyboard(new KeyboardInputRedirection(this)) @@ -1750,6 +1754,40 @@ } ); } + setupTouchpadShortcuts(); +#endif +} + +void InputRedirection::setupTouchpadShortcuts() +{ + if (!m_libInput) { + return; + } +#ifdef HAVE_INPUT + QAction *touchpadToggleAction = new QAction(this); + QAction *touchpadOnAction = new QAction(this); + QAction *touchpadOffAction = new QAction(this); + + touchpadToggleAction->setObjectName(QStringLiteral("Toggle Touchpad")); + touchpadToggleAction->setProperty("componentName", s_touchpadComponent); + touchpadOnAction->setObjectName(QStringLiteral("Enable Touchpad")); + touchpadOnAction->setProperty("componentName", s_touchpadComponent); + touchpadOffAction->setObjectName(QStringLiteral("Disable Touchpad")); + touchpadOffAction->setProperty("componentName", s_touchpadComponent); + KGlobalAccel::self()->setDefaultShortcut(touchpadToggleAction, QList{Qt::Key_TouchpadToggle}); + KGlobalAccel::self()->setShortcut(touchpadToggleAction, QList{Qt::Key_TouchpadToggle}); + KGlobalAccel::self()->setDefaultShortcut(touchpadOnAction, QList{Qt::Key_TouchpadOn}); + KGlobalAccel::self()->setShortcut(touchpadOnAction, QList{Qt::Key_TouchpadOn}); + KGlobalAccel::self()->setDefaultShortcut(touchpadOffAction, QList{Qt::Key_TouchpadOff}); + KGlobalAccel::self()->setShortcut(touchpadOffAction, QList{Qt::Key_TouchpadOff}); +#ifndef KWIN_BUILD_TESTING + registerShortcut(Qt::Key_TouchpadToggle, touchpadToggleAction); + registerShortcut(Qt::Key_TouchpadOn, touchpadOnAction); + registerShortcut(Qt::Key_TouchpadOff, touchpadOffAction); +#endif + connect(touchpadToggleAction, &QAction::triggered, m_libInput, &LibInput::Connection::toggleTouchpads); + connect(touchpadOnAction, &QAction::triggered, m_libInput, &LibInput::Connection::enableTouchpads); + connect(touchpadOffAction, &QAction::triggered, m_libInput, &LibInput::Connection::disableTouchpads); #endif } diff --git a/libinput/connection.h b/libinput/connection.h --- a/libinput/connection.h +++ b/libinput/connection.h @@ -80,6 +80,8 @@ void processEvents(); void toggleTouchpads(); + void enableTouchpads(); + void disableTouchpads(); QVector devices() const { return m_devices; diff --git a/libinput/connection.cpp b/libinput/connection.cpp --- a/libinput/connection.cpp +++ b/libinput/connection.cpp @@ -26,7 +26,6 @@ #include "libinput_logging.h" #include -#include #include #include @@ -146,7 +145,6 @@ return s_self; } -static const QString s_touchpadComponent = QStringLiteral("kcm_touchpad"); Connection::Connection(Context *input, QObject *parent) : QObject(parent) @@ -156,47 +154,6 @@ , m_leds() { Q_ASSERT(m_input); - - // steal touchpad shortcuts - QAction *touchpadToggleAction = new QAction(this); - QAction *touchpadOnAction = new QAction(this); - QAction *touchpadOffAction = new QAction(this); - - touchpadToggleAction->setObjectName(QStringLiteral("Toggle Touchpad")); - touchpadToggleAction->setProperty("componentName", s_touchpadComponent); - touchpadOnAction->setObjectName(QStringLiteral("Enable Touchpad")); - touchpadOnAction->setProperty("componentName", s_touchpadComponent); - touchpadOffAction->setObjectName(QStringLiteral("Disable Touchpad")); - touchpadOffAction->setProperty("componentName", s_touchpadComponent); - KGlobalAccel::self()->setDefaultShortcut(touchpadToggleAction, QList{Qt::Key_TouchpadToggle}); - KGlobalAccel::self()->setShortcut(touchpadToggleAction, QList{Qt::Key_TouchpadToggle}); - KGlobalAccel::self()->setDefaultShortcut(touchpadOnAction, QList{Qt::Key_TouchpadOn}); - KGlobalAccel::self()->setShortcut(touchpadOnAction, QList{Qt::Key_TouchpadOn}); - KGlobalAccel::self()->setDefaultShortcut(touchpadOffAction, QList{Qt::Key_TouchpadOff}); - KGlobalAccel::self()->setShortcut(touchpadOffAction, QList{Qt::Key_TouchpadOff}); -#ifndef KWIN_BUILD_TESTING - InputRedirection::self()->registerShortcut(Qt::Key_TouchpadToggle, touchpadToggleAction); - InputRedirection::self()->registerShortcut(Qt::Key_TouchpadOn, touchpadOnAction); - InputRedirection::self()->registerShortcut(Qt::Key_TouchpadOff, touchpadOffAction); -#endif - connect(touchpadToggleAction, &QAction::triggered, this, &Connection::toggleTouchpads); - connect(touchpadOnAction, &QAction::triggered, this, - [this] { - if (m_touchpadsEnabled) { - return; - } - toggleTouchpads(); - } - ); - connect(touchpadOffAction, &QAction::triggered, this, - [this] { - if (!m_touchpadsEnabled) { - return; - } - toggleTouchpads(); - } - ); - // need to connect to KGlobalSettings as the mouse KCM does not emit a dedicated signal QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KGlobalSettings"), QStringLiteral("org.kde.KGlobalSettings"), QStringLiteral("notifyChange"), this, SLOT(slotKGlobalSettingsNotifyChange(int,int))); @@ -582,6 +539,22 @@ } } +void Connection::enableTouchpads() +{ + if (m_touchpadsEnabled) { + return; + } + toggleTouchpads(); +} + +void Connection::disableTouchpads() +{ + if (!m_touchpadsEnabled) { + return; + } + toggleTouchpads(); +} + void Connection::updateLEDs(Xkb::LEDs leds) { if (m_leds == leds) {