Wayland, Windows, MacOS: Popup Implementation (#4543)

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

With this commit, 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
This commit is contained in:
Martin Marmsoler
2026-07-27 15:43:51 +02:00
committed by GitHub
parent 1fe178b2a6
commit 9674d8ceef
22 changed files with 2035 additions and 368 deletions

View File

@@ -1,4 +1,4 @@
#[cfg(any(x11_platform, macos_platform, windows_platform))]
#[cfg(any(wayland_platform, x11_platform, macos_platform, windows_platform))]
#[allow(deprecated)]
fn main() -> Result<(), impl std::error::Error> {
use std::collections::HashMap;
@@ -10,7 +10,7 @@ fn main() -> Result<(), impl std::error::Error> {
use winit::event::{ElementState, KeyEvent, WindowEvent};
use winit::event_loop::{ActiveEventLoop, EventLoop, OwnedDisplayHandle};
use winit::raw_window_handle::HasRawWindowHandle;
use winit::window::{Window, WindowAttributes, WindowId};
use winit::window::{Window, WindowAttributes, WindowId, WindowType};
#[path = "util/fill.rs"]
mod fill;
@@ -39,6 +39,7 @@ fn main() -> Result<(), impl std::error::Error> {
fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) {
let attributes = WindowAttributes::default()
.with_title("parent window")
.with_window_type(WindowType::Window)
.with_position(Position::Logical(LogicalPosition::new(0.0, 0.0)))
.with_surface_size(LogicalSize::new(640.0f32, 480.0f32));
let window = event_loop.create_window(attributes).unwrap();
@@ -131,10 +132,10 @@ fn main() -> Result<(), impl std::error::Error> {
event_loop.run_app(Application { context, parent_window_id: None, windows: HashMap::new() })
}
#[cfg(not(any(x11_platform, macos_platform, windows_platform)))]
#[cfg(not(any(wayland_platform, x11_platform, macos_platform, windows_platform)))]
fn main() {
panic!(
"This example is supported only on x11, macOS, and Windows, with the `rwh_06` feature \
enabled."
"This example is supported only on wayland, x11, macOS, and Windows, with the `rwh_06` \
feature enabled."
);
}