Skip to content

fix(remote-subsurface): reattach child subsurface when ancestor is re… - #1375

Merged
zccrs merged 1 commit into
linuxdeepin:masterfrom
wineee:fix-remote-subsurface
Sep 8, 2026
Merged

fix(remote-subsurface): reattach child subsurface when ancestor is re…#1375
zccrs merged 1 commit into
linuxdeepin:masterfrom
wineee:fix-remote-subsurface

Conversation

@wineee

@wineee wineee commented Sep 3, 2026

Copy link
Copy Markdown
Member

…created

Reattach nested remote subsurfaces when recreating an ancestor WSurface wrapper, restoring their position and z-order so they become visible again.

重建祖先 WSurface 包装器时重新挂载嵌套的远程子曲面,恢复其位置和 z 序,使其重新可见。

PMS: TASK-393795

Summary by Sourcery

Ensure nested remote subsurfaces are recreated and reattached when their ancestor surface wrapper is recreated.

Bug Fixes:

  • Restore nested remote subsurfaces after an ancestor WSurface wrapper is recreated, preserving their positions, z-order, and visibility.

Enhancements:

  • Track parent surface mapping at the wlroots surface level so remote subsurface mapping remains valid across WSurface wrapper recreation.

@deepin-ci-robot

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@sourcery-ai

sourcery-ai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Reviewer's Guide

The fix makes remote subsurface contexts resilient to ancestor WSurface wrapper destruction by retaining positions, recreating missing child WSubsurface objects during mapping checks, and restoring their position and z-order so nested subsurfaces become visible again.

Sequence diagram for restoring nested remote subsurfaces

sequenceDiagram
    participant Parent as Ancestor WSurface
    participant Context as RemoteSubsurfaceContext
    participant Manager as WRemoteSubsurfaceManagerV1Private
    participant Child as WSubsurface

    Parent->>Context: recheckMapping()
    Context->>Context: ensureSubsurface()
    alt WSubsurface missing
        Context->>Manager: createRemoteSubsurface(parent, child)
        Manager-->>Context: WSubsurface
        Context->>Child: setPosition(position())
        Context->>Manager: syncRemoteSubsurfaceOrder(parent)
    end
    Context->>Child: recheckMapping()
Loading

File-Level Changes

Change Details Files
Preserve remote subsurface geometry and recreate child wrappers when an ancestor WSurface is rebuilt.
  • Store the latest child position independently of the WSubsurface object.
  • Add lazy recreation of missing WSubsurface instances from the parent and child exported surfaces.
  • Restore the saved position and resynchronize stacking order after recreation.
  • Invoke the recreation check during mapping reevaluation, while retaining existing objects as a fast no-op path.
waylib/src/server/protocols/wremotesubsurfacemanagerv1.cpp

Possibly linked issues

  • #TODO: surface position: PR stores remote subsurface positions and restores them when recreating wrappers, directly implementing position persistence during lifecycle updates.

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

@wineee
wineee marked this pull request as ready for review September 3, 2026 11:37

@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 ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@wineee
wineee marked this pull request as draft September 3, 2026 12:01
@wineee
wineee force-pushed the fix-remote-subsurface branch 4 times, most recently from 5673905 to 6e99cbc Compare September 3, 2026 13:29
@wineee
wineee marked this pull request as ready for review September 4, 2026 02:15

@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 1 issue

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

## Individual Comments

### Comment 1
<location path="waylib/src/server/protocols/wremotesubsurfacemanagerv1.cpp" line_range="651-653" />
<code_context>
     auto *parentWs = wsurfaceFrom(m_parent);
     parentMapped = parentWs  && parentWs->mapped();

+    // ensureSubsurface re-creates this subsurface when the parent WSurface
+    // wrapper was destroyed and recreated.  Fast no-op when it still exists.
+    ensureSubsurface();
+
     bool childHasBuffer = childQw && wlr_surface_has_buffer(childQw);
</code_context>
<issue_to_address>
**issue (bug_risk):** Recreating a non-remote ancestor WSurface does not trigger `recheckMapping()` for its remote children because `trackCommits()` remains connected to the destroyed WSurface wrapper and is never reconnected to the replacement wrapper. Consequently, `ensureSubsurface()` is never called and the child remains detached until some unrelated child or parent event happens.

**Triggers:** When the ancestor is an xdg-toplevel or other non-remote surface whose WSurface wrapper is recreated while the child already has a buffer and no subsequent commit occurs.

**Suggested fix:** Reconnect each affected RemoteSubsurfaceContext to the replacement WSurface's `commit` and `mappedChanged` signals, or explicitly recheck all remote children when a WSurface wrapper is recreated.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread waylib/src/server/protocols/wremotesubsurfacemanagerv1.cpp
@wineee
wineee force-pushed the fix-remote-subsurface branch from 6e99cbc to 5197f3f Compare September 4, 2026 02:31
@wineee
wineee marked this pull request as draft September 4, 2026 02:52
@wineee
wineee marked this pull request as draft September 4, 2026 02:52
@wineee
wineee force-pushed the fix-remote-subsurface branch from 5197f3f to f5b7318 Compare September 8, 2026 08:56
@wineee
wineee marked this pull request as ready for review September 8, 2026 08:57

@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.

Sorry @wineee, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 18 hours and 17 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The change affects low-level Wayland surface lifecycle/mapping behavior and should be validated with runtime scenarios (涉及底层 Wayland 生命周期与映射逻辑,建议人工结合实际场景验证后再合入).

Pull request overview

EN: This PR fixes visibility regressions for nested remote subsurfaces by reattaching (recreating) missing WSubsurface objects when an ancestor WSurface wrapper gets torn down and rebuilt (e.g., role lifecycle changes), while restoring position and z-order so children become visible again.
中文:本 PR 修复了嵌套远程子曲面在祖先 WSurface 包装器被销毁并重建(例如 role 生命周期变化)后不可见的问题:在检测到子曲面对象缺失时重新创建 WSubsurface,并恢复位置与 z 序以确保重新可见。

Changes:

  • EN: Listen to parent wlr_surface commit via WScopedListener so remapping logic survives WSurface wrapper recreation.
    中文:通过 WScopedListener 监听父 wlr_surface 的 commit,使重建 WSurface 包装器后仍能触发重映射检查。
  • EN: Add ensureSubsurface() to recreate missing WSubsurface, restore saved position, and resync remote subsurface ordering.
    中文:新增 ensureSubsurface():在 WSubsurface 缺失时重建、恢复缓存的位置,并重新同步远程子曲面排序。
File summaries
File Description
waylib/src/server/protocols/wremotesubsurfacemanagerv1.cpp EN: Reattach/remap nested remote subsurfaces across WSurface wrapper recreation using wlr_surface commit listeners and on-demand subsurface recreation. 中文:通过监听 wlr_surface commit + 按需重建子曲面,保证 WSurface 包装器重建后嵌套远程子曲面可重新挂载并恢复可见性。
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread waylib/src/server/protocols/wremotesubsurfacemanagerv1.cpp Outdated
@wineee
wineee force-pushed the fix-remote-subsurface branch from 6fb578c to ac21156 Compare September 8, 2026 09:52
…created

When a remote subsurface B is destroyed and recreated, its child C
loses the parent WSubsurface link and never reappears.  The root cause
is that QPointer<WSubsurface> m_subsurface is cleared when the ancestor
WSurface wrapper is destroyed, but nothing re-creates it afterwards.

Fix by adding a m_position cache and an ensureSubsurface() member, and
by tracking the parent surface state at the wlr_surface level:

- Cache the subsurface position in m_position so it survives the
  WSubsurface being destroyed along with the ancestor WSurface wrapper.
- ensureSubsurface() is called on every recheckMapping(); it is a fast
  no-op when the subsurface still exists, and re-creates it otherwise,
  restoring the cached position and z-order.
- Replace WSurface::mappedChanged Qt connections (which break on WSurface
  wrapper recreation) with wlr_surface::events.map / events.unmap
  WScopedListeners.  These live at the wlr_surface level and survive
  role teardown/rebuild, so no reconnection is ever needed.  This
  mirrors the upstream wlroots scene subsurface tree pattern.

重建祖先 WSurface 包装器时重新挂载嵌套的远程子曲面,恢复其位置和 z 序,使其重新可见。

当中间层远程子曲面 B 被销毁后重建时,其子曲面 C 丢失了父 WSubsurface 链接,
导致 C 无法恢复显示。根本原因是祖先 WSurface 包装器被销毁时,持有 WSubsurface
的 QPointer 被清空,但之后没有任何逻辑重建该链接。

修复方案:新增 m_position 位置缓存和 ensureSubsurface() 成员函数,
并在 wlr_surface 层追踪父表面状态:

- 在 m_position 中缓存子曲面位置,使位置在 WSubsurface 随祖先 WSurface
  包装器一同销毁后仍然保留。
- 每次 recheckMapping() 调用 ensureSubsurface(),当 subsurface 仍存在时
  为快速空操作,否则重建 subsurface 并恢复缓存的位置和 z 序。
- 用 wlr_surface::events.map / events.unmap 的 WScopedListener 替代
  WSurface::mappedChanged 的 Qt 连接。后者会随 WSurface 包装器重建而断开,
  前者在 wlr_surface 层存活,无需任何重连逻辑。
  此方案与上游 wlroots scene subsurface tree 模式完全一致。

PMS: TASK-393795
@wineee
wineee force-pushed the fix-remote-subsurface branch from ac21156 to f2ffc21 Compare September 8, 2026 12:19
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: wineee, zccrs

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

@zccrs
zccrs merged commit 423b2ad into linuxdeepin:master Sep 8, 2026
10 checks passed
@wineee
wineee deleted the fix-remote-subsurface branch September 8, 2026 13:07
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.

5 participants