diff --git a/src/plugin-qt/shortcut/tools/dde-shortcut-tool/touchpadcontroller.cpp b/src/plugin-qt/shortcut/tools/dde-shortcut-tool/touchpadcontroller.cpp index 0369f930..c01a6c3e 100644 --- a/src/plugin-qt/shortcut/tools/dde-shortcut-tool/touchpadcontroller.cpp +++ b/src/plugin-qt/shortcut/tools/dde-shortcut-tool/touchpadcontroller.cpp @@ -6,33 +6,11 @@ #include #include -#include #include -TouchPadController::TouchPadController(QObject *parent) +TouchPadController::TouchPadController(QObject *parent) : BaseController(parent) - , m_touchpadInterface(nullptr) { - // Connect to touchpad service - using same path and interface as Go version - m_touchpadInterface = new QDBusInterface( - "org.deepin.dde.InputDevices1", - "/org/deepin/dde/InputDevice1/TouchPad", - "org.deepin.dde.InputDevice1.TouchPad", - QDBusConnection::sessionBus(), - this - ); - - if (!m_touchpadInterface->isValid()) { - qWarning() << "Failed to connect to TouchPad service:" - << m_touchpadInterface->lastError().message(); - } -} - -TouchPadController::~TouchPadController() -{ - if (m_touchpadInterface) { - delete m_touchpadInterface; - } } QStringList TouchPadController::commandActions() @@ -81,87 +59,18 @@ QString TouchPadController::actionHelp(const QString &action) const bool TouchPadController::toggle() { - if (!m_touchpadInterface || !m_touchpadInterface->isValid()) { - qDebug() << "Touchpad interface not available"; - return false; - } - - // Check if touchpad exists (following Go version logic) - QVariant existVariant = m_touchpadInterface->property("Exist"); - if (!existVariant.isValid()) { - qWarning() << "Failed to get touchpad exist state"; - return false; - } - - bool exist = existVariant.toBool(); - if (!exist) { - qDebug() << "Touchpad does not exist"; - return true; // Return success (nil in Go version) - } - - // Check if HandleTouchPadToggle is enabled (following Go version logic) - // Note: Currently assumes true, corresponds to globalConfig.HandleTouchPadToggle in Go version - bool handleTouchPadToggle = true; // TODO: Read from config file - - if (handleTouchPadToggle) { - // Get current state using TPadEnable property (Go version property name) - QVariant enabledVariant = m_touchpadInterface->property("TPadEnable"); - if (!enabledVariant.isValid()) { - qWarning() << "Failed to get touchpad TPadEnable state"; - return false; - } - - bool currentEnabled = enabledVariant.toBool(); - - // Set new state - bool success = m_touchpadInterface->setProperty("TPadEnable", !currentEnabled); - if (!success) { - qWarning() << "Failed to set touchpad TPadEnable state"; - return false; - } - - qDebug() << "Toggled touchpad TPadEnable from" << currentEnabled << "to" << !currentEnabled; - } - - // Toggle always shows TouchpadToggle OSD (Go version logic) + // The shortcut only shows the OSD; the actual touchpad switch is handled + // elsewhere (e.g. the system keyevent service). showOSD("TouchpadToggle"); - return true; } bool TouchPadController::setEnabled(bool enabled) { - if (!m_touchpadInterface || !m_touchpadInterface->isValid()) { - qDebug() << "Touchpad interface not available"; - return false; - } - - // Check if touchpad exists (following Go version logic) - QVariant existVariant = m_touchpadInterface->property("Exist"); - if (!existVariant.isValid()) { - qWarning() << "Failed to get touchpad exist state"; - return false; - } - - bool exist = existVariant.toBool(); - if (!exist) { - qDebug() << "Touchpad does not exist"; - return true; // Return success (nil in Go version) - } - - // Set state using TPadEnable property (Go version logic) - bool success = m_touchpadInterface->setProperty("TPadEnable", enabled); - if (!success) { - qWarning() << "Failed to set touchpad TPadEnable state"; - return false; - } - - qDebug() << "Set touchpad TPadEnable:" << enabled; - - // Show corresponding OSD (Go version logic) + // The shortcut only shows the OSD; the actual touchpad switch is handled + // elsewhere (e.g. the system keyevent service). QString osd = enabled ? "TouchpadOn" : "TouchpadOff"; showOSD(osd); - return true; } diff --git a/src/plugin-qt/shortcut/tools/dde-shortcut-tool/touchpadcontroller.h b/src/plugin-qt/shortcut/tools/dde-shortcut-tool/touchpadcontroller.h index 974e6791..b0d15558 100644 --- a/src/plugin-qt/shortcut/tools/dde-shortcut-tool/touchpadcontroller.h +++ b/src/plugin-qt/shortcut/tools/dde-shortcut-tool/touchpadcontroller.h @@ -9,14 +9,12 @@ #include -class QDBusInterface; - class TouchPadController : public BaseController { Q_OBJECT public: explicit TouchPadController(QObject *parent = nullptr); - ~TouchPadController() override; + ~TouchPadController() override = default; static QString commandName() { return "touchpad"; } static QStringList commandActions(); @@ -32,8 +30,6 @@ class TouchPadController : public BaseController bool toggle(); bool setEnabled(bool enabled); void showOSD(const QString &signal); - - QDBusInterface *m_touchpadInterface; }; #endif