Skip to content

fix(display): avoid duplicate UUIDs for identical EDID monitors - #1295

Draft
Ivy233 wants to merge 1 commit into
linuxdeepin:release/2500from
Ivy233:fix/display-duplicate-edid-uuid
Draft

Ivy233 wants to merge 1 commit into
linuxdeepin:release/2500from
Ivy233:fix/display-duplicate-edid-uuid

Conversation

@Ivy233

@Ivy233 Ivy233 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Monitors with identical EDID (same model and batch without a unique serial number) were all mapped to the first matching DRM connector by getStdMonitorName(), so they received the same UUID. Config lookup by UUID then always returned the first entry, collapsing every screen to the same X/Y and restoring the overlap after each apply or drag.

Prefer the X output name when matching the DRM connector. If the EDID matches multiple connectors and the output name cannot identify one, return an error so the caller falls back to the unique X output name. Match saved monitor configs by UUID + Name, with a UUID fallback for compatibility, when selecting the mirror primary and applying configs.

Add regression tests for identical EDIDs, ambiguous matches, unique non-exact matches, UUID + Name config lookup and primary selection.

Log: Identical-EDID monitors now get distinct UUIDs and keep their own positions.

Influence:

  1. Connect multiple identical-EDID monitors; each monitor gets a distinct UUID and keeps its own saved X/Y after apply and logout/login.
  2. Existing configurations whose Name does not match still fall back to UUID lookup and are not disabled.
  3. Single-monitor and unique-EDID setups keep the previous UUID and config behavior.

fix(display): 避免 EDID 相同的显示器生成重复 UUID

同型号同批次显示器可能没有唯一序列号,EDID 完全相同。
getStdMonitorName() 原来只按 EDID 返回第一个匹配的 DRM connector, 导致这些显示器生成相同 UUID。配置按 UUID 查找时永远命中第一条,
所有屏幕被写成相同的 X/Y,拖拽或 apply 后又恢复重叠。

改为优先用 X output 名称精确匹配 connector;EDID 匹配到多个
connector 且无法按名称区分时返回错误,由调用方回退到唯一的
X output 名称。同时在复制模式主屏选择和配置应用路径中优先按
UUID + Name 匹配,匹配不到再回退到原 UUID 逻辑,兼容旧配置。

补充相同 EDID、歧义匹配、唯一但名称不完全匹配、UUID + Name
配置查找和主屏选择的回归测试。

Log: EDID 相同的显示器现在会生成不同 UUID,并各自保持位置。

Influence:

  1. 接入多台 EDID 相同的显示器,每台生成不同 UUID,apply 和注销重登后各自保持 X/Y。
  2. 旧配置 Name 不匹配时仍回退 UUID 查找,不会被误禁用。
  3. 单屏和 EDID 唯一的场景保持原有 UUID 和配置行为。

PMS: BUG-382483

Summary by Sourcery

Keep identical-EDID monitors’ identities and saved display layouts distinct while retaining compatibility with existing configurations.

Bug Fixes:

  • Give identical-EDID monitors distinct UUIDs when their DRM connector cannot be identified unambiguously, preventing their saved layouts from collapsing onto one another.
  • Migrate safely identifiable legacy screen configurations that used duplicate UUIDs to the monitors’ distinct UUIDs while preserving layouts and fill modes.

Enhancements:

  • Match monitor configurations and mirror-primary selection by UUID plus output name, falling back to UUID when names do not match for compatibility.
  • Preserve existing UUID behavior for uniquely matched connectors and single-monitor setups, and avoid overwriting names on configurations with ambiguous UUIDs.

Tests:

  • Add regression coverage for identical and ambiguous EDID matches, UUID compatibility, configuration lookup, primary selection, and duplicate-UUID configuration migration.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 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

@sourcery-ai

sourcery-ai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Review how per-refresh EDID matching assigns stable, distinct monitor UUIDs, including connector selection and the fallback rules that preserve legacy UUIDs when matching is unambiguous.

  • display1/util.go L218-229, L408-481 (+2 small edits)
  • display1/xorg.go L428-489, L515-539 (+4 small edits)

Review UUID-plus-name monitor and configuration lookup, and duplicate-UUID name preservation, which establish the identity rules used by callers.

  • display1/config.go L43-56
  • display1/monitor.go L560-571

Uses of the API

Review the display-manager call sites that use UUID-plus-name lookup and primary selection, with UUID-only fallback for compatibility.

  • display1/manager.go L1713-2585 (6 small edits)

Review configuration-update paths that run duplicate-UUID migrations before normal UUID updates and persist any resulting changes.

  • display1/displayconf.go L158-161, L212-215

Implementation

Review the migration planner and screen, user, and fill-mode rewriting logic, including its safeguards against ambiguous monitor mappings and its handling of competing saved layouts.

  • display1/displayconf.go L450-812, L1078-1115

Tests

Review regression coverage for UUID assignment, matching, lookup, primary selection, and randomized topology properties.

  • display1/duplicate_uuid_test.go L1-583
  • display1/stdname_property_test.go L1-76

Review regression coverage for duplicate-UUID migration, safe rejection of ambiguous cases, and preservation of layouts and related settings.

  • display1/migration_test.go L1-405

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 8 issues

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

## Individual Comments

### Comment 1
<location path="display1/util.go" line_range="440-441" />
<code_context>
+			continue
 		}
+
+		if connectorName == outputName {
+			exactMatches = append(exactMatches, connectorName)
+		} else {
+			otherMatches = append(otherMatches, connectorName)
</code_context>
<issue_to_address>
**Saved layouts lose monitor positions**

When a saved system layout contains identical-EDID monitors under their former shared UUID, `updateUuid` leaves these `|v1` UUIDs unmigrated or maps repeated UUIDs to the same first monitor, so `getSysScreenConfig` looks up a different monitor-set key and returns an empty config. The saved layout is not applied.

Migrate each entry with a duplicate old UUID to its corresponding connector-specific UUID before rebuilding the saved system-layout key.

Also at `display1/util.go:448`.
</issue_to_address>

### Comment 2
<location path="display1/util.go" line_range="440-441" />
<code_context>
+			continue
 		}
+
+		if connectorName == outputName {
+			exactMatches = append(exactMatches, connectorName)
+		} else {
+			otherMatches = append(otherMatches, connectorName)
</code_context>
<issue_to_address>
**Saved monitor positions are lost**

When a user upgrades with saved configs for identical-EDID monitors under their former shared UUID, `updateUuid` leaves some `|v1` UUIDs unchanged or maps repeated UUIDs to the first monitor, so `applySysMonitorConfigs` cannot match the other monitors’ saved configs or applies the first config’s position to them. The monitors are disabled or their saved positions are lost.

Migrate each saved monitor config to the corresponding connector-specific UUID using the monitor’s identity rather than UUID alone.

Also at `display1/manager.go:2447`.
</issue_to_address>

### Comment 3
<location path="display1/manager.go" line_range="1922" />
<code_context>
 			// TODO 这里为什么需要更新 Name?
 			updateSysMonitorConfigsName(configs, m.monitorMap)
-			configs.setPrimary(primaryMonitor.uuid)
+			configs.setPrimaryByUuidAndName(primaryMonitor.uuid, primaryMonitor.Name)
 		}

</code_context>
<issue_to_address>
**Primary selection collapses monitor configs**

When the user changes the primary in Extend mode while multiple connected monitors share a UUID, `updateSysMonitorConfigsName` matches configs by UUID alone, so when identical-EDID monitors share a UUID it overwrites every saved config name with the first matching monitor’s name. `setPrimaryByUuidAndName` then saves those collapsed names, and `applySysMonitorConfigs` matches by UUID and name exactly, so the other monitors lose their configs and are disabled on a later apply.

Update config names by matching both UUID and the existing monitor name, or otherwise preserve the distinct names for configs with duplicate UUIDs.
</issue_to_address>

### Comment 4
<location path="display1/displayconf.go" line_range="721-722" />
<code_context>
+		}
+	}
+
+	// Name 不匹配时回退到旧行为,避免旧配置导致显示器被直接禁用。
+	return cfgs.getByUuid(uuid)
+}
+
</code_context>
<issue_to_address>
**Legacy configs still collapse**

When saved configs contain multiple entries with the same UUID and their names do not match the connected monitors, `getByUuidAndName` falls back to the first UUID match for each monitor, so monitors sharing a legacy UUID and having names that no longer match all receive the same saved position. `setPrimary` can also rewrite every such config’s name to the first matching monitor, leaving the saved configurations indistinguishable; apply then restores the overlap.

When UUID fallback finds multiple configs, preserve or resolve their per-monitor identity instead of applying the first entry to every monitor.

Also at `display1/manager.go:1922`.
</issue_to_address>

### Comment 5
<location path="display1/displayconf.go" line_range="731" />
<code_context>
-		} else {
-			mc.Primary = false
-		}
+		mc.Primary = mc.UUID == uuid && (name == "" || mc.Name == name)
 	}
 }
</code_context>
<issue_to_address>
**Mirror primary selection is lost**

When a saved mirror config is found by UUID fallback because its saved name differs from the connected monitor’s name, `getByUuidAndName` returns the UUID match, but `setPrimaryByUuidAndName` requires an exact UUID-and-name match and clears every config’s `Primary` flag. The mirror config loses its inherited primary and falls back to an unintended default primary.

Set the primary flag on the config returned by the UUID-and-name lookup, including when that lookup used its UUID fallback.

Also at `display1/manager.go:1714`.
</issue_to_address>

### Comment 6
<location path="display1/duplicate_uuid_test.go" line_range="74" />
<code_context>
+	edid := bytes.Repeat([]byte{0x78}, 128)
+	seen := make(map[string]string)
+	for _, connector := range []string{"DP-1", "DP-2", "DP-3", "DP-4"} {
+		uuid := getOutputUuid(connector, connector, edid)
+		if other, ok := seen[uuid]; ok {
+			t.Fatalf("connector %s and %s got the same UUID %s", other, connector, uuid)
</code_context>
<issue_to_address>
**Standard names are not verified**

When `getOutputUuid` uses the output name instead of the standard name for a valid EDID, testGetOutputUuidIdenticalEdidUsesDistinctStdNames passes the connector as both `name` and `stdName` on line 74, so `getOutputUuid` can ignore `stdName` and still produce distinct UUIDs from the distinct connector names; the test misses that regression.

Pass differing output and standard names, then assert the UUIDs reflect the standard names.
</issue_to_address>

### Comment 7
<location path="display1/duplicate_uuid_test.go" line_range="149" />
<code_context>
+	if got := monitors.GetByUuidAndNameOrUuid("duplicate-uuid", "DP-2"); got == nil || got.Name != "DP-2" {
+		t.Fatalf("GetByUuidAndNameOrUuid returned %+v, want DP-2", got)
+	}
+	if got := monitors.GetByUuidAndNameOrUuid("duplicate-uuid", "DP-9"); got == nil {
+		t.Fatal("GetByUuidAndNameOrUuid should fall back to UUID for unknown name")
+	}
</code_context>
<issue_to_address>
**Wrong duplicate fallback passes**

When the requested name is unknown and multiple monitors share the UUID, testMonitorsGetByUuidAndNameOrUuid only checks for non-nil on line 149, so returning the wrong monitor when the name is unknown and UUIDs are duplicated still passes; the compatibility fallback can select the wrong display.

Assert that the duplicate-UUID fallback returns the same monitor as the existing UUID-only lookup.
</issue_to_address>

### Comment 8
<location path="display1/duplicate_uuid_test.go" line_range="111" />
<code_context>
+		t.Fatal("getByUuidAndName should fall back to UUID for unknown name")
+	}
+
+	cfgs.setPrimaryByUuidAndName(uuid, "DP-2")
+	primaryCount := 0
+	for _, cfg := range cfgs {
</code_context>
<issue_to_address>
**Stale primary flags go undetected**

When a different config is already marked primary before selection, testSysMonitorConfigsGetByUuidAndName initializes every config with `Primary` false (lines 84–89), so an implementation that sets DP-2 primary but fails to clear an existing primary passes the count check at lines 113–123; callers can end up with multiple primary configs.

Initialize another config as primary before selection and assert that only DP-2 remains primary.
</issue_to_address>

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

Comment thread display1/util.go Resolved
Comment thread display1/util.go Resolved
Comment thread display1/manager.go Resolved
Comment thread display1/displayconf.go Resolved
Comment thread display1/displayconf.go Resolved
Comment thread display1/duplicate_uuid_test.go Resolved
Comment thread display1/duplicate_uuid_test.go Resolved
Comment thread display1/duplicate_uuid_test.go Resolved
@Ivy233
Ivy233 marked this pull request as draft November 10, 2026 07:53
@Ivy233

Ivy233 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

该PR暂时不合入,因为显示器EDID完全一致的情况,可能从驱动入手会更好一些,而不是在daemon侧做兼容。

@Ivy233
Ivy233 force-pushed the fix/display-duplicate-edid-uuid branch from 4c853bd to 6c13a2a Compare December 1, 2026 03:43
…ayouts

Generate display UUIDs from a per-refresh view of the current topology. All
connected X outputs are resolved against a freshly read DRM connector list,
so identical-EDID monitors no longer share a UUID and the result cannot
depend on hotplug or daemon-restart history. Only outputs that really share
a (stdName, EDID fingerprint) pair fall back to their X output name, exact
port-name matches keep the legacy UUID, and a single monitor keeps its
@connector UUID even when several connectors report the same EDID.

Migrate legacy screens configs that were saved with duplicate UUIDs instead
of resetting the user's layout. The migration matches the old UUIDs to the
current monitors by the EDID fingerprint embedded in each UUID and by the
saved output names; it rewrites the screen key, per-monitor UUIDs, OnlyOne
entries and fill-mode keys, and refuses to migrate when counts or names are
ambiguous.

Add regression tests for hotplug/restart stability, monitor replacement,
single-monitor multi-connector and duplicate-connector-name cases,
randomized topology properties, and legacy duplicate-UUID config migration.

Log: Identical-EDID monitors keep independent layouts across hotplug and daemon restart, and existing layouts are migrated instead of reset.
Influence:
1. Identical-EDID monitors receive unique UUIDs; a given topology keeps the same UUIDs across hotplug and daemon restarts.
2. A single monitor keeps its legacy UUID even when several DRM connectors report the same EDID.
3. Screens configs saved with duplicate UUIDs are migrated to the new UUIDs when the monitor set and names are unambiguous.

fix(display): 保证同 EDID 显示器身份稳定并迁移旧布局

每轮刷新基于当前拓扑重新解析所有 X 输出的标准 connector 名,相同 EDID 的
显示器不再共享 UUID,判定结果也不再依赖热插或 daemon 重启历史。仅当多个
输出确实共享 (标准名, EDID 指纹) 时才回退到 X output 名;端口名精确匹配的
输出保留旧 UUID;只有一台显示器时,即使多个 connector 报告同一 EDID 也保留
@connector 形式的旧 UUID。

新增旧配置迁移:对历史上因重复 UUID 而无法命中的 Screens 配置,按 UUID 中
携带的 EDID 指纹和配置里的输出名映射到当前显示器,重写屏幕 key、各显示器
UUID、OnlyOne 条目和填充模式 key;数量或名称无法唯一确定时放弃迁移,避免
把布局写到错误的显示器,也避免升级后布局被整体重置。

补充热插/重启稳定性、换接显示器、单屏多 connector、跨卡同名 connector、
随机拓扑属性以及旧重复 UUID 配置迁移的回归测试。

Log: 相同 EDID 显示器在热插和重启后保持独立布局,旧布局会迁移而不是重置。
Influence:
1. 相同 EDID 显示器获得唯一 UUID,同一拓扑在热插和重启后 UUID 不变。
2. 单屏在多个 connector 报告同一 EDID 时保留旧 UUID。
3. 重复 UUID 的旧屏幕配置在显示器集合与名称可唯一确定时迁移到新 UUID。

PMS: BUG-382483
@Ivy233
Ivy233 force-pushed the fix/display-duplicate-edid-uuid branch from a9a65cf to 926a02e Compare December 1, 2026 13:24
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