Skip to content

fix: preserve display settings across lid transitions - #1327

Merged
xujin177 merged 1 commit into
linuxdeepin:release/2500u2-pajilfrom
xujin177:fix/lid-scale-code-review
Dec 1, 2026
Merged

xujin177 merged 1 commit into
linuxdeepin:release/2500u2-pajilfrom
xujin177:fix/lid-scale-code-review

Conversation

@xujin177

@xujin177 xujin177 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor
  1. Initialize external display defaults when closing a builtin-only setup.
  2. Remember per-display scaling and restore builtin scaling on lid open.
  3. Preserve confirmed closed-lid settings across cycles and service restarts.

Log: Fix external display initialization and closed-lid settings recovery.
PMS: BUG-383753

Influence:

  1. Close a builtin-only setup and check external resolution, rotation and scale.
  2. Save an external resolution, reopen and close the lid, then check recovery.
  3. Restart the daemon with the lid closed and verify saved display settings.

fix: 修复开合盖时外屏初始化及显示配置恢复

  1. 仅内屏模式下合盖时初始化外屏默认显示参数。
  2. 按显示器记忆缩放,开盖时恢复内屏原有缩放。
  3. 保留合盖时确认保存的配置,避免反复开合盖或重启服务后重置。

Influence:

  1. 仅内屏模式下合盖,检查外屏分辨率、方向和缩放初始化。
  2. 保存外屏分辨率后反复开合盖,检查配置恢复和内屏状态。
  3. 合盖时重启 daemon,检查已保存显示参数是否保持。

Log: 修复合盖外屏初始化异常及已保存显示配置无法恢复的问题。
PMS: BUG-383753

Summary by Sourcery

Preserve display configuration when closing and opening the lid, including external display initialization and saved scaling.

Bug Fixes:

  • Initialize external display resolution, rotation, and scaling when closing the lid from an internal-display-only setup.
  • Restore each display’s saved scaling when switching between the built-in display and an external display.
  • Preserve confirmed closed-lid display settings across lid cycles and daemon restarts.

@sourcery-ai

sourcery-ai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Add persisted per-display lid-scaling state and a flag that distinguishes confirmed closed-lid configurations from defaults.

  • display1/displayconf.go L53-61, L490-494 (+2 small edits)

Implementation

Coordinate lid-transition display initialization, configuration preservation, and per-display scale saving and restoration.

  • display1/manager.go L1080-1102, L2398-2405, L3890-3904 (+4 small edits)
  • display1/manager_lid.go L10, L82-95, L159-269

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

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

## Individual Comments

### Comment 1
<location path="display1/displayconf.go" line_range="60" />
<code_context>
+
+// 缩放仍由 XSettings 生效,这里只保存开合盖切换时各显示器的配置。
+type LidScaleConfig struct {
+	Factors      map[string]map[string]float64 // 显示器 UUID -> 原有缩放映射
+	ExternalUUID string                        `json:",omitempty"` // 尚未切回内屏的外屏
 }
</code_context>
<issue_to_address>
**Lid transition crashes on missing factors**

When the user config has a non-nil `LidScale` with omitted or null `Factors`, `applyLidScale` assigns to `state.Factors` without initializing the map, so the lid transition panics and terminates the daemon.

Initialize `LidScale.Factors` when loading or fixing user config, and guard the assignment in `applyLidScale`.

Also at `display1/manager_lid.go:209`, `display1/manager_lid.go:248`.
</issue_to_address>

### Comment 2
<location path="display1/manager_lid.go" line_range="236" />
<code_context>
+	}
+	if state != nil && state.ExternalUUID == external.uuid {
+		// 合盖期间重启服务时,当前值已经属于外屏,不能拿它覆盖内屏记录。
+		m.lidScalePending = false
+		return
+	}
</code_context>
<issue_to_address>
**Failed external scale is not retried**

When the daemon stops before applying the external scale or `SetScreenScaleFactors` fails after `ExternalUUID` is saved, the next `applyLidScale` takes the matching-UUID branch, clears `lidScalePending`, and skips setting the scale; the external display remains at the wrong scale.

Make the matching-UUID path retry `SetScreenScaleFactors` while the scale is pending, and clear the pending flag only after the setting succeeds.

Also at `display1/manager_lid.go:254-263`.
</issue_to_address>

### Comment 3
<location path="display1/manager_lid.go" line_range="202" />
<code_context>
+	m.userCfgMu.Lock()
+	defer m.userCfgMu.Unlock()
+	state := m.userConfig.LidScale
+	if !builtin.lidClosed && builtin.Enabled && state != nil && state.ExternalUUID != "" {
+		// 切回内屏前保存外屏最后使用的值,不能下次合盖又重置为默认值。
+		factors, err := m.xsManager.GetScreenScaleFactors(0)
</code_context>
<issue_to_address>
**Disconnected display loses remembered scale**

When the external display recorded in `ExternalUUID` is disconnected while the lid is closed, `applyLidScale` reads the builtin display’s current factors and stores them under the disconnected external display’s UUID, overwriting its remembered scale.

Verify that the recorded external display is still connected and active before saving current factors under its UUID.

Also at `display1/manager_lid.go:209`.
</issue_to_address>

### Comment 4
<location path="display1/displayconf.go" line_range="60" />
<code_context>
+
+// 缩放仍由 XSettings 生效,这里只保存开合盖切换时各显示器的配置。
+type LidScaleConfig struct {
+	Factors      map[string]map[string]float64 // 显示器 UUID -> 原有缩放映射
+	ExternalUUID string                        `json:",omitempty"` // 尚未切回内屏的外屏
 }
</code_context>
<issue_to_address>
**UUID migration loses saved scales**

When a monitor UUID changes while lid-scale state for its previous UUID is persisted, `UserConfig.updateUuid` migrates only `Screens`, leaving `LidScale.Factors` and `ExternalUUID` at the old UUID; `applyLidScale` misses the saved factors and uses the recommended default scale.

Migrate the UUID keys in `LidScale.Factors` and the value of `LidScale.ExternalUUID` along with `Screens`.

Also at `display1/displayconf.go:61`.
</issue_to_address>

### Comment 5
<location path="display1/manager_lid.go" line_range="226" />
<code_context>
+	for _, monitor := range monitorMap {
+		if monitor.ID != builtin.ID && monitor.realConnected && monitor.Enabled {
+			if external != nil {
+				return // 多外屏组合沿用原有逻辑,不擅自套用单外屏的缩放。
+			}
+			external = monitor
</code_context>
<issue_to_address>
**Multiple displays leave scaling pending**

When more than one enabled external display is present during the lid-close apply, `applyLidScale` returns without clearing `lidScalePending`, so later resolution changes are ignored and a subsequent single-external setup can be treated as the original lid transition.

Clear or otherwise reset `lidScalePending` before returning for multiple enabled external displays.
</issue_to_address>

### Comment 6
<location path="display1/manager_lid.go" line_range="249" />
<code_context>
+		m.userConfig.LidScale = state
+	}
+	state.Factors[builtin.uuid] = factors
+	target := state.Factors[external.uuid]
+	if len(target) == 0 {
+		// 仅首次使用该外屏时计算默认值,之后优先恢复用户保存的值。
</code_context>
<issue_to_address>
**External scale changes are forgotten**

When the user changes the external display's scale while the lid is open, then selects builtin-only before closing the lid, `applyLidScale` reads the external target from the cached `state.Factors` map and reapplies that value on lid close, but it only refreshes the cache during the lid-open transition. A later user scale change while the external display is active is therefore overwritten by the older cached value on the next close.

Refresh the per-display factor cache when the active display's scale changes, or read and save the external factors before switching away from that display.
</issue_to_address>

### Comment 7
<location path="display1/manager.go" line_range="2403" />
<code_context>
+			closed := builtin.lidClosed
+			builtin.PropsMu.RUnlock()
+			if closed {
+				screenCfg.LidClosedConfigured = true
+			}
+		}
</code_context>
<issue_to_address>
**Confirmed closed-lid settings are missed**

When the user confirms external-only settings while the builtin display is lid-closed and the daemon restarts before the lid opens, `save` stores the confirmed external-only `Single` config under the active monitor ID, which excludes the closed builtin monitor. After restart, `getLidClosedSingleConfig` looks it up using the physical monitor ID including the builtin, misses both the saved config and its confirmation flag, and applies defaults instead of the user's settings.

Persist and look up the confirmed closed-lid config under the same monitor-set key, or add a fallback that retrieves it from the external-only key.
</issue_to_address>

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

Comment thread display1/displayconf.go Resolved
Comment thread display1/manager_lid.go Resolved
Comment thread display1/manager_lid.go Resolved
Comment thread display1/displayconf.go Resolved
Comment thread display1/manager_lid.go Resolved
Comment thread display1/manager_lid.go Resolved
Comment thread display1/manager.go Resolved
1. Initialize external display defaults when closing a builtin-only setup.
2. Remember per-display scaling and restore builtin scaling on lid open.
3. Preserve confirmed closed-lid settings across cycles and service restarts.

Log: Fix external display initialization and closed-lid settings recovery.
PMS: BUG-383753

Influence:
1. Close a builtin-only setup and check external resolution, rotation and scale.
2. Save an external resolution, reopen and close the lid, then check recovery.
3. Restart the daemon with the lid closed and verify saved display settings.

fix: 修复开合盖时外屏初始化及显示配置恢复

1. 仅内屏模式下合盖时初始化外屏默认显示参数。
2. 按显示器记忆缩放,开盖时恢复内屏原有缩放。
3. 保留合盖时确认保存的配置,避免反复开合盖或重启服务后重置。

Influence:
1. 仅内屏模式下合盖,检查外屏分辨率、方向和缩放初始化。
2. 保存外屏分辨率后反复开合盖,检查配置恢复和内屏状态。
3. 合盖时重启 daemon,检查已保存显示参数是否保持。

Log: 修复合盖外屏初始化异常及已保存显示配置无法恢复的问题。
PMS: BUG-383753
@xujin177
xujin177 force-pushed the fix/lid-scale-code-review branch from 4c7ecbb to 40db4e6 Compare December 1, 2026 13:01
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy, xujin177

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

@xujin177
xujin177 merged commit 5bf9eb0 into linuxdeepin:release/2500u2-pajil Dec 1, 2026
16 of 19 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