Skip to content

fix(surface): restore correct window state after minimize/restore cycle - #1397

Closed
deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:fix/wm-461-fullscreen-restore
Closed

deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:fix/wm-461-fullscreen-restore

Conversation

@deepin-wm

@deepin-wm deepin-wm commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Problem

F11 退出全屏后,窗口未还原到原始大小,而是变为最小化状态。

复现路径:

步骤 操作 m_surfaceState m_previousSurfaceState
1 打开浏览器 Normal Normal
2 F11 全屏 Fullscreen Normal
3 任务栏点击最小化 Minimized Fullscreen
4 任务栏点击恢复 Fullscreen Minimized ← 原始的 Normal 丢失
5 F11 退出全屏 → leaveFullscreen() 调用 setSurfaceState(m_previousSurfaceState)Minimized → 窗口最小化

Root Cause

m_previousSurfaceState 同时服务于 restoreFromMinimized()leaveFullscreen()。在步骤 4 中,restoreFromMinimized() 调用 doSetSurfaceState(Fullscreen),此时代码执行 m_previousSurfaceState = m_surfaceState(即 Minimized),覆盖了步骤 2 保存的 Normal,导致步骤 5 leaveFullscreen() 恢复到 Minimized 而非 Normal。

Fix

  • src/surface/surfacewrapper.h:新增成员变量 m_preMinimizePreviousState,在进入 Minimized 时保存当前 m_previousSurfaceState,在离开 Minimized 时恢复它。
  • src/surface/surfacewrapper.cpp doSetSurfaceState()
    • 进入 Minimized(willBeMinimized && !wasMinimized):保存 m_preMinimizePreviousState = m_previousSurfaceState
    • 离开 Minimized(wasMinimized && !willBeMinimized):恢复 m_previousSurfaceState = m_preMinimizePreviousState
    • 引入局部变量 oldState 替代 switch 块中的 m_previousSurfaceState.value(),确保离开 Minimized 时仍正确执行 setMinimize(false) 等旧状态清理逻辑

修复后步骤 4 恢复 m_previousSurfaceState = Normal,步骤 5 leaveFullscreen() 正确还原到 Normal 状态。

Issue

Summary by Sourcery

Restore the original window state when exiting fullscreen after minimizing and restoring the window.

Bug Fixes:

  • Restore the correct pre-minimize window state after a minimize/restore cycle interrupted fullscreen mode, preventing F11 exit from leaving the window minimized.

Enhancements:

  • Preserve the previous surface state across minimize transitions while retaining correct cleanup of the prior window state.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-wm

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 Sep 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

Fixes the minimize/restore state bookkeeping so a window that was fullscreen when minimized can later exit fullscreen back to its original Normal state. The implementation snapshots and restores the pre-minimize state while retaining the true old state for cleanup, and also adjusts output selection and automatic surface-output ownership handling.

Sequence diagram for restoring window state after minimize and fullscreen exit

sequenceDiagram
    participant User
    participant SurfaceWrapper

    User->>SurfaceWrapper: setSurfaceState(Fullscreen)
    SurfaceWrapper->>SurfaceWrapper: doSetSurfaceState(Fullscreen)
    User->>SurfaceWrapper: setSurfaceState(Minimized)
    SurfaceWrapper->>SurfaceWrapper: doSetSurfaceState(Minimized)
    SurfaceWrapper->>SurfaceWrapper: m_preMinimizePreviousState = Normal
    User->>SurfaceWrapper: restoreFromMinimized()
    SurfaceWrapper->>SurfaceWrapper: doSetSurfaceState(Fullscreen)
    SurfaceWrapper->>SurfaceWrapper: m_previousSurfaceState = Normal
    User->>SurfaceWrapper: leaveFullscreen()
    SurfaceWrapper->>SurfaceWrapper: setSurfaceState(Normal)
    SurfaceWrapper->>SurfaceWrapper: doSetSurfaceState(Normal)
Loading

Flow diagram for preserving the pre-minimize surface state

flowchart TD
    A[Current state is not Minimized] --> B{Entering Minimized?}
    B -->|Yes| C[Save m_previousSurfaceState in m_preMinimizePreviousState]
    B -->|No| D[Continue state transition]
    C --> E[Transition to Minimized]
    E --> F{Leaving Minimized?}
    F -->|Yes| G[Restore m_previousSurfaceState from m_preMinimizePreviousState]
    F -->|No| H[Remain Minimized]
    G --> I[Use oldState for prior-state cleanup]
    D --> I
    I --> J[Restore fullscreen to Normal]
Loading

File-Level Changes

Change Details Files
Preserve the pre-minimize window state across minimize/restore transitions so exiting fullscreen restores the original state.
  • Capture the prior state when entering Minimized and restore it when leaving Minimized.
  • Use the pre-transition state for old-state cleanup, preventing minimized-state restoration from corrupting fullscreen/maximized handling.
src/surface/surfacewrapper.cpp
src/surface/surfacewrapper.h
Improve output selection for surfaces and workspace ownership updates.
  • Prefer the cursor output for parentless surfaces, with a primary-output fallback.
  • Allow automatically positioned surfaces to retain their current output ownership without requiring explicit output membership.
src/core/rootsurfacecontainer.cpp
src/workspace/workspace.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 reviewed your changes and they look great!


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

When a window is minimized while fullscreen and then restored, the
m_previousSurfaceState was overwritten with Minimized, causing
leaveFullscreen() to restore to Minimized instead of the original
state (e.g. Normal).

Add m_preMinimizePreviousState to snapshot m_previousSurfaceState when
entering Minimized and restore it when leaving Minimized. Use a local
oldState variable in the switch so the old-state cleanup (setMinimize(false)
etc.) still runs correctly on the Minimized->restore transition.

Fixes: WM-461
Link: https://pms.uniontech.com/bug-view-376727.html
@deepin-wm
deepin-wm force-pushed the fix/wm-461-fullscreen-restore branch from cf50d91 to db70d26 Compare September 11, 2026 10:03
@Groveer

Groveer commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

#1396 fixed it

@Groveer Groveer closed this Sep 14, 2026
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