Skip to content

fix: pre-activate lock screen on VT switch away to prevent desktop flash - #94

Closed
mhduiy wants to merge 1 commit into
linuxdeepin:masterfrom
mhduiy:agent/pms-bug-bot/f995044c3163
Closed

mhduiy wants to merge 1 commit into
linuxdeepin:masterfrom
mhduiy:agent/pms-bug-bot/f995044c3163

Conversation

@mhduiy

@mhduiy mhduiy commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

When switching from tty1 to another tty, the ActiveChanged(false) signal in lockworker.cpp only stopped authentication without pre-activating the lock screen window. The lock screen was activated only on ActiveChanged(true) (switching back), after the compositor had already rendered the desktop frame, causing a brief desktop flash before the lock screen appeared. The root cause is in src/dde-lock/lockworker.cpp:168 — the showLockScreen() call was guarded by active &&, so it only fired when switching back, not when switching away.

Key evidence:

  • lockworker.cpp:168: if (active && !m_model->visible()) only triggers on active=true (switch back)
  • The PrepareForSleep handler already uses pre-activation (setVisible(true) before sleep), establishing the correct pattern

Fix

Remove the active condition from the showLockScreen() call in the ActiveChanged handler so the lock screen is pre-activated when switching away from the session (active=false). This ensures the lock screen window is already mapped to the compositor before the VT switch, so on switch-back the compositor renders the lock screen first instead of the desktop. This follows the same pre-activation pattern already used by the PrepareForSleep handler.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • The target code was introduced by commit 2fcc70ba (BUG-341543) to unify lock screen activation logic; this change does not revert that fix — still only one showLockScreen() call, just with a broader trigger condition
  • The m_model->visible() guard prevents duplicate activation; when the lock screen is already visible, the call is skipped — no regression

Business Impact Scope

Affects the VT (virtual terminal) switching scenario: when a logged-in user switches from the desktop (tty1) to another tty and back, the lock screen should appear immediately without flashing the desktop. No other lock/unlock flows (normal lock, sleep/wake, manual lock) are affected.

Verification Suggestion

Test the VT switch scenario: log in on tty1, switch to tty2 via keyboard shortcut, switch back to tty1 — verify the lock screen appears immediately without a desktop flash. Also verify normal lock/unlock and sleep/wake still work correctly.


根因分析

从 tty1 切换到其他 tty 时,lockworker.cpp 中 ActiveChanged(false) 信号仅停止认证,未预激活锁屏窗口。锁屏仅在 ActiveChanged(true)(切回)时才激活,此时合成器已渲染了桌面帧,导致切回时先闪现桌面再显示锁屏。根因位于 src/dde-lock/lockworker.cpp:168——showLockScreen() 调用被 active && 守卫,仅在切回时触发,切走时不触发。

关键证据:

  • lockworker.cpp:168:if (active && !m_model->visible()) 仅在 active=true(切回)时触发
  • PrepareForSleep 处理器已使用预激活模式(休眠前 setVisible(true)),是正确的参考模式

修复方案

移除 ActiveChanged 处理器中 showLockScreen() 调用的 active 条件,使锁屏在切走会话时(active=false)也被预激活。这样锁屏窗口在 VT 切换前已映射到合成器,切回时合成器优先渲染锁屏而非桌面。与 PrepareForSleep 处理器使用的预激活模式一致。

改动安全评估

代码安全评估

  • 风险等级:低
  • 目标代码由 commit 2fcc70ba(BUG-341543)引入以统一锁屏激活逻辑;本次修改不回退该修复——仍只有一处 showLockScreen() 调用,仅扩大触发条件
  • m_model->visible() 守卫防止重复激活;锁屏已可见时跳过调用——无回归

业务影响范围

影响 VT(虚拟终端)切换场景:已登录用户从桌面(tty1)切换到其他 tty 再切回时,锁屏应立即出现,不闪现桌面。其他锁屏/解锁流程(正常锁屏、休眠唤醒、手动锁屏)不受影响。

验证建议

测试 VT 切换场景:在 tty1 登录后,用快捷键切换到 tty2,再切回 tty1——验证锁屏立即出现,不闪现桌面。同时验证正常锁屏/解锁和休眠唤醒功能正常。

Summary by Sourcery

Bug Fixes:

  • Prevent desktop flashes during VT switching by pre-activating the lock screen when leaving the active session.

When switching from tty1 to another tty, the ActiveChanged(false) signal
only stopped authentication without pre-activating the lock screen window.
The lock screen was activated only on ActiveChanged(true) (switching back),
after the compositor had already rendered the desktop frame, causing a
brief desktop flash before the lock screen appeared.

Remove the `active` condition from the showLockScreen() call in the
ActiveChanged handler so the lock screen is pre-activated when switching
away from the session. This ensures the lock screen window is already
mapped to the compositor before the VT switch, so on switch-back the
compositor renders the lock screen first instead of the desktop.

This follows the same pre-activation pattern already used by the
PrepareForSleep handler.

PMS: BUG-345559

@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.

Sorry @mhduiy, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 2 hours and 51 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 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 commented Sep 15, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the ActiveChanged handling so the lock screen is mapped before switching away from the graphical VT, ensuring the lock screen is rendered immediately on return instead of briefly exposing the desktop; existing visibility protection and other lock flows remain unchanged.

Sequence diagram for pre-activating the lock screen during VT switching

sequenceDiagram
    participant Compositor
    participant LockWorker
    participant LockModel

    Compositor->>LockWorker: ActiveChanged(false)
    LockWorker->>LockModel: visible()
    alt lock screen not visible
        LockWorker->>LockModel: showLockScreen()
        LockModel-->>Compositor: Lock screen window mapped
    else lock screen already visible
        LockWorker-->>Compositor: No duplicate activation
    end
    Compositor->>LockWorker: ActiveChanged(true)
    Compositor-->>LockModel: Render lock screen immediately
Loading

File-Level Changes

Change Details Files
Pre-activate the lock screen whenever the session activity changes away, preventing a desktop frame from appearing during VT switch-back.
  • Remove the active guard from the showLockScreen() condition.
  • Retain the visibility guard to avoid duplicate activation.
  • Align VT switching behavior with the existing sleep pre-activation pattern.
src/dde-lock/lockworker.cpp

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

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 98 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 98 分,大于 70 分通过阈值,代码质量符合要求。本次变更通过移除 active 条件实现 VT 切换时锁屏预激活,修复了桌面闪现问题,逻辑清晰且无安全风险。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 语法正确,逻辑清晰。变更移除了 if 条件中的 active 参数,使 showLockScreen() 在 VT 切换离开时(active=false)也能被调用,实现锁屏预激活。m_model->visible() 守卫仍然防止重复激活,逻辑完备。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. src/dde-lock/lockworker.cpp:168 - 移除 active 条件后未添加行内注释说明原因,建议补充注释以便后续维护

建议: 建议在 if (!m_model->visible()) 行前添加简短注释,说明移除 active 条件的原因(VT 切换时预激活锁屏以防止桌面闪现),便于后续维护者理解意图。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 性能良好,资源使用合理。变更仅移除一个布尔条件判断,无性能影响。m_model->visible() 守卫防止了 showLockScreen() 的冗余调用。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 存在0个安全漏洞。本次变更不涉及用户输入处理、网络操作或文件操作,无安全风险。变更实际上提升了安全性——通过在 VT 切换时预激活锁屏,防止了桌面内容闪现可能导致的敏感信息短暂暴露。


💡 改进建议代码示例

// 在 ActiveChanged 信号处理器中,移除 active 条件
// 使锁屏在 VT 切换离开时也被预激活,防止切回时桌面闪现
#ifdef ENABLE_DSS_SNIPE
        // VT 切换时预激活锁屏,防止切回时桌面闪现(与 PrepareForSleep 预激活模式一致)
        if (!m_model->visible()) {
            m_model->showLockScreen();
        }
#endif

本报告由 AI 代码审查工具自动生成

@mhduiy

mhduiy commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

修改是无效的,渲染阻塞: 当图形服务器失去显卡的主控权(Drop Master)后,如果应用程序试图向显卡发送新的绘图指令,内核会阻塞这个请求。这时,图形界面程序会停在某个系统调用上,直到你切回 GUI。由于桌面是一直在显示(渲染中),锁屏是后起应用,切回GUI后,先显示桌面,再显示锁屏,是正常现象。

@mhduiy mhduiy closed this Sep 21, 2026
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.

2 participants