Skip to content

wayland: share window setup, handle the parent window - #4819

Merged
ogoffart merged 9 commits into
rust-windowing:masterfrom
Murmele:mm/window-weak
Nov 11, 2026
Merged

ogoffart merged 9 commits into
rust-windowing:masterfrom
Murmele:mm/window-weak

Conversation

@Murmele

@Murmele Murmele commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

This was pulled out from the #4627 branch

I had to replace the weak pointer again by a strong Arc. The problem is that we are exposing raw pointers and surfaces to the user application so when winit destroys the surface but used by glutin / wgpu it has a dangling pointer.
So now every child holds a strong pointer to the parent to ensure that a parent can only be deleted when the child was destroyed before.
The parent holds only the id to the child to prevent a circular dependency

  • Tested on all platforms changed
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

… weak state

Move the setup of a `Window` into `Window::setup`, and the registration
with the event loop plus the wait for the initial configure into
`finish_window_setup`, which `Popup` now uses as well. When the compositor
dismisses the surface before the initial configure, `finish_window_setup`
also removes it from the event loop again. A popup is now only added as a
child of its parent once its setup succeeded.

Move the handling of an `xdg_toplevel` configure into
`WinitState::configure_xdg_toplevel` and rename
`WindowState::configure_window` to `configure_xdg_toplevel`, so that other
`xdg_toplevel`-based surfaces can share them.

A window created with a parent window now calls `xdg_toplevel.set_parent`
with that parent and is registered as its child, so it is closed together
with its parent. A parent that is not a Wayland window, not a window of
the same event loop, or a popup is now an error instead of being ignored.

`Window` now only holds a `Weak` to its state, like `Popup`. The event
loop owns the state, and with it the SCTK window and its surface, so a
window closed together with its parent is actually destroyed, even while
the application still holds its handle. Because of that,
`Window::surface()` now returns `Option<WlSurface>`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Murmele
Murmele requested a review from kchibisov as a code owner November 6, 2026 09:55
@Murmele
Murmele marked this pull request as draft November 6, 2026 10:00
@Murmele
Murmele marked this pull request as ready for review November 6, 2026 13:14
@Murmele Murmele changed the title wayland: share window setup, handle the parent window and hold only a weak state wayland: share window setup, handle the parent window Nov 11, 2026
@ogoffart
ogoffart merged commit 6d0e541 into rust-windowing:master Nov 11, 2026
53 checks passed
joeleaver pushed a commit to joeleaver/winit-fork that referenced this pull request Nov 12, 2026
…#4819)

Move the setup of a `Window` into `Window::setup`, and the registration
with the event loop plus the wait for the initial configure into
`finish_window_setup`, which `Popup` now uses as well. When the compositor
dismisses the surface before the initial configure, `finish_window_setup`
also removes it from the event loop again. A popup is now only added as a
child of its parent once its setup succeeded.

Move the handling of an `xdg_toplevel` configure into
`WinitState::configure_xdg_toplevel` and rename
`WindowState::configure_window` to `configure_xdg_toplevel`, so that other
`xdg_toplevel`-based surfaces can share them.

A window created with a parent window now calls `xdg_toplevel.set_parent`
with that parent and is registered as its child, so it is closed together
with its parent. A parent that is not a Wayland window, not a window of
the same event loop, or a popup is now an error instead of being ignored.

`Window` now only holds a `Weak` to its state, like `Popup`. The event
loop owns the state, and with it the SCTK window and its surface, so a
window closed together with its parent is actually destroyed, even while
the application still holds its handle. Because of that,
`Window::surface()` now returns `Option<WlSurface>`.
(cherry picked from commit 6d0e541)

Note for rinch-patch-beta4: this squash's message describes an earlier
round of the upstream PR. The code holds the state strongly (`WindowCommon`
keeps an `Arc`, a child keeps its parent), and `Window::surface()` still
returns `&WlSurface`.

Conflicts with the fork's layer-shell role, resolved here:
- `Window::new` picks the role (layer surface or xdg-toplevel) and hands the
  attributes' Wayland part to `Window::setup`, which now sets up either: the
  parent, the app id and the startup mode only where there is an
  `xdg_toplevel`. A layer surface with a parent window is an error
  (`InvalidInput`), since it has no `xdg_toplevel` to give one to.
- `Window` no longer keeps the role object: the state owns it, as upstream's
  window does, so `ShellSurface` goes. `surface_role` reads the state's
  `WindowType`.
- `LayerShellHandler` ignores a configure or close for a window the event
  loop no longer manages, as upstream's handlers now do.
- `configure_xdg_toplevel` refuses a layer surface as it refuses a popup.
- Only this PR's changelog entries are taken.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
joeleaver added a commit to joeleaver/winit-fork that referenced this pull request Nov 12, 2026
The cherry-picked rust-windowing#4819 checks for a surface dismissed
before its first configure with a let chain. Upstream master can use one;
this branch keeps beta.4's rust-version, 1.86, which has none, and CI's 1.86
rows failed on it (E0658). The same check as two ifs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
joeleaver added a commit to joeleaver/winit-fork that referenced this pull request Nov 12, 2026
wayland: popup fixes for rinch: upstream rust-windowing#4819, the grab's press, placement and repositions (rinch#2552)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants