Skip to content

fix: correct display mode in event log for single screen / 修复单屏时事件日志显…#1123

Merged
Ivy233 merged 1 commit into
linuxdeepin:masterfrom
Ivy233:fix-display-mode-event-log
May 25, 2026
Merged

fix: correct display mode in event log for single screen / 修复单屏时事件日志显…#1123
Ivy233 merged 1 commit into
linuxdeepin:masterfrom
Ivy233:fix-display-mode-event-log

Conversation

@Ivy233
Copy link
Copy Markdown
Contributor

@Ivy233 Ivy233 commented May 23, 2026

…示模式错误

When a user unplugs an external monitor and logs in again with only one screen, the event log incorrectly shows display_mode as "EXTEND" instead of the monitor name. This fix ensures the display mode in event logs reflects the actual screen state.

当用户拔掉外接显示器后重新登录只有一个屏幕时,事件日志错误地显示 display_mode 为 "EXTEND" 而不是显示器名称。 此修复确保事件日志中的显示模式反映实际的屏幕状态。

PMS: BUG-361115

Summary by Sourcery

Bug Fixes:

  • Correct display_mode logging so that when only one screen is connected it records single-screen mode instead of an extended display state.

@Ivy233 Ivy233 requested a review from mhduiy May 23, 2026 03:44
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 23, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts display event logging so that when only one screen is connected, the logged display_mode is forced to single-screen mode instead of an extended display mode value.

Flow diagram for updated display_mode logging in logDisplayScreenEvent

flowchart TD
    A[logDisplayScreenEvent called] --> B[Read screenCount]
    B --> C{screenCount == 1?}
    C -- Yes --> D[Set displayMode = DisplayModeOnlyOne]
    C -- No --> E[Use displayMode = m.DisplayMode]
    D --> F[Get primaryMonitor]
    E --> F[Get primaryMonitor]
    F --> G[Write event log with displayMode and primaryMonitor]
Loading

File-Level Changes

Change Details Files
Ensure event log display_mode reflects single-screen mode when only one display is connected.
  • Override the current display mode value when only one screen is detected
  • Assign DisplayModeOnlyOne to the displayMode variable when screenCount equals 1 before logging the event
display1/manager.go

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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Instead of overriding displayMode when screenCount == 1, consider deriving the mode directly from the current layout/state (e.g., actual active outputs and primary assignment) so the logged value always reflects the real configuration rather than relying on a forced constant.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Instead of overriding `displayMode` when `screenCount == 1`, consider deriving the mode directly from the current layout/state (e.g., actual active outputs and primary assignment) so the logged value always reflects the real configuration rather than relying on a forced constant.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

…示模式错误

When a user unplugs an external monitor and logs in again with only one screen,
the event log incorrectly shows display_mode as "EXTEND" instead of the monitor name.
This fix ensures the display mode in event logs reflects the actual screen state.

当用户拔掉外接显示器后重新登录只有一个屏幕时,事件日志错误地显示 display_mode 为 "EXTEND" 而不是显示器名称。
此修复确保事件日志中的显示模式反映实际的屏幕状态。

PMS: BUG-361115
@Ivy233 Ivy233 force-pushed the fix-display-mode-event-log branch from 8c7db96 to e0720dd Compare May 25, 2026 05:25
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

你好!我是智能编程助手 CodeGeeX。我已仔细审查了你提供的 Git Diff 代码。

这段代码的意图是:在记录显示器屏幕事件日志时,如果检测到只有一个屏幕,则强制将显示模式覆盖为 DisplayModeOnlyOne

以下是我从语法逻辑、代码质量、代码性能和代码安全四个维度提出的审查意见和改进建议:

1. 语法与逻辑

  • 未声明的变量 screenCount:代码中直接使用了 screenCount,但在提供的 Diff 上下文中并未看到该变量的声明和赋值。如果该变量未在函数的其他位置定义,这将导致编译错误。你需要确保 screenCount 已经被正确计算和赋值。
  • 逻辑覆盖风险:直接使用赋值操作 displayMode = DisplayModeOnlyOne 会无条件覆盖 m.DisplayMode 的值。如果 m.DisplayMode 包含了其他重要的状态信息(虽然这里是日志记录,但如果是枚举值,可能会丢失原状态),这种硬覆盖可能会掩盖真实的配置状态。在日志逻辑中,这通常是可接受的,但需明确这是“业务逻辑”还是“展示逻辑”。
  • 边界条件:如果 screenCount 为 0(例如所有显示器都被断开),当前的 if screenCount == 1 不会触发,displayMode 将保持原样。需要确认这是否符合预期。

2. 代码质量

  • 魔法数字if screenCount == 1 中的 1 是一个魔法数字。建议将其提取为常量,以提高代码的可读性和可维护性。
  • 变量遮蔽displayMode := m.DisplayMode 声明了一个局部变量,后续的修改不会影响结构体 m 中的原值。这在当前场景下(仅用于日志记录)是正确的做法,避免了副作用,但建议添加注释说明此处故意使用局部变量,以免后续维护者误以为需要同步更新 m.DisplayMode

3. 代码性能

  • 获取屏幕数量的开销:当前性能影响未知,取决于 screenCount 是如何获取的。如果 screenCount 需要遍历系统显示器列表或进行系统调用,建议确保该值的获取是 O(1) 的复杂度,或者直接复用 m 对象中已经缓存的状态,避免在日志记录这种非核心路径上引入不必要的性能损耗。

4. 代码安全

  • 并发安全:如果 m.DisplayModescreenCount(或其底层数据来源)在并发环境中可能被修改,读取时必须保证线程安全。在 Go 语言中,直接读取结构体字段可能引发数据竞争。建议在读取这些状态时,确认是否需要通过互斥锁(如 m.mu.Lock())或原子操作来保护。

改进建议代码

综合以上分析,我为你提供了一份改进后的代码示例(假设 screenCount 需要通过方法或缓存获取):

// 建议将魔法数字定义为常量,提高可读性
const MinScreenCountForMultiDisplay = 2

func (m *Manager) logDisplayScreenEvent() {
    // TODO: 确保 screenCount 的获取是线程安全的,且性能良好
    // 例如: screenCount := m.getScreenCount() 
    // 暂时假设你已有 screenCount 变量
    
    // 获取当前显示模式 (局部变量,仅用于日志记录,不修改原状态)
    displayMode := m.DisplayMode
    
    // 如果屏幕数量少于多屏的最小要求,强制使用单屏模式
    // 这里使用 <= 1 可以同时处理 screenCount 为 1 或 0 的边界情况
    if screenCount < MinScreenCountForMultiDisplay {
        displayMode = DisplayModeOnlyOne
    }

    // 获取主显示器名称
    primaryMonitor := m.Primary
    // ... 后续逻辑
}

重点修改说明:

  1. 1 替换为了常量比较 MinScreenCountForMultiDisplay,逻辑更清晰。
  2. == 1 改为了 < MinScreenCountForMultiDisplay(即 <= 1),以防御 screenCount 为 0 的异常情况。
  3. 添加了关于线程安全和局部变量意图的注释提醒。

请根据你的实际项目结构,确认 screenCount 的来源及并发安全机制。如果有更多上下文代码,我可以提供更精准的优化方案!

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@Ivy233 Ivy233 merged commit 2e39d84 into linuxdeepin:master May 25, 2026
18 checks passed
@Ivy233 Ivy233 deleted the fix-display-mode-event-log branch May 25, 2026 07:25
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