Skip to content

Commit 904b4fa

Browse files
committed
fix: support showing lock screen triggered by logind lock signal
- Support showing the lock screen when receiving a lock signal from logind. - Use asynchronous DBus call for RequestLock to prevent blocking the main thread when locking the session, especially when switching TTY. - Introduce a boolean `m_inCallRequestLock` to prevent multiple concurrent lock requests from being sent in a short time. - 支持接收 logind 的 lock 锁定信号后,触发并显示锁屏。 - 使用异步 DBus 调用 [RequestLock](cci:1://file:///home/zyz/works/work/v25/dde-session/src/dde-session/impl/sessionmanager.cpp:418:0-434:1),防止在锁定会话(如切换 TTY 时)阻塞主线程。 - 引入了 `m_inCallRequestLock` 标志位,防止短时间内产生多次并发的锁屏请求。 Log: support showing lock screen triggered by logind lock signal Pms: BUG-314653
1 parent f39ee57 commit 904b4fa

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/dde-session/impl/sessionmanager.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <QJsonDocument>
1717
#include <QProcess>
1818
#include <QFile>
19+
#include <QDBusPendingCall>
20+
#include <QDBusPendingCallWatcher>
1921

2022
#include <unistd.h>
2123
#include <signal.h>
@@ -79,6 +81,7 @@ SessionManager::SessionManager(QObject *parent)
7981
, m_systemd1ManagerInter(new org::freedesktop::systemd1::Manager("org.freedesktop.systemd1", "/org/freedesktop/systemd1", QDBusConnection::sessionBus(), this))
8082
, m_DBusInter(new org::freedesktop::DBus("org.freedesktop.DBus", "/org/freedesktop/DBus", QDBusConnection::sessionBus(), this))
8183
, m_isVM(detectVirtualMachine())
84+
, m_inCallRequestLock(false)
8285
{
8386
initConnections();
8487

@@ -415,11 +418,20 @@ void SessionManager::RequestHibernate()
415418

416419
void SessionManager::RequestLock()
417420
{
418-
QDBusInterface inter("org.deepin.dde.LockFront1", "/org/deepin/dde/LockFront1", "org.deepin.dde.LockFront1", QDBusConnection::sessionBus(), this);
419-
const QDBusMessage &msg = inter.call("Show");
420-
if (!msg.errorName().isEmpty()) {
421-
qWarning() << "failed to lock, error: " << msg.errorMessage();
422-
}
421+
QDBusInterface inter("org.deepin.dde.LockFront1", "/org/deepin/dde/LockFront1", "org.deepin.dde.LockFront1", QDBusConnection::sessionBus());
422+
423+
// 使用异步调用方式防止当前线程阻塞
424+
QDBusPendingCall async = inter.asyncCall("Show");
425+
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this);
426+
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
427+
QDBusPendingReply<> reply = *watcher;
428+
if (reply.isError()) {
429+
qWarning() << "failed to lock, async error: " << reply.error().message();
430+
}
431+
432+
m_inCallRequestLock = false;
433+
watcher->deleteLater();
434+
});
423435
}
424436

425437
void SessionManager::RequestLogout()
@@ -910,16 +922,24 @@ void SessionManager::handleLoginSessionLocked()
910922
{
911923
qDebug() << "login session locked." << locked();
912924
// 在特殊情况下,比如用 dde-switchtogreeter 命令切换到 greeter, 即切换到其他 tty
913-
// 前端(登录界面和锁屏界面)已绑定锁定信号进行了处理,此处只需更新Locked属性
925+
// 此时同步的 DBus RequestLock 方法不能立即返回,需要使用异步调用避免阻塞主线程
914926

915927
// 如果已经锁定,则立即返回
916928
if (locked()) {
917929
qDebug() << "already locked";
918930
return;
919931
}
920932

921-
m_locked = true;
922-
emitLockChanged(true);
933+
// 防止短时间内多次同时调用 RequestLock
934+
if (m_inCallRequestLock) {
935+
qDebug() << "handleLoginSessionLocked inCall is true, return";
936+
return;
937+
}
938+
939+
m_inCallRequestLock = true;
940+
941+
qDebug() << "handleLoginSessionLocked call RequestLock begin (async)";
942+
RequestLock();
923943
}
924944

925945
void SessionManager::handleLoginSessionUnlocked()

src/dde-session/impl/sessionmanager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,6 @@ private Q_SLOTS:
142142
org::freedesktop::DBus *m_DBusInter;
143143

144144
QMap<uint, Inhibitor *> m_inhibitorMap;
145+
bool m_inCallRequestLock;
145146
};
146147
#endif // SESSIONMANAGER_H

0 commit comments

Comments
 (0)