Skip to content

fix: preserve display settings across lid transitions - #1332

Merged
xujin177 merged 1 commit into
linuxdeepin:masterfrom
xujin177:master
Dec 2, 2026
Merged

xujin177 merged 1 commit into
linuxdeepin:masterfrom
xujin177:master

Conversation

@xujin177

@xujin177 xujin177 commented Dec 2, 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
(cherry picked from commit 5bf9eb0)

Summary by Sourcery

Preserve external and builtin display settings when the lid closes or opens.

Bug Fixes:

  • Initialize external display defaults when closing the lid from a builtin-only setup, and restore saved per-display scaling and the builtin display’s scale when reopening.
  • Preserve confirmed closed-lid display settings across lid cycles and daemon restarts instead of resetting them.

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
(cherry picked from commit 5bf9eb0)
@sourcery-ai

sourcery-ai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Add persisted lid-scale state to the user configuration and a flag marking closed-lid single-display settings as confirmed, preserving both through UUID updates and clones.

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

Implementation

Coordinate lid transitions with display configuration application so saved closed-lid settings are reused, defaults do not overwrite confirmed settings, and per-display scale is saved or restored at the appropriate transition.

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

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

## Individual Comments

### Comment 1
<location path="display1/manager_lid.go" line_range="257" />
<code_context>
+		// 仅首次使用该外屏时计算默认值,之后优先恢复用户保存的值。
+		target = map[string]float64{"ALL": scale.GetRecommendedScaleFactor(m.xConn)}
+	}
+	state.ExternalUUID = external.uuid
+	if err := m.saveUserConfigNoLock(); err != nil {
+		state.ExternalUUID = ""
</code_context>
<issue_to_address>
**External display keeps wrong scale**

When the daemon stops after saving `ExternalUUID` but before applying the external scale, or `SetScreenScaleFactors` fails, `applyLidScale` saves `ExternalUUID` before the scale change succeeds, so a later call takes the matching-UUID branch, clears `lidScalePending`, and skips the retry. The external display keeps the wrong scale.

Only treat `ExternalUUID` as proof that the external scale is active after the scale change succeeds.

Also at `display1/manager_lid.go:212`, `display1/manager_lid.go:237-240`, `display1/manager_lid.go:251`, `display1/manager_lid.go:263`.
</issue_to_address>

### Comment 2
<location path="display1/manager_lid.go" line_range="251" />
<code_context>
+		state = &LidScaleConfig{Factors: make(map[string]map[string]float64)}
+		m.userConfig.LidScale = state
+	}
+	state.Factors[builtin.uuid] = factors
+	target := state.Factors[external.uuid]
+	if len(target) == 0 {
</code_context>
<issue_to_address>
**Lid transition crashes the daemon**

When the user config contains a `LidScale` object with `Factors` omitted or null, `applyLidScale` assigns into `state.Factors` while the map is nil, causing a panic during the lid transition and terminating the daemon.

Initialize `state.Factors` when loading or creating a `LidScaleConfig` if it is nil.

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

### Comment 3
<location path="display1/manager_lid.go" line_range="217-218" />
<code_context>
+			logger.Warning("failed to restore builtin scale after lid open:", err)
+			return
+		}
+		state.ExternalUUID = ""
+		if err := m.saveUserConfigNoLock(); err != nil {
+			logger.Warning("failed to save lid scale config:", err)
+		}
</code_context>
<issue_to_address>
**Saved external scale gets overwritten**

When saving user configuration fails after restoring builtin scaling on lid open, `applyLidScale` clears `ExternalUUID` in memory, but the saved config retains the old external UUID. A later lid-open apply treats the builtin factors as the external scale and overwrites the saved external factors, so the next lid close restores the wrong scale.

Handle a failed config save so later applies cannot treat the restored builtin scale as the external scale.
</issue_to_address>

### Comment 4
<location path="display1/manager_lid.go" line_range="212" />
<code_context>
+			logger.Warning("failed to read external scale before lid open:", err)
+			return
+		}
+		state.Factors[state.ExternalUUID] = factors
+		if err := m.xsManager.SetScreenScaleFactors(0, state.Factors[builtin.uuid]); err != nil {
+			logger.Warning("failed to restore builtin scale after lid open:", err)
</code_context>
<issue_to_address>
**Wrong display scale overwrites saved settings**

When the external display named by `state.ExternalUUID` is disconnected while the lid is closed before the lid is reopened, `applyLidScale` stores the current screen factors under `state.ExternalUUID` without checking that this display is still connected and active. If the external display is unplugged while the lid is closed, reopening captures the builtin display’s factors and overwrites the unplugged display’s saved scale; reconnecting it later restores the wrong scale.

Before saving current factors under `ExternalUUID`, verify that the corresponding external display is active; otherwise preserve its saved factors and only restore the builtin scale.
</issue_to_address>

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

When the lid closes with multiple enabled external displays and a resolution-change event occurs before it opens, `applyLidScale` returns without clearing `lidScalePending`, so `tryToChangeScaleFactor` skips automatic scale adjustments while the lid remains closed. External displays keep an unsuitable scale.

Clear `lidScalePending` before returning for multiple enabled external displays.

Also at `display1/manager_lid.go:229-230`, `display1/manager.go:3891-3893`.
</issue_to_address>

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

Comment thread display1/manager_lid.go
// 仅首次使用该外屏时计算默认值,之后优先恢复用户保存的值。
target = map[string]float64{"ALL": scale.GetRecommendedScaleFactor(m.xConn)}
}
state.ExternalUUID = external.uuid

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · External display keeps wrong scale

When the daemon stops after saving ExternalUUID but before applying the external scale, or SetScreenScaleFactors fails, applyLidScale saves ExternalUUID before the scale change succeeds, so a later call takes the matching-UUID branch, clears lidScalePending, and skips the retry. The external display keeps the wrong scale.

Only treat ExternalUUID as proof that the external scale is active after the scale change succeeds.

Also at display1/manager_lid.go:212, display1/manager_lid.go:237-240, display1/manager_lid.go:251, display1/manager_lid.go:263.

Prompt for AI agents
In `display1/manager_lid.go` at line 257:

**External display keeps wrong scale**

When the daemon stops after saving `ExternalUUID` but before applying the external scale, or `SetScreenScaleFactors` fails, `applyLidScale` saves `ExternalUUID` before the scale change succeeds, so a later call takes the matching-UUID branch, clears `lidScalePending`, and skips the retry. The external display keeps the wrong scale.

Only treat `ExternalUUID` as proof that the external scale is active after the scale change succeeds.

Also at `display1/manager_lid.go:212`, `display1/manager_lid.go:237-240`, `display1/manager_lid.go:251`, `display1/manager_lid.go:263`.

Comment thread display1/manager_lid.go
state = &LidScaleConfig{Factors: make(map[string]map[string]float64)}
m.userConfig.LidScale = state
}
state.Factors[builtin.uuid] = factors

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 · Lid transition crashes the daemon

When the user config contains a LidScale object with Factors omitted or null, applyLidScale assigns into state.Factors while the map is nil, causing a panic during the lid transition and terminating the daemon.

Initialize state.Factors when loading or creating a LidScaleConfig if it is nil.

Also at display1/manager_lid.go:212.

Prompt for AI agents
In `display1/manager_lid.go` at line 251:

**Lid transition crashes the daemon**

When the user config contains a `LidScale` object with `Factors` omitted or null, `applyLidScale` assigns into `state.Factors` while the map is nil, causing a panic during the lid transition and terminating the daemon.

Initialize `state.Factors` when loading or creating a `LidScaleConfig` if it is nil.

Also at `display1/manager_lid.go:212`.

Comment thread display1/manager_lid.go
Comment on lines +217 to +218
state.ExternalUUID = ""
if err := m.saveUserConfigNoLock(); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Saved external scale gets overwritten

When saving user configuration fails after restoring builtin scaling on lid open, applyLidScale clears ExternalUUID in memory, but the saved config retains the old external UUID. A later lid-open apply treats the builtin factors as the external scale and overwrites the saved external factors, so the next lid close restores the wrong scale.

Handle a failed config save so later applies cannot treat the restored builtin scale as the external scale.

Prompt for AI agents
In `display1/manager_lid.go` at lines 217-218:

**Saved external scale gets overwritten**

When saving user configuration fails after restoring builtin scaling on lid open, `applyLidScale` clears `ExternalUUID` in memory, but the saved config retains the old external UUID. A later lid-open apply treats the builtin factors as the external scale and overwrites the saved external factors, so the next lid close restores the wrong scale.

Handle a failed config save so later applies cannot treat the restored builtin scale as the external scale.

Comment thread display1/manager_lid.go
logger.Warning("failed to read external scale before lid open:", err)
return
}
state.Factors[state.ExternalUUID] = factors

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Wrong display scale overwrites saved settings

When the external display named by state.ExternalUUID is disconnected while the lid is closed before the lid is reopened, applyLidScale stores the current screen factors under state.ExternalUUID without checking that this display is still connected and active. If the external display is unplugged while the lid is closed, reopening captures the builtin display’s factors and overwrites the unplugged display’s saved scale; reconnecting it later restores the wrong scale.

Before saving current factors under ExternalUUID, verify that the corresponding external display is active; otherwise preserve its saved factors and only restore the builtin scale.

Prompt for AI agents
In `display1/manager_lid.go` at line 212:

**Wrong display scale overwrites saved settings**

When the external display named by `state.ExternalUUID` is disconnected while the lid is closed before the lid is reopened, `applyLidScale` stores the current screen factors under `state.ExternalUUID` without checking that this display is still connected and active. If the external display is unplugged while the lid is closed, reopening captures the builtin display’s factors and overwrites the unplugged display’s saved scale; reconnecting it later restores the wrong scale.

Before saving current factors under `ExternalUUID`, verify that the corresponding external display is active; otherwise preserve its saved factors and only restore the builtin scale.

Comment thread display1/manager_lid.go
var external *Monitor
for _, monitor := range monitorMap {
if monitor.ID != builtin.ID && monitor.realConnected && monitor.Enabled {
if external != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Automatic scaling stops for multiple displays

When the lid closes with multiple enabled external displays and a resolution-change event occurs before it opens, applyLidScale returns without clearing lidScalePending, so tryToChangeScaleFactor skips automatic scale adjustments while the lid remains closed. External displays keep an unsuitable scale.

Clear lidScalePending before returning for multiple enabled external displays.

Also at display1/manager_lid.go:229-230, display1/manager.go:3891-3893.

Prompt for AI agents
In `display1/manager_lid.go` at line 228:

**Automatic scaling stops for multiple displays**

When the lid closes with multiple enabled external displays and a resolution-change event occurs before it opens, `applyLidScale` returns without clearing `lidScalePending`, so `tryToChangeScaleFactor` skips automatic scale adjustments while the lid remains closed. External displays keep an unsuitable scale.

Clear `lidScalePending` before returning for multiple enabled external displays.

Also at `display1/manager_lid.go:229-230`, `display1/manager.go:3891-3893`.

@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 2c02ff5 into linuxdeepin:master Dec 2, 2026
17 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