Skip to content

fix(display): get monitor info from display dbus on hw platforms - #950

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
add-uos:develop/eagle
Oct 27, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
add-uos:develop/eagle

Conversation

@add-uos

@add-uos add-uos commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
  1. 根因:Wayland 会话下 xrandr 连接的是 Xwayland,RandR 数据由 wl_output/xdg-output 仿真合成,模式经 CVT 公式生成(受全局缩放 与合成器刷新率影响),显示 2400×1350@49.93Hz 等虚假分辨率, 且输出无 EDID 属性,无法解析屏幕尺寸与厂商信息
  2. 修复:HW 平台机型(Common::isHwPlatform)显示器信息优先走 com.deepin.daemon.Display DBus 获取真实模式数据,DBus 不可用 时回退 xrandr;接口类型由 DBus 连接器名切分填充
  3. 影响:HW 机型在 Wayland 下显示真实分辨率/刷新率/接口类型, X11 下除 PGUV 增加 DBus 失败回退外行为不变;非 HW 机型不受影响

PMS: https://pms.uniontech.com/bug-view-380841.html

Summary by Sourcery

Prefer reliable display D-Bus information on hardware platforms while retaining xrandr fallback and existing behavior elsewhere.

Bug Fixes:

  • Use display D-Bus data on hardware platforms to report accurate monitor resolution, refresh rate, and interface information under Wayland, with xrandr fallback when D-Bus data is unavailable.

Enhancements:

  • Preserve existing xrandr behavior for non-hardware platforms and normalize special-platform resolution and refresh-rate values from D-Bus data.

1. 根因:Wayland 会话下 xrandr 连接的是 Xwayland,RandR 数据由
   wl_output/xdg-output 仿真合成,模式经 CVT 公式生成(受全局缩放
   与合成器刷新率影响),显示 2400×1350@49.93Hz 等虚假分辨率,
   且输出无 EDID 属性,无法解析屏幕尺寸与厂商信息
2. 修复:HW 平台机型(Common::isHwPlatform)显示器信息优先走
   com.deepin.daemon.Display DBus 获取真实模式数据,DBus 不可用
   时回退 xrandr;接口类型由 DBus 连接器名切分填充
3. 影响:HW 机型在 Wayland 下显示真实分辨率/刷新率/接口类型,
   X11 下除 PGUV 增加 DBus 失败回退外行为不变;非 HW 机型不受影响

PMS: https://pms.uniontech.com/bug-view-380841.html
@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026

Copy link
Copy Markdown

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

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

@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026

Copy link
Copy Markdown

Reviewer's Guide

Hardware platforms now prefer real monitor modes and connector metadata from the display DBus service, avoiding unreliable Xwayland RandR values on Wayland; monitor discovery falls back to xrandr when DBus is unavailable, while non-hardware behavior remains unchanged.

Sequence diagram for hardware monitor discovery with DBus fallback

sequenceDiagram
    participant ThreadExecXrandr
    participant Common
    participant DisplayDBus
    participant Xrandr
    participant DeviceMonitor

    ThreadExecXrandr->>Common: isHwPlatform()
    alt Hardware platform
        ThreadExecXrandr->>DisplayDBus: getResolutionRateFromDBus()
        alt DBus returns monitor modes
            DisplayDBus-->>ThreadExecXrandr: monitor mode maps
            ThreadExecXrandr->>DeviceMonitor: setInfoFromDbus(mapInfo)
            DeviceMonitor->>DeviceMonitor: setAttribute(mapInfo, CurResolution)
            DeviceMonitor->>DeviceMonitor: parse connector name
        else DBus unavailable or empty
            ThreadExecXrandr->>Xrandr: getMonitorInfoFromXrandrVerbose()
        end
    else Non-hardware platform
        ThreadExecXrandr->>Xrandr: getMonitorInfoFromXrandrVerbose()
    end
Loading

Flow diagram for DBus monitor mode normalization

flowchart TD
    A[DBus monitor info received] --> B{Connector name matches display input?}
    B -->|No| C[Keep existing monitor metadata]
    B -->|Yes| D{Interface is empty and connector name matches?}
    D -->|Yes| E[Set interface from connector prefix]
    D -->|No| F[Keep existing interface]
    E --> G[Set current resolution from CurResolution]
    F --> G
    G --> H{specialComType is kSpecialType10?}
    H -->|No| I[Keep DBus resolution and refresh rate]
    H -->|Yes| J[Parse resolution and fractional refresh rate]
    J --> K[Store pixel dimensions and rounded refresh rate]
Loading

File-Level Changes

Change Details Files
Prefer display metadata from the display service on hardware platforms, while retaining xrandr as a failure fallback.
  • Route non-GPU hardware-platform monitor discovery through Display DBus.
  • Fall back to verbose xrandr discovery when DBus returns no monitor data.
  • Preserve the existing xrandr path for non-hardware platforms and GPU information.
deepin-devicemanager/src/Tool/ThreadExecXrandr.cpp
Derive monitor interface and normalize hardware-platform resolution and refresh-rate values from DBus data.
  • Extract the connector type prefix from the DBus display name when no interface is already known.
  • For the special hardware type, parse combined resolution/refresh-rate strings and expose integer dimensions plus a rounded refresh rate.
deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp
Update the source copyright range.
  • Extend the copyright year through 2026.
deepin-devicemanager/src/Tool/ThreadExecXrandr.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

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, lzwind

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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了硬件平台上显示器信息获取逻辑,将硬编码的厂商类型判断替换为通用的 isHwPlatform(), 并新增了对特殊硬件类型(kSpecialType10)的分辨率与刷新率解析。代码逻辑正确,无安全漏洞。 存在少量代码质量改进空间(缺少注释说明魔法常量、QRegExp每次调用重新编译、版权年份格式不一致), 但整体质量良好,四维度均通过,总分92分,评级优秀。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

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

建议: ['建议将正则量词改为 +(一个或多个字母),确保接口名不为空:^([a-zA-Z]+)-[\s\S]*']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

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

建议: ['为 kSpecialType10 添加注释说明该硬件类型特征及为何需要特殊分辨率解析', "修正版权年份格式为 '2022-2026'", '考虑将 QRegExp 替换为 QRegularExpression 以兼容 Qt6']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

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

建议: ['将 QRegExp 对象声明为 static const 局部变量,避免重复编译正则表达式']


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// DeviceMonitor.cpp - 优化后的 setInfoFromDbus
void DeviceMonitor::setInfoFromDbus(const QMap<QString, QString> &mapInfo)
{
    if (mapInfo["Name"].toLower().contains(m_DisplayInput.toLower(), Qt::CaseInsensitive)) {
        // 使用 + 量词确保接口名非空,static 避免重复编译
        static const QRegExp reInput("^([a-zA-Z]+)-[\\s\\S]*");
        if (m_Interface.isEmpty() && reInput.exactMatch(mapInfo["Name"])) {
            m_Interface = reInput.cap(1);
        }

        setAttribute(mapInfo, "CurResolution", m_CurrentResolution);

        // kSpecialType10: 特定硬件平台分辨率格式为 "WxH@RateHz",需解析提取
        if (Common::specialComType == Common::kSpecialType10) {
            static const QRegExp reResolution("^([0-9]{1,5})×([0-9]{1,5})@([0-9.]+)Hz$");
            if (reResolution.exactMatch(m_CurrentResolution)) {
                m_CurrentResolution = QString("%1×%2").arg(reResolution.cap(1)).arg(reResolution.cap(2));
                m_RefreshRate = QString::number(ceil(reResolution.cap(3).toDouble())) + "Hz";
            }
        }
    }
}

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

@add-uos

add-uos commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot
deepin-bot Bot merged commit e9da505 into linuxdeepin:develop/eagle Oct 27, 2026
17 checks passed
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