Skip to content

Commit

Permalink
fix: 待机后不能通过PS2鼠标唤醒
Browse files Browse the repository at this point in the history
修复待机后不能通过PS2鼠标唤醒

Log: 修复待机后不能通过PS2鼠标唤醒

Bug: https://pms.uniontech.com/bug-view-219597.html
  • Loading branch information
feeengli authored and deepin-bot[bot] committed Nov 13, 2023
1 parent 9e37ad3 commit 75df7db
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 23 deletions.
24 changes: 21 additions & 3 deletions deepin-devicemanager/src/DeviceManager/DeviceInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,21 @@ bool DeviceInput::isWakeupMachine()
return false;
}
QString info = file.readAll();
if (info.contains("disabled"))
return false;

if (m_Name.contains("PS/2")) {
// QStringList lines = info.split("\n");
// for (QString line : lines) {
// if (line.startsWith("PS2M" && line.contains("disabled"))) {
// return false;
// }
// /proc/acpi/wakeup文件中状态未刷新,ps2设备通过dbus获取状态
return DBusWakeupInterface::getInstance()->isInputWakeupMachine(m_SysPath, m_Name);

} else {
if (info.contains("disabled"))
return false;
}

return true;
}

Expand All @@ -410,7 +423,12 @@ QString DeviceInput::wakeupPath()
if (index < 1) {
return "";
}
return QString("/sys") + m_SysPath.left(index) + QString("/power/wakeup");

if (m_Name.contains("PS/2")) {
return "/proc/acpi/wakeup";
} else {
return QString("/sys") + m_SysPath.left(index) + QString("/power/wakeup");
}
}

const QString &DeviceInput::wakeupID()
Expand Down
2 changes: 1 addition & 1 deletion deepin-devicemanager/src/Page/PageSingleInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ void PageSingleInfo::slotWakeupMachine()
// 键盘鼠标唤醒机器
DeviceInput *input = qobject_cast<DeviceInput *>(mp_Device);
if (input && !input->wakeupID().isEmpty() && !input->sysPath().isEmpty()) {
DBusWakeupInterface::getInstance()->setWakeupMachine(input->wakeupID(), input->sysPath(), mp_WakeupMachine->isChecked());
DBusWakeupInterface::getInstance()->setWakeupMachine(input->wakeupID(), input->sysPath(), mp_WakeupMachine->isChecked(), input->name());
}

// 网卡的远程唤醒
Expand Down
63 changes: 47 additions & 16 deletions deepin-devicemanager/src/WakeupControl/DBusWakeupInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,46 @@ DBusWakeupInterface::DBusWakeupInterface()
init();
}

bool DBusWakeupInterface::setWakeupMachine(const QString &unique_id, const QString &path, bool wakeup)
bool DBusWakeupInterface::setWakeupMachine(const QString &unique_id, const QString &path, bool wakeup, const QString &name)
{
if (nullptr != mp_InputIface && mp_InputIface->isValid()) {
QStringList pathList = path.split("/", QString::SkipEmptyParts);
if (pathList.size() < 3)
return false;

auto metaObject = mp_InputIface->metaObject();
for (int i = 0 ; i < metaObject->methodCount(); ++i) {
if (metaObject->method(i).name() == "SetWakeupDevices") {
QString curPath = pathList[pathList.size() - 2];
QString busPath = QString("/sys/bus/usb/devices/%1/power/wakeup").arg(curPath);
mp_InputIface->call("SetWakeupDevices", busPath, wakeup ? "enabled" : "disabled");
return true;
if (name.contains("PS/2")) {
// ps2设备无法通过/sys/devices/platform/i8042/serio1/power/wakeup控制,只能通过acpi的接口进行控制
QDBusInterface interface(INPUT_SERVICE_NAME, INPUT_WAKEUP_SERVICE_PATH, INPUT_WAKEUP_PROPERTIES_INTERFACE, QDBusConnection::systemBus());
if (interface.isValid()) {
QDBusMessage replay = interface.call("Get", INPUT_WAKEUP_INTERFACE, "SupportWakeupDevices");
QVariant v = replay.arguments().first();
if (v.isValid()) {
QDBusArgument arg = v.value<QDBusVariant>().variant().value<QDBusArgument>();
QMap<QString, QString> allSupportWakeupDevices;
arg >> allSupportWakeupDevices;
QStringList pathList = allSupportWakeupDevices.keys();

for (QString path : pathList) {
if (path.contains("PS2")) {
mp_InputIface->call("SetWakeupDevices", path, wakeup ? "enabled" : "disabled");
return true;
}
}
}
}
} else {
auto metaObject = mp_InputIface->metaObject();
for (int i = 0 ; i < metaObject->methodCount(); ++i) {
if (metaObject->method(i).name() == "SetWakeupDevices") {
QString curPath = pathList[pathList.size() - 2];
QString busPath = QString("/sys/bus/usb/devices/%1/power/wakeup").arg(curPath);
mp_InputIface->call("SetWakeupDevices", busPath, wakeup ? "enabled" : "disabled");
return true;
}
}
}
}

QDBusReply<bool> reply = mp_Iface->call("setWakeupMachine", unique_id, path, wakeup);
if (reply.isValid()) {
return reply.value();
Expand Down Expand Up @@ -81,7 +104,7 @@ bool DBusWakeupInterface::canInputWakeupMachine(const QString &path)
return file.open(QIODevice::ReadOnly);
}

bool DBusWakeupInterface::isInputWakeupMachine(const QString &path)
bool DBusWakeupInterface::isInputWakeupMachine(const QString &path, const QString &name)
{
if (nullptr != mp_InputIface && mp_InputIface->isValid()) {
QDBusInterface interface(INPUT_SERVICE_NAME, INPUT_WAKEUP_SERVICE_PATH, INPUT_WAKEUP_PROPERTIES_INTERFACE, QDBusConnection::systemBus());
Expand All @@ -93,13 +116,21 @@ bool DBusWakeupInterface::isInputWakeupMachine(const QString &path)
QMap<QString, QString> allSupportWakeupDevices;
arg >> allSupportWakeupDevices;

QString curPath = path.left(path.size() - 13);
int index = curPath.lastIndexOf('/');
if (index < 1)
return false;
curPath = curPath.right(curPath.size() - index - 1);
QString busPath = QString("/sys/bus/usb/devices/%1/power/wakeup").arg(curPath);
return (allSupportWakeupDevices.contains(busPath) && allSupportWakeupDevices[busPath] == "enabled");
if (name.contains("PS/2")) {
for(QString path : allSupportWakeupDevices.keys()) {
if (path.contains("PS2")) {
return allSupportWakeupDevices[path] == "enabled";
}
}
} else {
QString curPath = path.left(path.size() - 13);
int index = curPath.lastIndexOf('/');
if (index < 1)
return false;
curPath = curPath.right(curPath.size() - index - 1);
QString busPath = QString("/sys/bus/usb/devices/%1/power/wakeup").arg(curPath);
return (allSupportWakeupDevices.contains(busPath) && allSupportWakeupDevices[busPath] == "enabled");
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions deepin-devicemanager/src/WakeupControl/DBusWakeupInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DBusWakeupInterface
* @param wakeup 可唤醒 不可唤醒
* @return
*/
bool setWakeupMachine(const QString &unique_id, const QString &path, bool wakeup);
bool setWakeupMachine(const QString &unique_id, const QString &path, bool wakeup, const QString &name);

/**
* @brief canWakeupMachine 获取input是否支持唤醒
Expand All @@ -54,7 +54,7 @@ class DBusWakeupInterface
* @param path 设备节点路径
* @return
*/
bool isInputWakeupMachine(const QString &path);
bool isInputWakeupMachine(const QString &path, const QString &name);

/**
* @brief isNetworkWakeup 获取网卡是否支持远程唤醒
Expand Down
2 changes: 1 addition & 1 deletion deepin-devicemanager/src/Widget/TextBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void TextBrowser::setWakeupMachine(bool wakeup)
// 键盘鼠标唤醒机器
DeviceInput *input = qobject_cast<DeviceInput*>(mp_Info);
if(input && !input->wakeupID().isEmpty() && !input->sysPath().isEmpty()){
DBusWakeupInterface::getInstance()->setWakeupMachine(input->wakeupID(),input->sysPath(),wakeup);
DBusWakeupInterface::getInstance()->setWakeupMachine(input->wakeupID(),input->sysPath(),wakeup, input->name());
}

// 网卡的远程唤醒
Expand Down

0 comments on commit 75df7db

Please sign in to comment.