Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 5 additions & 96 deletions src/plugin-qt/shortcut/tools/dde-shortcut-tool/touchpadcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,13 @@

#include "touchpadcontroller.h"

#include <QDebug>

Check warning on line 7 in src/plugin-qt/shortcut/tools/dde-shortcut-tool/touchpadcontroller.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusInterface>

Check warning on line 8 in src/plugin-qt/shortcut/tools/dde-shortcut-tool/touchpadcontroller.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusInterface> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusReply>
#include <QDBusConnection>

Check warning on line 9 in src/plugin-qt/shortcut/tools/dde-shortcut-tool/touchpadcontroller.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusConnection> not found. Please note: Cppcheck does not need standard library headers to get proper results.

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()
Expand Down Expand Up @@ -81,87 +59,18 @@

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");
Comment on lines +62 to 64

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): The touchpad toggle, touchpad on, and touchpad off commands now return success and display an OSD without changing the touchpad state. Any caller that invokes dde-shortcut-tool directly rather than going through the system keyevent service therefore receives a successful no-op, despite the command names and help text promising to toggle or enable/disable the touchpad.

Triggers: When a user, script, control-center integration, or custom shortcut invokes these dde-shortcut-tool actions directly.

Suggested fix: Keep the state-changing DBus implementation for explicit tool actions, or clearly separate the OSD-only keyevent path from the public on, off, and toggle commands and update their contract/help text.


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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@

#include "basecontroller.h"

#include <QMap>

Check warning on line 10 in src/plugin-qt/shortcut/tools/dde-shortcut-tool/touchpadcontroller.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMap> not found. Please note: Cppcheck does not need standard library headers to get proper results.

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();
Expand All @@ -32,8 +30,6 @@
bool toggle();
bool setEnabled(bool enabled);
void showOSD(const QString &signal);

QDBusInterface *m_touchpadInterface;
};

#endif
Loading