Skip to content

Popup: Set correct window adapter for the component#11352

Open
Murmele wants to merge 17 commits intoslint-ui:masterfrom
Murmele:mm/window_adapter
Open

Popup: Set correct window adapter for the component#11352
Murmele wants to merge 17 commits intoslint-ui:masterfrom
Murmele:mm/window_adapter

Conversation

@Murmele
Copy link
Copy Markdown
Contributor

@Murmele Murmele commented Apr 13, 2026

Reason: Previously always the main window adapter is used for popups as well. This is not correct, because then acting on the wrong renderer caches is done and the application might crash or memory gets not freed.
To solve this problem, showing the popup is split up in multiple steps.

  1. Creating the window adapter for the popup if possible.
  2. Assigning this window adapter to the popup instance so that the tree will be setup with the newly created window adapter.
  3. Determine the popup location and show the created popup

Comment thread internal/core/window.rs Outdated
Comment thread internal/backends/winit/winitwindowadapter.rs Outdated
Comment thread internal/compiler/generator/rust.rs
Comment thread internal/compiler/generator/rust.rs
Comment thread internal/backends/winit/winitwindowadapter.rs Outdated
Reason: Previously always the main window adapter is used for popups as well. This is not correct, because then acting on the wrong renderer caches is done and the application might crash or memory gets not freed. To solve this problem. Showing the popup is split up in multiple steps. 1) Creating the window adapter for the popup if possible. 2) Assigning this window adapter to the popup instance so that the tree will be setup with the newly created window adapter. 3) Determine the popup location and show the created popup
@Murmele Murmele force-pushed the mm/window_adapter branch from 610922e to f2b74e4 Compare April 13, 2026 06:19
@Murmele Murmele marked this pull request as ready for review April 13, 2026 07:02
Comment thread internal/core/window.rs Outdated
@Murmele Murmele requested a review from ogoffart April 13, 2026 07:04
Copy link
Copy Markdown
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

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

(partial review)

Comment thread internal/core/window.rs Outdated

/// Shows the popup created with create_popup_window_adapter()
/// `geometry` is the location and size of the popup in the window coordinate
fn show_popup(&self, _window_adapter: Rc<dyn WindowAdapter>, _geometry: LogicalRect) {}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Long term, we'll want to make this interface public, and i'd like to avoid having too many functions for this in the WindowAdapter.

What's the reason this can't be done by the normal show function?

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.

I changed to use the set_visible() function so we don't need this trait function. fd13575

Tested with qt, winit ChildWindow and winit TopLevelWindow (on another branch)

Comment thread internal/core/window.rs Outdated
Comment on lines +1348 to +1351
if let Some(s) = self.window_adapter().internal(crate::InternalToken) {
return s.create_popup_window_adapter();
}
None
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nitpick: This could be simplified with a .map(...)

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 ee60b66

Comment thread internal/core/window.rs Outdated
ItemTreeRc::borrow_pin(popup_componentrc)
.as_ref()
.window_adapter(false, &mut popup_window_adapter);
let popup_window_adapter = popup_window_adapter.unwrap(); // It must be there because we set the global
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nitpick: could be an expect(...) instead of a comment

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.

Thanks. Fixed in b32cee7

Comment thread internal/core/window.rs
WindowInner::from_pub(window_adapter.window()).set_component(popup_componentrc);
PopupWindowLocation::TopLevel(window_adapter)
}
let location = if Rc::ptr_eq(&parent_window_adapter, &popup_window_adapter) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm thinking this could potentially be a problem if we had a popup child of another popup and one (custom) platform would only support one layer of popup. But maybe there is no such thing.

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.

You mean a mix of ChildWindow and TopLevelWindow?

#(#global_names : self.#global_names.clone(),)*
#(#from_library_global_names : self.#from_library_global_names.clone(),)*
window_adapter: ::core::default::Default::default(),
root_item_tree_weak: self.root_item_tree_weak.clone(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this also need to passed in

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.

I can do. It is only required to init the window_adapter, but since we initialized already, self.window_adapter.get_or_try_init will never call the init branch

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 problem here is that we need the global to create the item, but on the other side we need the global to create the popup item

let parent_item = #parent_item;
let popup_instance = #popup_window_id::new(#component_access_tokens.self_weak.get().unwrap().clone()).unwrap();
// Use the newly created window adapter if we are able to create one. Otherwise use the parent's one
let globals = if let Some(window_adapter) = sp::WindowInner::from_pub(#window_adapter_tokens.window()).create_popup_window_adapter() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess a similar change in the C++ and interpreter code will be required.

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.

yep there I have to add as well

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.

done

@Murmele Murmele marked this pull request as draft April 13, 2026 12:30
@Murmele Murmele marked this pull request as ready for review April 15, 2026 06:39
@Murmele Murmele requested a review from ogoffart April 15, 2026 06:39
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.

2 participants