Skip to content

feat: support displaying LVDS monitor info without EDID - #962

Closed
GongHeng2017 wants to merge 3 commits into
linuxdeepin:develop/eaglefrom
GongHeng2017:agent/uos-pmo/beb2927f654d
Closed

GongHeng2017 wants to merge 3 commits into
linuxdeepin:develop/eaglefrom
GongHeng2017:agent/uos-pmo/beb2927f654d

Conversation

@GongHeng2017

@GongHeng2017 GongHeng2017 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

背景

PMS Task #397927: 【智微智能】【HG3350】【IPC-830h】系统下设备管理器未识别到LVDS屏信息

Story #42241: 设备管理器-显示设备中支持显示LVDS显示器

问题

设备管理器-显示设备中当前从 EDID 读取厂商信息显示,LVDS 设备无 EDID,导致识别不到对应信息,设备管理器中无展示。

修复方案

通过 xrandr --verbose 读取所有已连接但缺少 EDID 的显示接口(不限于 LVDS,也包括 VGA/DVI/HDMI/DP/eDP 等),补充 hwinfo / xrandr(EDID) 未识别的显示器信息。

变更内容

  • DeviceMonitor::setInfoFromLvds(): 新增方法,设置无 EDID 显示器的基本信息(接口名、分辨率、刷新率、宽高比等)
  • DeviceGenerator::getMonitorWithoutEdidFromXrandr(): 新增方法,执行 xrandr --verbose 解析所有已连接但无 EDID 的显示接口,补充分辨率/刷新率等信息
  • 在 DeviceGenerator::generatorMonitor() 末尾调用,确保不覆盖已有 EDID 显示器

流程基线

Summary by Sourcery

Display connected monitors without EDID data by supplementing existing monitor detection with xrandr information.

New Features:

  • Add monitor detection for connected display interfaces that do not provide EDID information, including LVDS and other connector types.
  • Expose display input identifiers and populate basic monitor details such as connector, resolution, refresh rate, supported resolutions, and primary-display status.

Bug Fixes:

  • Ensure displays without EDID are shown in the device manager while avoiding duplicate entries for monitors already detected through existing sources.
  • Handle monitor overview formatting when screen-size information is unavailable.

LVDS displays don't provide EDID data, causing device manager to fail
to recognize them. Add getMonitorWithoutEdidFromXrandr() to parse
xrandr --verbose output for connected displays without EDID, and
setInfoFromLvds() to populate monitor info from xrandr data.

Task: https://pms.uniontech.com/task-view-397927.html
Story: https://pms.uniontech.com/story-view-42241.html
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: GongHeng2017

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 Nov 3, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR adds an xrandr-based fallback monitor-generation path for connected displays without EDID, constructs display records from connector and mode data without replacing existing EDID-backed records, and adjusts monitor presentation for missing screen-size information.

Sequence diagram for fallback monitor discovery without EDID

sequenceDiagram
    participant Generator as DeviceGenerator
    participant Xrandr as xrandr
    participant Monitor as DeviceMonitor
    participant Manager as DeviceManager

    Generator->>Generator: getMonitorInfoFromHwinfo()
    Generator->>Generator: getMonitorWithoutEdidFromXrandr()
    Generator->>Xrandr: xrandr --verbose
    Xrandr-->>Generator: connector and mode data
    alt connected connector without EDID
        Generator->>Monitor: setInfoFromLvds(connectorName, interfaceType, isPrimary, currentResolution, currentRate, supportResolutions)
        Monitor-->>Generator: monitor information populated
        Generator->>Manager: addMonitor(device)
    else connector has EDID or is disconnected
        Generator-->>Generator: skip connector
    end
Loading

File-Level Changes

Change Details Files
Add a fallback path that discovers connected displays lacking EDID by parsing xrandr --verbose.
  • Execute xrandr --verbose during monitor generation.
  • Track connector boundaries, connection state, EDID presence, primary status, current mode, refresh rates, and supported resolutions.
  • Create fallback monitor entries only for connected connectors without EDID, while leaving EDID-backed monitor handling unchanged.
src/GenerateDevice/DeviceGenerator.cpp
src/GenerateDevice/DeviceGenerator.h
Populate fallback monitor objects with connector-derived identity and display mode information.
  • Add a setter for connector name, interface type, primary status, resolution, refresh rate, and supported modes.
  • Use connector names as fallback name/model/raw interface and Unknown as vendor.
  • Calculate the aspect ratio before formatting the current resolution for display.
src/DeviceManager/DeviceMonitor.cpp
src/DeviceManager/DeviceMonitor.h
Make monitor overview formatting tolerate displays without physical-size data.
  • Display only the monitor name when screen size is unavailable instead of rendering an empty-size suffix.
src/DeviceManager/DeviceMonitor.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

@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 1 issue

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

## Individual Comments

### Comment 1
<location path="deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp" line_range="149" />
<code_context>
+
+    // 当前分辨率(先用原始格式计算比例,再转为显示格式)
+    m_CurrentResolution = currentResolution;
+    caculateScreenRatio();
+    m_CurrentResolution.replace("x", "×", Qt::CaseInsensitive);
+    if (!refreshRate.isEmpty()) {
</code_context>
<issue_to_address>
**Monitor discovery crashes**

When a connected output has no active mode, leaving `currentResolution` empty, `setInfoFromLvds()` passes the empty resolution to `caculateScreenRatio()`, which reaches `gcd(0, 0)` and divides by zero; device generation crashes instead of listing the display.

Skip ratio calculation or handle an empty resolution before calling `caculateScreenRatio()`.
</issue_to_address>

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


// 当前分辨率(先用原始格式计算比例,再转为显示格式)
m_CurrentResolution = currentResolution;
caculateScreenRatio();

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 · Monitor discovery crashes

When a connected output has no active mode, leaving currentResolution empty, setInfoFromLvds() passes the empty resolution to caculateScreenRatio(), which reaches gcd(0, 0) and divides by zero; device generation crashes instead of listing the display.

Skip ratio calculation or handle an empty resolution before calling caculateScreenRatio().

Prompt for AI agents
In `deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp` at line 149:

**Monitor discovery crashes**

When a connected output has no active mode, leaving `currentResolution` empty, `setInfoFromLvds()` passes the empty resolution to `caculateScreenRatio()`, which reaches `gcd(0, 0)` and divides by zero; device generation crashes instead of listing the display.

Skip ratio calculation or handle an empty resolution before calling `caculateScreenRatio()`.

P2: In getMonitorWithoutEdidFromXrandr(), check existing monitors in
DeviceManager for matching displayInput (connectorName) before calling
addMonitor(), preventing duplicate entries under Wayland where xrandr
cannot read EDID.

P3: Replace waitForFinished(-1) with waitForFinished(5000) to avoid
infinite blocking when xrandr hangs.

Add displayInput() public getter to DeviceMonitor for the dedup check.
Update doxygen comment to remove LVDS-specific wording and reflect
the general 'no EDID' purpose. Function logic unchanged.
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为 deepin-devicemanager 新增无 EDID 显示器信息显示功能,代码逻辑基本正确,安全无漏洞。存在使用已废弃 Qt API(QRegExp、QString::SkipEmptyParts)及边界条件处理不够严谨等轻微问题,建议替换为 QRegularExpression 并加强空值防护。

🔍 详细分析

1. 语法逻辑 ❌

评价: 存在逻辑缺陷 ❌ 不通过

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

建议: ['在 setInfoFromXrandrWithoutEdid() 中增加 currentResolution 非空判断,仅当分辨率非空时才拼接刷新率', '将所有 QRegExp 替换为 QRegularExpression,使用 match() 和 captured() 替代 indexIn() 和 cap()', '将 QString::SkipEmptyParts 替换为 Qt::SkipEmptyParts']


2. 代码质量 ✅

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

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

建议: ['考虑将 getMonitorWithoutEdidFromXrandr() 拆分为 xrandr 输出解析和显示器创建两个子函数', "更新 DeviceMonitor.cpp 第138行注释为 '设置无 EDID 的已连接显示器信息'"]


3. 代码性能 ✅

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

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

建议: ['确认 generatorMonitorDevice() 在后台线程执行,避免阻塞主线程', '替换 QRegExp 为 QRegularExpression 以获得更好的正则匹配性能']


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: ['建议检查 process.waitForFinished(5000) 的返回值,虽然已有 output.isEmpty() 后续检查,但显式处理超时更健壮']


💡 改进建议代码示例

// 修复1: DeviceMonitor.cpp — 增加空值防护
void DeviceMonitor::setInfoFromXrandrWithoutEdid(const QString &connectorName, const QString &interfaceType,
                                     bool isPrimary, const QString &currentResolution,
                                     const QString &refreshRate, const QStringList &supportResolutions)
{
    // 设置无 EDID 的已连接显示器信息
    m_DisplayInput = connectorName;
    m_Interface = interfaceType;
    m_RawInterface = connectorName;
    m_Name = connectorName;
    m_Model = connectorName;
    m_Vendor = "Unknown";
    m_MainScreen = isPrimary ? "Yes" : "NO";

    // 当前分辨率(先用原始格式计算比例,再转为显示格式)
    m_CurrentResolution = currentResolution;
    caculateScreenRatio();
    m_CurrentResolution.replace("x", "×", Qt::CaseInsensitive);
    // 仅当分辨率非空时才拼接刷新率,避免产生畸形字符串
    if (!refreshRate.isEmpty() && !m_CurrentResolution.isEmpty()) {
        m_CurrentResolution += " @" + refreshRate;
        m_RefreshRate = refreshRate;
    }

    // 支持的分辨率
    m_SupportResolution = supportResolutions.join(", ");
}

// 修复2: DeviceGenerator.cpp — 替换 QRegExp 为 QRegularExpression
#include <QRegularExpression>
// 移除 #include <QRegExp>

void DeviceGenerator::getMonitorWithoutEdidFromXrandr()
{
    QProcess process;
    process.start("xrandr", QStringList() << "--verbose");
    process.waitForFinished(5000);
    QString output = process.readAllStandardOutput();
    if (output.isEmpty())
        return;

    // 使用 Qt::SkipEmptyParts 替代 QString::SkipEmptyParts
    QStringList lines = output.split("\n", Qt::SkipEmptyParts);

    // ... 变量声明省略 ...

    // 使用 QRegularExpression 替代 QRegExp
    QRegularExpression reEdid("^\\t{2}([0-9a-f]{32}).*");

    for (int i = 0; i < lines.size(); i++) {
        const QString &line = lines[i];
        // ... 连接器解析逻辑省略 ...

        if (reEdid.match(line).hasMatch()) {
            hasEdid = true;
            continue;
        }

        // 分辨率行
        if (line.startsWith(" ") && !line.contains(":") && !line.contains("connect")) {
            QRegularExpression reRes("^\\s+(\\d+x\\d+\\w*)");
            auto match = reRes.match(line);
            if (match.hasMatch()) {
                lastResolution = match.captured(1);
                lastWasCurrent = line.contains("*current");
                if (lastWasCurrent) {
                    currentResolution = lastResolution;
                }
            }
            continue;
        }

        // v: 行包含刷新率
        if (line.startsWith(" ") && line.contains("v:") && line.contains("clock")) {
            QRegularExpression reRate("clock\\s+(\\d+\\.\\d+)Hz");
            auto match = reRate.match(line);
            if (match.hasMatch() && !lastResolution.isEmpty()) {
                QString rate = match.captured(1) + "Hz";
                // ... 其余逻辑不变 ...
            }
        }
    }
    createMonitor();
}


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

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