Skip to content

fix(power): avoid 25s stall when blanking the screen - #235

Open
fly602 wants to merge 1 commit into
linuxdeepin:develop/2500u3from
fly602:develop/2500u3
Open

fly602 wants to merge 1 commit into
linuxdeepin:develop/2500u3from
fly602:develop/2500u3

Conversation

@fly602

@fly602 fly602 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor
  1. TurnOffScreen waited for LockFront ShowAuth while dde-lock read Power1 SleepLock back, so both sides stalled until the 25s D-Bus timeout and the display stayed lit the whole time.
  2. SessionDBusProxy::showLockAuth fire-and-forgets ShowAuth now, and the X11 turn-off path blanks the screen before requesting the lock.
  3. dde-shortcut-tool's power controller uses the same async ShowAuth call, so the power-button shortcut no longer blocks its key handler.

Log: Blank the screen immediately instead of waiting for LockFront.

Influence:

  1. Press the power button: the display blanks immediately; journalctl shows no 25s gap between "Locking session" and "Setting DPMS mode to off".
  2. Lock/unlock, suspend/resume, hibernate and shutdown still work.
  3. Repeat screen-off after a suspend/resume cycle and confirm the display still blanks immediately.

fix(power): 修复锁屏回读导致关屏延迟 25 秒

  1. TurnOffScreen 同步等待 LockFront ShowAuth,而 dde-lock 在 ShowAuth 中回读 Power1 SleepLock,双方互等到 25 秒 D-Bus 超时,期间屏幕 一直亮着。
  2. SessionDBusProxy::showLockAuth 改为异步发送 ShowAuth 后立即返回, X11 关屏路径先关闭显示器再请求锁屏。
  3. dde-shortcut-tool 的电源控制器同样改为异步调用 ShowAuth,按电源键 不再阻塞快捷键处理。

Log: 立即关闭显示器,不再等待 LockFront 返回。

Influence:

  1. 按电源键后显示器立即熄灭;journalctl 中 "Locking session" 到 "Setting DPMS mode to off" 不再有 25 秒间隔。
  2. 锁屏/解锁、待机/唤醒、休眠、关机功能正常。
  3. 待机/唤醒后再按一次电源键,确认显示器仍立即关闭。

PMS: BUG-382691

Summary by Sourcery

Eliminate the power-button screen-off delay by decoupling display blanking and lock-auth requests.

Bug Fixes:

  • Prevent screen-off operations from stalling for 25 seconds by blanking the display before locking and making lock-auth requests asynchronous.
  • Keep power-button shortcut handling responsive by avoiding blocking lock-auth calls.

1. TurnOffScreen waited for LockFront ShowAuth while dde-lock read Power1
   SleepLock back, so both sides stalled until the 25s D-Bus timeout and
   the display stayed lit the whole time.
2. SessionDBusProxy::showLockAuth fire-and-forgets ShowAuth now, and the
   X11 turn-off path blanks the screen before requesting the lock.
3. dde-shortcut-tool's power controller uses the same async ShowAuth call,
   so the power-button shortcut no longer blocks its key handler.

Log: Blank the screen immediately instead of waiting for LockFront.

Influence:
1. Press the power button: the display blanks immediately; journalctl shows
   no 25s gap between "Locking session" and "Setting DPMS mode to off".
2. Lock/unlock, suspend/resume, hibernate and shutdown still work.
3. Repeat screen-off after a suspend/resume cycle and confirm the display
   still blanks immediately.

fix(power): 修复锁屏回读导致关屏延迟 25 秒

1. TurnOffScreen 同步等待 LockFront ShowAuth,而 dde-lock 在 ShowAuth
   中回读 Power1 SleepLock,双方互等到 25 秒 D-Bus 超时,期间屏幕
   一直亮着。
2. SessionDBusProxy::showLockAuth 改为异步发送 ShowAuth 后立即返回,
   X11 关屏路径先关闭显示器再请求锁屏。
3. dde-shortcut-tool 的电源控制器同样改为异步调用 ShowAuth,按电源键
   不再阻塞快捷键处理。

Log: 立即关闭显示器,不再等待 LockFront 返回。

Influence:
1. 按电源键后显示器立即熄灭;journalctl 中 "Locking session" 到
   "Setting DPMS mode to off" 不再有 25 秒间隔。
2. 锁屏/解锁、待机/唤醒、休眠、关机功能正常。
3. 待机/唤醒后再按一次电源键,确认显示器仍立即关闭。

PMS: BUG-382691
@sourcery-ai

sourcery-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

Uses of the API

Make both ShowAuth callers fire-and-forget so they do not block while LockFront reads Power1 properties.

  • src/plugin-qt/power/session/sessiondbusproxy.cpp L340-346
  • src/plugin-qt/shortcut/tools/dde-shortcut-tool/powercontroller.cpp L278-280

Implementation

Blank the display before requesting the lock so LockFront cannot delay screen-off.

  • src/plugin-qt/power/session/powermanager.cpp L635 (removed lines), L637-641

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602, mhduiy

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/plugin-qt/shortcut/tools/dde-shortcut-tool/powercontroller.cpp" line_range="280" />
<code_context>
-    lockFront.call("ShowAuth", autoStartAuth);
+    // Fire and forget: LockFront reads Power1 back, so waiting for its reply
+    // from a key handler only risks the 25s D-Bus timeout.
+    lockFront.asyncCall("ShowAuth", autoStartAuth);
 }

</code_context>
<issue_to_address>
**Machine suspends before lock is ready**

When lockFront takes longer than 500 ms to handle `ShowAuth`, `PowerController::handleSystemSuspend` starts its 500 ms pause after `asyncCall` only queues `ShowAuth`, then calls `systemSuspend` before LockFront has established the lock. The machine can resume without the intended lock screen.

Wait until LockFront has handled `ShowAuth` before allowing `systemSuspend` to proceed.
</issue_to_address>

### Comment 2
<location path="src/plugin-qt/power/session/sessiondbusproxy.cpp" line_range="347" />
<code_context>
         return;
     }

-    if (m_screenBlackLock)
</code_context>
<issue_to_address>
**Desktop briefly exposed after resume**

When the machine resumes while the screensaver was running and `lockScreenAtAwake` is enabled, `handleWakeup` sends `ShowAuth` through `showLockAuth` and immediately deactivates the black screen without waiting for LockFront to display the lock UI. The desktop is visible and interactive during that gap, so someone at the device can view or use the session before authentication appears.

Keep the black screen active until LockFront confirms the lock UI is ready, or use another synchronization mechanism that guarantees the session remains masked until authentication is enforced.
</issue_to_address>

### Comment 3
<location path="src/plugin-qt/power/session/sessiondbusproxy.cpp" line_range="346" />
<code_context>
         kLockFront, kLockFrontPath, kLockFront, QStringLiteral("ShowAuth"));
     msg << autoStart;
-    QDBusConnection::sessionBus().call(msg, QDBus::Block);
+    QDBusConnection::sessionBus().asyncCall(msg);
 }

</code_context>
<issue_to_address>
**Suspend can overtake locking**

When a suspend request proceeds before LockFront has handled the asynchronous lock request, `showLockAuth` returns without waiting for LockFront to process `ShowAuth`, so callers that immediately proceed with a suspend request no longer have the former reply as an ordering barrier. If suspend reaches the system before the session is locked, the machine resumes without the expected lock screen.

Preserve ordering where locking is required by proceeding with suspend only after a lock-state confirmation or a bounded asynchronous completion check.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

lockFront.call("ShowAuth", autoStartAuth);
// Fire and forget: LockFront reads Power1 back, so waiting for its reply
// from a key handler only risks the 25s D-Bus timeout.
lockFront.asyncCall("ShowAuth", autoStartAuth);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Machine suspends before lock is ready

When lockFront takes longer than 500 ms to handle ShowAuth, PowerController::handleSystemSuspend starts its 500 ms pause after asyncCall only queues ShowAuth, then calls systemSuspend before LockFront has established the lock. The machine can resume without the intended lock screen.

Wait until LockFront has handled ShowAuth before allowing systemSuspend to proceed.

Prompt for AI agents
In `src/plugin-qt/shortcut/tools/dde-shortcut-tool/powercontroller.cpp` at line 280:

**Machine suspends before lock is ready**

When lockFront takes longer than 500 ms to handle `ShowAuth`, `PowerController::handleSystemSuspend` starts its 500 ms pause after `asyncCall` only queues `ShowAuth`, then calls `systemSuspend` before LockFront has established the lock. The machine can resume without the intended lock screen.

Wait until LockFront has handled `ShowAuth` before allowing `systemSuspend` to proceed.

msg << autoStart;
QDBusConnection::sessionBus().call(msg, QDBus::Block);
QDBusConnection::sessionBus().asyncCall(msg);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Desktop briefly exposed after resume

When the machine resumes while the screensaver was running and lockScreenAtAwake is enabled, handleWakeup sends ShowAuth through showLockAuth and immediately deactivates the black screen without waiting for LockFront to display the lock UI. The desktop is visible and interactive during that gap, so someone at the device can view or use the session before authentication appears.

Keep the black screen active until LockFront confirms the lock UI is ready, or use another synchronization mechanism that guarantees the session remains masked until authentication is enforced.

Prompt for AI agents
In `src/plugin-qt/power/session/sessiondbusproxy.cpp` at line 347:

**Desktop briefly exposed after resume**

When the machine resumes while the screensaver was running and `lockScreenAtAwake` is enabled, `handleWakeup` sends `ShowAuth` through `showLockAuth` and immediately deactivates the black screen without waiting for LockFront to display the lock UI. The desktop is visible and interactive during that gap, so someone at the device can view or use the session before authentication appears.

Keep the black screen active until LockFront confirms the lock UI is ready, or use another synchronization mechanism that guarantees the session remains masked until authentication is enforced.

kLockFront, kLockFrontPath, kLockFront, QStringLiteral("ShowAuth"));
msg << autoStart;
QDBusConnection::sessionBus().call(msg, QDBus::Block);
QDBusConnection::sessionBus().asyncCall(msg);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Suspend can overtake locking

When a suspend request proceeds before LockFront has handled the asynchronous lock request, showLockAuth returns without waiting for LockFront to process ShowAuth, so callers that immediately proceed with a suspend request no longer have the former reply as an ordering barrier. If suspend reaches the system before the session is locked, the machine resumes without the expected lock screen.

Preserve ordering where locking is required by proceeding with suspend only after a lock-state confirmation or a bounded asynchronous completion check.

Prompt for AI agents
In `src/plugin-qt/power/session/sessiondbusproxy.cpp` at line 346:

**Suspend can overtake locking**

When a suspend request proceeds before LockFront has handled the asynchronous lock request, `showLockAuth` returns without waiting for LockFront to process `ShowAuth`, so callers that immediately proceed with a suspend request no longer have the former reply as an ordering barrier. If suspend reaches the system before the session is locked, the machine resumes without the expected lock screen.

Preserve ordering where locking is required by proceeding with suspend only after a lock-state confirmation or a bounded asynchronous completion check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants