fix(shortcut): skip ddm default session when counting display sessions#92
fix(shortcut): skip ddm default session when counting display sessions#92yixinshark wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: yixinshark The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideAdjusts the display session counting logic to ignore the ddm greeter session identified by UserName "dde" so that power actions are only gated when multiple real user sessions are present. Sequence diagram for updated display session counting in hasMultipleDisplaySessionsequenceDiagram
participant PowerController
participant DisplayManager
participant DisplayManagerSession
PowerController->>DisplayManager: property(Sessions)
DisplayManager-->>PowerController: QList<QDBusObjectPath>
loop for each QDBusObjectPath
PowerController->>DisplayManagerSession: QDBusInterface("org.freedesktop.DisplayManager", path.path(), "org.freedesktop.DisplayManager.Session", QDBusConnection::systemBus())
alt [session is valid]
PowerController->>DisplayManagerSession: property(UserName)
DisplayManagerSession-->>PowerController: QString
alt [UserName == "dde"]
PowerController-->>PowerController: skip greeter session
else [UserName != "dde"]
PowerController-->>PowerController: ++userSessions
end
else [session is invalid]
PowerController-->>PowerController: continue
end
end
PowerController-->>PowerController: return userSessions >= 2
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Consider caching the systemBus QDBusConnection or reusing a single session interface where possible to avoid repeatedly constructing QDBusInterface objects inside the loop for each session.
- If the underlying DDM implementation changes the greeter UserName from "dde" or introduces additional special sessions, this hard-coded filter could become brittle; you might want to make the greeter identification more robust (e.g., via a dedicated property or configurable list of greeter usernames).
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider caching the systemBus QDBusConnection or reusing a single session interface where possible to avoid repeatedly constructing QDBusInterface objects inside the loop for each session.
- If the underlying DDM implementation changes the greeter UserName from "dde" or introduces additional special sessions, this hard-coded filter could become brittle; you might want to make the greeter identification more robust (e.g., via a dedicated property or configurable list of greeter usernames).
## Individual Comments
### Comment 1
<location path="src/plugin-qt/shortcut/tools/dde-shortcut-tool/powercontroller.cpp" line_range="255-254" />
<code_context>
+ QDBusConnection::systemBus());
+ if (!session.isValid())
+ continue;
+ if (session.property("UserName").toString() == QLatin1String("dde"))
+ continue;
+ ++userSessions;
+ }
</code_context>
<issue_to_address>
**question (bug_risk):** Hardcoding the greeter username "dde" could miscount sessions in some edge cases.
This logic assumes the greeter account is always named `dde` and that no real user account ever uses that name. If either assumption is wrong, real user sessions may be skipped. Please consider a more reliable way to detect greeter sessions (e.g. using a dedicated property or configurable identifier) instead of a hardcoded username.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
hasMultipleDisplaySession() counted org.freedesktop.DisplayManager Sessions and treated >= 2 as "multiple users logged in". On Wayland the default display manager (ddm) keeps a dde session alive next to the user session, so a single logged-in user already exposes two sessions (session's UserName is "dde"). This misjudged a single user as multiple sessions, wrongly gating shutdown/suspend confirmation. Query each session's UserName and skip the "dde" session before counting, so only real user sessions are tallied. On X11 there is no such "dde" session, so the filter is a no-op there. hasMultipleDisplaySession() 通过统计 org.freedesktop.DisplayManager 的 Sessions 数量、以 >= 2 判定"多用户登录"。Wayland 下默认使用的 ddm 会在 用户会话之外保留一个dde会话,因此单个用户登录就已经存在两个 session(UserName 为 "dde"),导致单用户被误判为多会话, 错误地拦截了关机/挂起确认。 改为查询每个会话的 UserName,统计前先跳过 "dde" 会话,只计真实 用户会话。X11 下不存在该 "dde" 会话,过滤为空操作。 Log: skip ddm default session when counting display sessions Pms: BUG-366665 Change-Id: I6eac98bf68881b5210945cd647b4d4306ef9a255
3195353 to
84240dd
Compare
deepin pr auto review★ 总体评分:100分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 当前代码已足够优秀,无需额外修改。若未来会话数量剧增,可考虑异步并发获取,但当前场景下无必要。
bool PowerController::hasMultipleDisplaySession()
{
QVariant v = displayMgr.property("Sessions");
if (!v.isValid())
return false;
const QList<QDBusObjectPath> sessions = qdbus_cast<QList<QDBusObjectPath>>(v);
if (!isWaylandSession())
return sessions.size() >= 2;
// On Treeland the default display manager (ddm) keeps a default session(dde)
int userSessions = 0;
for (const QDBusObjectPath &path : sessions) {
QDBusInterface session("org.freedesktop.DisplayManager", path.path(),
"org.freedesktop.DisplayManager.Session",
QDBusConnection::systemBus());
if (!session.isValid())
continue;
if (session.property("UserName").toString() == QLatin1String("dde"))
continue;
++userSessions;
}
return userSessions >= 2;
} |
Summary
hasMultipleDisplaySession()countedorg.freedesktop.DisplayManagerSessionsand treated>= 2as multiple users logged in.UserNameisdde. This misjudged a single user as multiple sessions and wrongly gated shutdown/suspend confirmation.UserNameand skip theddegreeter before counting. On X11 there is no suchddesession, so the filter is a no-op there.Verification
On a Treeland/ddm machine with a single user logged in,
org.freedesktop.DisplayManager.Sessionsreturns two paths:/org/freedesktop/DisplayManager/Session→ UserNamedde(default)/org/freedesktop/DisplayManager/Session0→ UserNameuos(real user)After the fix, only the real session is counted, so a single user no longer trips the
>= 2check; a second real login still does.Summary by Sourcery
Bug Fixes: