Repository navigation
feat: add fallback detection for monitors without EDID - #983
Conversation
Reviewer's GuideAPIDeclare the new no-EDID monitor-population method and update the header attribution.
Declare the xrandr fallback entry point on DeviceGenerator.
Uses of the APIInvoke fallback detection only when the standard hwinfo path produced no monitors.
ImplementationPopulate monitor fields from connector details when EDID data is unavailable.
Run xrandr and parse connected EDID-less connectors into fallback monitor objects.
UIAvoid appending empty screen-size parentheses in monitor overview text.
TestsTest EDID filtering, fallback monitor fields, and empty xrandr output.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 8 issues
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="339" />
<code_context>
+
+ // 当前分辨率(先用原始格式计算比例,再转为显示格式)
+ m_CurrentResolution = currentResolution;
+ caculateScreenRatio();
+ m_CurrentResolution.replace("x", "×", Qt::CaseInsensitive);
+ if (!refreshRate.isEmpty()) {
</code_context>
<issue_to_address>
**Device manager crashes on missing resolution**
When a connected EDID-less connector has no mode marked `*current`, `caculateScreenRatio()` matches the empty resolution as zero width and height, then `gcd(0, 0)` evaluates modulo by zero and terminates the device manager instead of listing the display.
Guard the empty resolution before calculating the screen ratio, or make the ratio calculation handle zero dimensions safely.
</issue_to_address>
### Comment 2
<location path="deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp" line_range="917-918" />
<code_context>
+ // 有 EDID 的接口已由 getMonitorInfoFromHwinfo -> setMonitorInfoFromXrandr 处理,此处不再重复添加
+ QProcess process;
+ process.start("xrandr", QStringList() << "--verbose");
+ process.waitForFinished(5000);
+ if (process.exitCode() != 0) {
+ qCWarning(appLog) << "xrandr --verbose failed with exit code:" << process.exitCode();
+ return;
</code_context>
<issue_to_address>
**Slow query omits monitor**
When `xrandr --verbose` takes longer than five seconds to finish, `waitForFinished(5000)` times out, but the return value is ignored; the subsequent exit-code check returns before parsing output or creating monitors, leaving the connected monitor absent from the device manager.
Handle a timed-out wait explicitly, for example by allowing a suitable retry or reporting the failed fallback rather than silently treating it as completed output.
</issue_to_address>
### Comment 3
<location path="deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp" line_range="995" />
<code_context>
+ }
+
+ // 分辨率行:以空格开头,不包含 ":"
+ if (line.startsWith(" ") && !line.contains(":") && !line.contains("connect")) {
+ QRegularExpression reRes("^\\s+(\\d+x\\d+\\w*)");
+ QRegularExpressionMatch matchRes = reRes.match(line);
</code_context>
<issue_to_address>
**Resolution details stay empty**
When `xrandr --verbose` indents mode and timing lines with tabs, the mode and timing lines in `xrandr --verbose` are tab-indented on common systems, so both `startsWith(" ")` checks skip them. The monitor is still added, but its current resolution, refresh rate, and supported resolutions remain empty.
Recognize any leading whitespace when parsing mode and timing lines.
Also at `deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp:1009`.
</issue_to_address>
### Comment 4
<location path="deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp" line_range="330-338" />
<code_context>
+{
+ // 设置 LVDS 显示器信息
+ m_DisplayInput = connectorName; // 显示输入,如 LVDS-0
+ m_Interface = interfaceType; // 接口类型,如 LVDS
+ 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);
</code_context>
<issue_to_address>
**Fallback monitor state goes stale**
When a fallback monitor's resolution or primary status changes after generation and the monitor-page xrandr refresh runs, `setInfoFromXrandrWithoutEdid` pre-populates `m_Interface` and `m_CurrentResolution`; after the live mode or primary status changes, the monitor-page xrandr refresh reaches the existing-interface branch in `setInfoFromXradr`, which does not refresh those fields, so the device manager displays the old state.
Update the live resolution and primary fields from each refresh for fallback monitors instead of treating their pre-populated interface as already refreshed.
</issue_to_address>
### Comment 5
<location path="deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp" line_range="972" />
<code_context>
+ // 解析新的连接器
+ QStringList parts = line.split(" ", QT_SKIP_EMPTY_PARTS);
+ connectorName = parts.isEmpty() ? "" : parts[0].trimmed();
+ isPrimary = line.contains("primary");
+ // 判断是否连接:行中存在 "connected",且不是 "disconnected"(disconnected 包含 connected 子串)
+ isConnected = line.contains("connected") && !line.contains("disconnected");
</code_context>
<issue_to_address>
**Primary monitor is marked non-primary**
When the fallback runs on Wayland, where xrandr omits primary information, the parser treats the missing primary marker as `false`, and `setInfoFromXrandrWithoutEdid` stores that as `NO`, so connected monitors—including the only monitor—are reported as non-primary.
Preserve the missing primary status instead of treating it as false, and avoid storing `NO` when xrandr provides no primary information.
Also at `deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp:335-336`.
</issue_to_address>
### Comment 6
<location path="deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp" line_range="940" />
<code_context>
+ // 创建并添加无 EDID 的已连接显示器
+ auto createMonitor = [&]() {
+ // 仅处理已连接且无 EDID 的接口
+ if (!isConnected || hasEdid || connectorName.isEmpty())
+ return;
+
</code_context>
<issue_to_address>
**Virtual outputs appear as monitors**
When xrandr reports a connected virtual output such as `XWAYLAND0` without EDID while hwinfo yields no monitors, `createMonitor` accepts every connected, EDID-less connector without checking whether it represents a physical display, so a virtual output such as `XWAYLAND0` is added as a monitor and appears as a phantom device.
Exclude known virtual outputs from the fallback, or otherwise verify that a connector represents a physical display before adding it.
</issue_to_address>
### Comment 7
<location path="deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp" line_range="945-947" />
<code_context>
+
+ // 接口类型:去掉末尾的 -N
+ QString interfaceType = connectorName;
+ int dashPos = interfaceType.lastIndexOf('-');
+ if (dashPos > 0)
+ interfaceType = interfaceType.left(dashPos);
+
+ DeviceMonitor *device = new DeviceMonitor();
</code_context>
<issue_to_address>
**Monitor details show the wrong interface**
When xrandr reports connectors such as `DP-1-1`, `HDMI-A-1`, or `VGA1`, the last-dash truncation leaves port segments in `interfaceType` (or leaves `VGA1` unchanged), so `setInfoFromXrandrWithoutEdid` records a port identifier rather than the interface type; for `HDMI-A-1`, it also disagrees with the existing Xrandr path, and monitor details show the wrong type.
Derive the interface type using the existing Xrandr path’s connector-name parsing instead of removing only the final dash-separated segment.
</issue_to_address>
### Comment 8
<location path="deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp" line_range="391-392" />
<code_context>
ov = QString("(%1)").arg(m_ScreenSize);
} else {
- ov = QString("%1(%2)").arg(m_Name).arg(m_ScreenSize);
+ ov = m_ScreenSize.isEmpty() ? QString("%1").arg(m_Name)
+ : QString("%1(%2)").arg(m_Name).arg(m_ScreenSize);
}
} else {
</code_context>
<issue_to_address>
**Overview shows blank parentheses**
When a fallback monitor has an empty screen size and `Common::specialComType` is 6 or 7, `getOverviewInfo()` takes the special-type branch before the new empty-size guard and formats the empty `m_ScreenSize` as `()`, so users see blank parentheses instead of a useful monitor overview.
Update the special-type 6/7 branch to omit the parentheses when the screen size is empty.
</issue_to_address>
|
|
||
| // 当前分辨率(先用原始格式计算比例,再转为显示格式) | ||
| m_CurrentResolution = currentResolution; | ||
| caculateScreenRatio(); |
There was a problem hiding this comment.
🟡 Medium · Device manager crashes on missing resolution
When a connected EDID-less connector has no mode marked *current, caculateScreenRatio() matches the empty resolution as zero width and height, then gcd(0, 0) evaluates modulo by zero and terminates the device manager instead of listing the display.
Guard the empty resolution before calculating the screen ratio, or make the ratio calculation handle zero dimensions safely.
Prompt for AI agents
In `deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp` at line 339:
**Device manager crashes on missing resolution**
When a connected EDID-less connector has no mode marked `*current`, `caculateScreenRatio()` matches the empty resolution as zero width and height, then `gcd(0, 0)` evaluates modulo by zero and terminates the device manager instead of listing the display.
Guard the empty resolution before calculating the screen ratio, or make the ratio calculation handle zero dimensions safely.
| process.waitForFinished(5000); | ||
| if (process.exitCode() != 0) { |
There was a problem hiding this comment.
🟡 Medium · Slow query omits monitor
When xrandr --verbose takes longer than five seconds to finish, waitForFinished(5000) times out, but the return value is ignored; the subsequent exit-code check returns before parsing output or creating monitors, leaving the connected monitor absent from the device manager.
Handle a timed-out wait explicitly, for example by allowing a suitable retry or reporting the failed fallback rather than silently treating it as completed output.
Prompt for AI agents
In `deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp` at lines 917-918:
**Slow query omits monitor**
When `xrandr --verbose` takes longer than five seconds to finish, `waitForFinished(5000)` times out, but the return value is ignored; the subsequent exit-code check returns before parsing output or creating monitors, leaving the connected monitor absent from the device manager.
Handle a timed-out wait explicitly, for example by allowing a suitable retry or reporting the failed fallback rather than silently treating it as completed output.
| } | ||
|
|
||
| // 分辨率行:以空格开头,不包含 ":" | ||
| if (line.startsWith(" ") && !line.contains(":") && !line.contains("connect")) { |
There was a problem hiding this comment.
🟡 Medium · Resolution details stay empty
When xrandr --verbose indents mode and timing lines with tabs, the mode and timing lines in xrandr --verbose are tab-indented on common systems, so both startsWith(" ") checks skip them. The monitor is still added, but its current resolution, refresh rate, and supported resolutions remain empty.
Recognize any leading whitespace when parsing mode and timing lines.
Also at deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp:1009.
Prompt for AI agents
In `deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp` at line 995:
**Resolution details stay empty**
When `xrandr --verbose` indents mode and timing lines with tabs, the mode and timing lines in `xrandr --verbose` are tab-indented on common systems, so both `startsWith(" ")` checks skip them. The monitor is still added, but its current resolution, refresh rate, and supported resolutions remain empty.
Recognize any leading whitespace when parsing mode and timing lines.
Also at `deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp:1009`.
| m_Interface = interfaceType; // 接口类型,如 LVDS | ||
| m_RawInterface = connectorName; // 原始接口名 | ||
| m_Name = connectorName; // 名称 | ||
| m_Model = connectorName; // 型号 | ||
| m_Vendor = "Unknown"; // 厂商 | ||
| m_MainScreen = isPrimary ? "Yes" : "NO"; // 是否主显示器 | ||
|
|
||
| // 当前分辨率(先用原始格式计算比例,再转为显示格式) | ||
| m_CurrentResolution = currentResolution; |
There was a problem hiding this comment.
🟡 Medium · Fallback monitor state goes stale
When a fallback monitor's resolution or primary status changes after generation and the monitor-page xrandr refresh runs, setInfoFromXrandrWithoutEdid pre-populates m_Interface and m_CurrentResolution; after the live mode or primary status changes, the monitor-page xrandr refresh reaches the existing-interface branch in setInfoFromXradr, which does not refresh those fields, so the device manager displays the old state.
Update the live resolution and primary fields from each refresh for fallback monitors instead of treating their pre-populated interface as already refreshed.
Prompt for AI agents
In `deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp` at lines 330-338:
**Fallback monitor state goes stale**
When a fallback monitor's resolution or primary status changes after generation and the monitor-page xrandr refresh runs, `setInfoFromXrandrWithoutEdid` pre-populates `m_Interface` and `m_CurrentResolution`; after the live mode or primary status changes, the monitor-page xrandr refresh reaches the existing-interface branch in `setInfoFromXradr`, which does not refresh those fields, so the device manager displays the old state.
Update the live resolution and primary fields from each refresh for fallback monitors instead of treating their pre-populated interface as already refreshed.
| // 解析新的连接器 | ||
| QStringList parts = line.split(" ", QT_SKIP_EMPTY_PARTS); | ||
| connectorName = parts.isEmpty() ? "" : parts[0].trimmed(); | ||
| isPrimary = line.contains("primary"); |
There was a problem hiding this comment.
🟡 Medium · Primary monitor is marked non-primary
When the fallback runs on Wayland, where xrandr omits primary information, the parser treats the missing primary marker as false, and setInfoFromXrandrWithoutEdid stores that as NO, so connected monitors—including the only monitor—are reported as non-primary.
Preserve the missing primary status instead of treating it as false, and avoid storing NO when xrandr provides no primary information.
Also at deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp:335-336.
Prompt for AI agents
In `deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp` at line 972:
**Primary monitor is marked non-primary**
When the fallback runs on Wayland, where xrandr omits primary information, the parser treats the missing primary marker as `false`, and `setInfoFromXrandrWithoutEdid` stores that as `NO`, so connected monitors—including the only monitor—are reported as non-primary.
Preserve the missing primary status instead of treating it as false, and avoid storing `NO` when xrandr provides no primary information.
Also at `deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp:335-336`.
| // 创建并添加无 EDID 的已连接显示器 | ||
| auto createMonitor = [&]() { | ||
| // 仅处理已连接且无 EDID 的接口 | ||
| if (!isConnected || hasEdid || connectorName.isEmpty()) |
There was a problem hiding this comment.
🟡 Medium · Virtual outputs appear as monitors
When xrandr reports a connected virtual output such as XWAYLAND0 without EDID while hwinfo yields no monitors, createMonitor accepts every connected, EDID-less connector without checking whether it represents a physical display, so a virtual output such as XWAYLAND0 is added as a monitor and appears as a phantom device.
Exclude known virtual outputs from the fallback, or otherwise verify that a connector represents a physical display before adding it.
Prompt for AI agents
In `deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp` at line 940:
**Virtual outputs appear as monitors**
When xrandr reports a connected virtual output such as `XWAYLAND0` without EDID while hwinfo yields no monitors, `createMonitor` accepts every connected, EDID-less connector without checking whether it represents a physical display, so a virtual output such as `XWAYLAND0` is added as a monitor and appears as a phantom device.
Exclude known virtual outputs from the fallback, or otherwise verify that a connector represents a physical display before adding it.
| int dashPos = interfaceType.lastIndexOf('-'); | ||
| if (dashPos > 0) | ||
| interfaceType = interfaceType.left(dashPos); |
There was a problem hiding this comment.
🟡 Medium · Monitor details show the wrong interface
When xrandr reports connectors such as DP-1-1, HDMI-A-1, or VGA1, the last-dash truncation leaves port segments in interfaceType (or leaves VGA1 unchanged), so setInfoFromXrandrWithoutEdid records a port identifier rather than the interface type; for HDMI-A-1, it also disagrees with the existing Xrandr path, and monitor details show the wrong type.
Derive the interface type using the existing Xrandr path’s connector-name parsing instead of removing only the final dash-separated segment.
Prompt for AI agents
In `deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp` at lines 945-947:
**Monitor details show the wrong interface**
When xrandr reports connectors such as `DP-1-1`, `HDMI-A-1`, or `VGA1`, the last-dash truncation leaves port segments in `interfaceType` (or leaves `VGA1` unchanged), so `setInfoFromXrandrWithoutEdid` records a port identifier rather than the interface type; for `HDMI-A-1`, it also disagrees with the existing Xrandr path, and monitor details show the wrong type.
Derive the interface type using the existing Xrandr path’s connector-name parsing instead of removing only the final dash-separated segment.
| ov = m_ScreenSize.isEmpty() ? QString("%1").arg(m_Name) | ||
| : QString("%1(%2)").arg(m_Name).arg(m_ScreenSize); |
There was a problem hiding this comment.
🟡 Medium · Overview shows blank parentheses
When a fallback monitor has an empty screen size and Common::specialComType is 6 or 7, getOverviewInfo() takes the special-type branch before the new empty-size guard and formats the empty m_ScreenSize as (), so users see blank parentheses instead of a useful monitor overview.
Update the special-type 6/7 branch to omit the parentheses when the screen size is empty.
Prompt for AI agents
In `deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp` at lines 391-392:
**Overview shows blank parentheses**
When a fallback monitor has an empty screen size and `Common::specialComType` is 6 or 7, `getOverviewInfo()` takes the special-type branch before the new empty-size guard and formats the empty `m_ScreenSize` as `()`, so users see blank parentheses instead of a useful monitor overview.
Update the special-type 6/7 branch to omit the parentheses when the screen size is empty.
When only a monitor without EDID (e.g. LVDS, or VGA/DVI/HDMI/DP/eDP without EDID data) is connected, hwinfo/xrandr cannot identify it and the device manager shows no monitor entry. Add a fallback path that runs `xrandr --verbose` and parses connected interfaces that have no EDID block, so such monitors are still listed. - DeviceGenerator: add getMonitorWithoutEdidFromXrandr() to query xrandr --verbose and create a monitor for connected, EDID-less connectors, invoked when getMonitorInfoFromHwinfo() yields no monitor - DeviceMonitor: add setInfoFromXrandrWithoutEdid() to populate monitor info (interface, primary flag, resolution, refresh rate, supported resolutions) from the xrandr output - DeviceMonitor: guard getOverviewInfo() against an empty screen size to avoid formatting "name()" with a blank size Log: 当hwinfo检测不到监视器时,通过xrandr获取连接信息,生成监视器 PMS: Task-398193 Influence: 影响监视器的显示
713d326 to
0e2b8c9
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, GongHeng2017, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
When only a monitor without EDID (e.g. LVDS, or VGA/DVI/HDMI/DP/eDP without EDID data) is connected, hwinfo/xrandr cannot identify it and the device manager shows no monitor entry.
Add a fallback path that runs
xrandr --verboseand parses connected interfaces that have no EDID block, so such monitors are still listed.Log: 增加兜底策略,当前hwinfo 检测不到监视器时,通过 xrandr 获取连接信息,
生成监视器信息
PMS: Task#398193
Influence: 影响监视器的显示
Summary by Sourcery
Ensure EDID-less connected monitors are detected and displayed when standard hardware discovery cannot identify them.
New Features:
Bug Fixes:
Enhancements:
Tests: