Skip to content

Commit 8e86c3e

Browse files
committed
fix: correct mouse/touchpad enable/disable button visibility
Move PS/2 mouse canEnable check after getMouseInfoFromBusDevice() to avoid misidentifying bluetooth mice. Add validateCanEnableForMouse() to check sysfs authorized/remove files. Fix v25 touchpad disable by using DBus Enable method. Refactor TableWidget to use per-row canEnable from item data instead of global m_Enable flag. 修复鼠标/触摸板禁用按钮显示逻辑:将PS/2鼠标canEnable检查移到 getMouseInfoFromBusDevice之后避免误判蓝牙鼠标;新增sysfs文件 校验;v25触摸板禁用改用DBus Enable方法;TableWidget改为逐行 读取canEnable而非全局m_Enable标志。 Log: 修复鼠标触摸板禁用按钮显示和触控板禁用功能 PMS: BUG-355975 Influence: 蓝牙鼠标、I2C触控笔等无法禁用的设备不再显示禁用按钮;v25触摸板禁用功能恢复正常
1 parent 31b2fbb commit 8e86c3e

6 files changed

Lines changed: 64 additions & 25 deletions

File tree

deepin-devicemanager/src/DeviceManager/DeviceInput.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -190,10 +190,6 @@ void DeviceInput::setInfoFromHwinfo(const QMap<QString, QString> &mapInfo)
190190
if ("PS/2" == m_Interface) {
191191
qCDebug(appLog) << "Interface is PS/2, getting PS2 Syspath.";
192192
getPS2Syspath(mapInfo["Device Files"]);
193-
if (m_Model.contains("Mouse", Qt::CaseInsensitive)) {
194-
qCDebug(appLog) << "Model contains Mouse, setting m_CanEnable to false.";
195-
m_CanEnable = false;
196-
}
197193
}
198194

199195
// 获取映射到 lshw设备信息的 关键字
@@ -206,11 +202,38 @@ void DeviceInput::setInfoFromHwinfo(const QMap<QString, QString> &mapInfo)
206202
qCDebug(appLog) << "Info set from Bluetoothctl.";
207203

208204
getMouseInfoFromBusDevice();
205+
206+
// PS/2鼠标不支持启用/禁用(需在getMouseInfoFromBusDevice之后判断,
207+
// 因为接口类型可能在getMouseInfoFromBusDevice中被更正,如蓝牙鼠标)
208+
if ("PS/2" == m_Interface && m_Model.contains("Mouse", Qt::CaseInsensitive)) {
209+
qCDebug(appLog) << "PS/2 Mouse, setting m_CanEnable to false.";
210+
m_CanEnable = false;
211+
}
209212
// 获取其他设备信息
210213
getOtherMapInfo(mapInfo);
211214
qCDebug(appLog) << "Exiting setInfoFromHwinfo.";
212215
}
213216

217+
void DeviceInput::validateCanEnableForMouse()
218+
{
219+
// 触摸板使用DBusTouchPad接口,不需要检查sysfs
220+
if (m_Name.contains("Touchpad", Qt::CaseInsensitive)) {
221+
return;
222+
}
223+
// setEnable()需要SerialID、UniqueID、SysPath,缺少则禁用操作会失败
224+
if (m_SerialID.isEmpty() || m_UniqueID.isEmpty() || m_SysPath.isEmpty()) {
225+
m_CanEnable = false;
226+
return;
227+
}
228+
// 如果sysfs路径下两者都没有,则该设备无法被禁用
229+
QString sysfsPath = "/sys" + m_SysPath;
230+
bool hasAuthorized = QFile::exists(sysfsPath + "/authorized");
231+
bool hasRemove = QFile::exists(sysfsPath + "/remove");
232+
if (!hasAuthorized && !hasRemove) {
233+
m_CanEnable = false;
234+
}
235+
}
236+
214237
void DeviceInput::setInfoFromBluetoothctl()
215238
{
216239
qCDebug(appLog) << "Entering setInfoFromBluetoothctl.";

deepin-devicemanager/src/DeviceManager/DeviceInput.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ class DeviceInput : public DeviceBaseInfo
134134

135135
QString getInterface() const;
136136

137+
/**
138+
* @brief validateCanEnableForMouse: 校验鼠标设备是否满足禁用所需的字段
139+
* setEnable()需要SerialID、UniqueID、SysPath,缺少任何一个则禁用操作会失败
140+
*/
141+
void validateCanEnableForMouse();
142+
137143
protected:
138144
/**
139145
* @brief initFilterKey:初始化可现实的可显示的属性,m_FilterKey

deepin-devicemanager/src/EnableControl/DBusTouchPad.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -24,6 +24,7 @@ const QString Path_V20 = "/com/deepin/daemon/InputDevice/TouchPad";
2424
const QString Interface_V20 = "com.deepin.daemon.InputDevice.TouchPad";
2525

2626
inline bool isV20() { return Dtk::Core::DSysInfo::majorVersion() == "20"; }
27+
inline bool isV25() { return Dtk::Core::DSysInfo::majorVersion() == "25"; }
2728
const QString Service = isV20() ? Service_V20 : Service_V23;
2829
const QString Path = isV20() ? Path_V20 : Path_V23;
2930
const QString Interface = isV20() ? Interface_V20 : Interface_V23;
@@ -65,7 +66,11 @@ void DBusTouchPad::setEnable(bool state)
6566
{
6667
qCDebug(appLog) << "Set touchpad enable state to:" << state;
6768
if (m_dbusTouchPad->isValid()) {
68-
m_dbusTouchPad->setProperty("TPadEnable", state);
69+
if (isV25()) {
70+
m_dbusTouchPad->call("Enable", state);
71+
} else {
72+
m_dbusTouchPad->setProperty("TPadEnable", state);
73+
}
6974
qCInfo(appLog) << "Touchpad state changed to:" << state;
7075
} else {
7176
qCWarning(appLog) << "Invalid DBus interface when setting touchpad state";

deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -1147,6 +1147,7 @@ void DeviceGenerator::getMouseInfoFromHwinfo()
11471147
}
11481148

11491149
//过滤触摸板,如果不是触摸板再检查
1150+
bool isTouchpad = (*it)["Model"].contains("Touchpad", Qt::CaseInsensitive);
11501151
if ((*it)["Hotplug"] != "PS/2") {
11511152
// 先判断是否存在
11521153
QString path = pciPath(*it);
@@ -1173,8 +1174,15 @@ void DeviceGenerator::getMouseInfoFromHwinfo()
11731174
device = new DeviceInput();
11741175
device->setInfoFromHwinfo(*it);
11751176
device->setHardwareClass("mouse");
1176-
if (device->bluetoothIsConnected()) {
1177-
// qCDebug(appLog) << "Adding bluetooth mouse device";
1177+
1178+
// 触摸板设备或蓝牙鼠标需要添加到设备列表
1179+
if (device->bluetoothIsConnected() || isTouchpad) {
1180+
// I2C接口的非触摸板设备(如触控屏、触控笔)不支持启用/禁用
1181+
if (!isTouchpad && device->getInterface() == "I2C") {
1182+
device->setCanEnable(false);
1183+
}
1184+
// 校验禁用所需的字段(SerialID、UniqueID、SysPath),缺少则不显示禁用按钮
1185+
device->validateCanEnableForMouse();
11781186
DeviceManager::instance()->addMouseDevice(device);
11791187
addBusIDFromHwinfo((*it)["SysFS BusID"]);
11801188
} else {

deepin-devicemanager/src/Widget/TableWidget.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -42,7 +42,6 @@ TableWidget::TableWidget(QWidget *parent)
4242
, mp_removeDriver(new QAction(tr("Uninstall drivers"), this))
4343
, mp_WakeupMachine(new QAction(tr("Allow it to wake the computer"), this))
4444
, mp_Menu(new DMenu(this))
45-
, m_Enable(false)
4645

4746
{
4847
qCDebug(appLog) << "TableWidget instance created";
@@ -106,12 +105,8 @@ void TableWidget::setHeaderLabels(const QStringList &lst)
106105
{
107106
qCDebug(appLog) << "Setting header labels to:" << lst;
108107
QStringList headers;
109-
for (int i = 0; i < lst.size(); i++) {
110-
if (i < lst.size() - 1) {
111-
headers.append(lst[i]);
112-
} else {
113-
m_Enable = lst[i] == "yes" ? true : false;
114-
}
108+
for (int i = 0; i < lst.size() - 1; i++) {
109+
headers.append(lst[i]);
115110
}
116111

117112
if (mp_Table) {
@@ -270,19 +265,22 @@ void TableWidget::slotShowMenu(const QPoint &point)
270265
mp_Menu->addAction(mp_Refresh);
271266
mp_Menu->addAction(mp_Export);
272267
QModelIndexList selected = mp_Table->selectionModel()->selectedRows();
273-
// 选中item状态下才有启用/禁用按钮
274-
if (m_Enable && selected.size() > 0) {
275-
mp_Menu->addAction(mp_Enable);
276-
}
277-
// 主板、内存、cpu等没有驱动,无需右键按钮
278-
// 选中item状态下才有卸载、更新按钮
268+
269+
// 先获取当前行的设备能力
279270
bool canUninstall = true , canEnable = true;
280271
QStandardItem* item = mp_Table->item(row,0);
281272
if(item){ // 获取该设备是否可以更新卸载驱动
282273
qCDebug(appLog) << "Getting device capabilities from item data";
283274
canUninstall = item->data(Qt::UserRole).toString()=="true" ? true : false;
284275
canEnable = item->data(Qt::UserRole+1).toString()=="true" ? true : false;
285276
}
277+
278+
// 选中item状态下才有启用/禁用按钮
279+
if (canEnable && selected.size() > 0) {
280+
mp_Menu->addAction(mp_Enable);
281+
}
282+
// 主板、内存、cpu等没有驱动,无需右键按钮
283+
// 选中item状态下才有卸载、更新按钮
286284
if(!canEnable){
287285
qCDebug(appLog) << "Device cannot be enabled/disabled, disabling action";
288286
mp_Enable->setEnabled(false);

deepin-devicemanager/src/Widget/TableWidget.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ private slots:
134134
QAction *mp_removeDriver;//<! 驱动卸载
135135
QAction *mp_WakeupMachine;//<! 唤醒机器
136136
QMenu *mp_Menu; //<! 右键菜单
137-
bool m_Enable;
138137
};
139138

140139

0 commit comments

Comments
 (0)