Skip to content

Wayland, Windows, MacOS: Popup Implementation#4543

Open
Murmele wants to merge 40 commits into
rust-windowing:masterfrom
Murmele:popup
Open

Wayland, Windows, MacOS: Popup Implementation#4543
Murmele wants to merge 40 commits into
rust-windowing:masterfrom
Murmele:popup

Conversation

@Murmele

@Murmele Murmele commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Implement proper decorationless popups by specifying the type of the child window with with_type()

With this PR different kind of child windows can be created

  • Popups: Special windows without any decoration which can be positioned relative to the parent
  • Window: Normal window with a parent or not

The type can be specified during creation of the Window using the window_attributes and the with_type() function. As default a normal Window is used. If Popup is choosen a parent must be specified, otherwise the Popup creation fails with an Error returned by the new() function.

Related issues: #403 and #4256

  • 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

Platforms

  • Wayland
    • Testing grabbing
      • Gnome (Mutter)
      • Kde Plasma
  • Windows
  • MacOs
  • X11

Wayland:

Bildschirmaufzeichnung.vom.2026-06-04.13-18-16.mp4

This work is sponsored by the NLnet foundation

@madsmtm madsmtm added DS - wayland Affects the Wayland backend, or generally free Unix platforms S - platform parity Unintended platform differences labels Mar 26, 2026
Comment thread winit-wayland/src/window/state.rs
Comment thread winit-wayland/src/window/state.rs Outdated
@Murmele Murmele marked this pull request as ready for review May 18, 2026 08:06
@Murmele Murmele requested a review from kchibisov as a code owner May 18, 2026 08:06
Comment thread winit-wayland/src/state.rs Outdated
Comment thread winit-wayland/src/state.rs Outdated
Comment thread winit-core/src/window.rs
Comment thread winit-core/src/window.rs Outdated
Comment thread winit-core/src/window.rs Outdated
Comment thread winit-wayland/src/popup.rs Outdated
Comment thread winit-wayland/src/popup.rs Outdated
Comment thread winit-wayland/src/state.rs Outdated
Comment thread winit-wayland/src/popup.rs Outdated
Comment thread winit-win32/src/window.rs
@Murmele Murmele requested a review from madsmtm as a code owner May 28, 2026 15:09
@Murmele Murmele force-pushed the popup branch 2 times, most recently from facdfde to 87f6327 Compare June 4, 2026 12:59
Murmele added 15 commits June 4, 2026 15:07
Reason: Because a normal window can have a parent window as well, like a Dialog
Reason: otherwise the child surface is anchored to the center
Reason: otherwise the height of the client side decoration is not considered and therefore the location is shifted
Reason: There are multiple pointers to the smithay popup. Once in state.windows and one time in the popup object it self. Just dropping the popup object releases only one pointer but we have to notify the state to release also the other
…he position

Reason: Much easier in the resize handle
Reason: we have to call resize to initialize the viewport to map to correct window size
@Murmele Murmele changed the title Wayland: Popup Implementation Wayland, Windows, MacOS: Popup Implementation Jun 4, 2026
Murmele added 2 commits June 18, 2026 14:57
Reason: Because wayland or the event loop could destroy the popup and therefore it is anymore available
@Murmele

Murmele commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

@kchibisov @CryZe @tronical

In 90ebef0 I implemented the correct popup order destroyment. I had the problem that the Popup Item it self contained a window state and therefore it got not delegated to the compositor that the popup shall be deleted. This I fixed in ac4a329 by storing only a Weak pointer of the window state in the Popup struct (popup_state: Weak<Mutex<WindowState>>).
What do you think about instead of returning a Box<dyn Window> returning a Weak pointer. So the event loop basically stores the state popup and the user has only a weak pointer and if the popup was destroyed for some reason (Parent destroyed, ...) then the pointer is invalid and the user is aware that it does not exist anymore?

@kchibisov

Copy link
Copy Markdown
Member

What do you think about instead of returning a Box returning a Weak pointer. So the event loop basically stores the state popup and the user has only a weak pointer and if the popup was destroyed for some reason (Parent destroyed, ...) then the pointer is invalid and the user is aware that it does not exist anymore?

I like that you also came to a conclusion I had for the window storage, as in basically user has some handle but the Window itself is only owned by winit.

I'll think about it a bit since we want to plug it into the current design, but generally, I think that's how it should be, honestly, even though a lot of folks disagree with me on that matter...

@Murmele Murmele closed this Jun 19, 2026
@Murmele Murmele reopened this Jun 19, 2026
@Murmele

Murmele commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

What do you think about instead of returning a Box returning a Weak pointer. So the event loop basically stores the state popup and the user has only a weak pointer and if the popup was destroyed for some reason (Parent destroyed, ...) then the pointer is invalid and the user is aware that it does not exist anymore?

I like that you also came to a conclusion I had for the window storage, as in basically user has some handle but the Window itself is only owned by winit.

I'll think about it a bit since we want to plug it into the current design, but generally, I think that's how it should be, honestly, even though a lot of folks disagree with me on that matter...

Thanks! Just let me know whats your decision here

Comment thread winit-core/src/window.rs Outdated
Comment thread winit/src/changelog/unreleased.md Outdated
mem::drop(window_requests.remove(window_id));
mem::drop(state.windows.get_mut().remove(window_id));
return Some(WindowEvent::Destroyed);
if self.with_state(|state| state.window_requests.get_mut().get(window_id).is_none()) {

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.

Is there a reason why we call with_state several time?
I think this could be simplified maybe.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

decided to keep it as it is for now

Comment thread winit-wayland/src/event_loop/mod.rs Outdated
Comment thread winit-wayland/src/event_loop/mod.rs Outdated
Comment thread winit-win32/src/window.rs
// If we have a popup the position is relative to the parent window and not
// relative to the screen. Therefore we have to translate it from the parent
// coordinate system to the display coordinate system
fn translate_outer_position(&self, position: Position) -> PhysicalPosition<i32> {

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.

Looks like with_position(p) and a later set_outer_position(p) put the popup in two different places. The initial position needs the same translation.

Also outer_position() still returns screen coordinates, so the getter and setter now use different coordinate spaces. Probaly the getter needs to be translated too.

Or the documentation should be cristal clear about this difference. And we need to be somehow consistent across platforms if possible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The initial position for win32 is set using the set_outer_position function:

if let Some(position) = attributes.position {
            win.set_outer_position(position);
}

So that means the translate is done here. I will have a look into for the return value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The outer_position returns now for windows and macOs the position relative to the parent if it is a popup

Comment thread winit-win32/src/window.rs
let parent = match attributes.parent_window() {
Some(rwh_06::RawWindowHandle::Win32(handle)) => {
window_flags.set(WindowFlags::CHILD, true);
if !is_popup {

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.

other platform return an error if there is no parents

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed in 5e3b9f4

Comment thread winit-win32/src/window_state.rs Outdated
Comment thread winit-appkit/src/window_delegate.rs
Comment thread typos.toml Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DS - wayland Affects the Wayland backend, or generally free Unix platforms S - platform parity Unintended platform differences

Development

Successfully merging this pull request may close these issues.

7 participants