diff --git a/src/platform/wayland.rs b/src/platform/wayland.rs index 9c1a8e4379..177991e567 100644 --- a/src/platform/wayland.rs +++ b/src/platform/wayland.rs @@ -16,6 +16,7 @@ use std::ffi::c_void; use std::ptr::NonNull; +use std::sync::Arc; use crate::event_loop::{ActiveEventLoop, EventLoop, EventLoopBuilder}; use crate::monitor::MonitorHandle; @@ -98,6 +99,14 @@ impl WindowExtWayland for Window { /// Additional methods on [`WindowAttributes`] that are specific to Wayland. pub trait WindowAttributesExtWayland { + /// Sets an existing window as the non-modal transient parent. + /// + /// The relationship is sent before the child's initial configure request, + /// allowing the compositor to choose auxiliary-window size and placement. + /// The parent must belong to the same Wayland event loop. Its native lifetime + /// is retained through creation; the application owns both windows afterward. + fn with_transient_parent(self, parent: Arc) -> Self; + /// Build window with the given name. /// /// The `general` name sets an application ID, which should match the `.desktop` @@ -109,6 +118,12 @@ pub trait WindowAttributesExtWayland { } impl WindowAttributesExtWayland for WindowAttributes { + #[inline] + fn with_transient_parent(mut self, parent: Arc) -> Self { + self.platform_specific.wayland_parent = Some(parent); + self + } + #[inline] fn with_name(mut self, general: impl Into, instance: impl Into) -> Self { self.platform_specific.name = diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index bc0e71c80c..65d305508f 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -73,6 +73,8 @@ impl ApplicationName { pub struct PlatformSpecificWindowAttributes { pub name: Option, pub activation_token: Option, + #[cfg(wayland_platform)] + pub wayland_parent: Option>, #[cfg(x11_platform)] pub x11: X11WindowAttributes, } @@ -96,6 +98,8 @@ impl Default for PlatformSpecificWindowAttributes { Self { name: None, activation_token: None, + #[cfg(wayland_platform)] + wayland_parent: None, #[cfg(x11_platform)] x11: X11WindowAttributes { visual_id: None, diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index 6d29a5a5f0..97eeaf663a 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -107,6 +107,26 @@ impl Window { let window = state.xdg_shell.create_window(surface.clone(), default_decorations, &queue_handle); + // Establish auxiliary ownership before the first commit/configure. + // Applying it after initial configuration retains a tiled initial size + // even if the compositor floats the window when its first buffer maps. + if let Some(parent) = &attributes.platform_specific.wayland_parent { + match &parent.window { + crate::platform_impl::Window::Wayland(parent) => { + if parent.display != display { + return Err(os_error!(OsError::Misc( + "transient parent belongs to another Wayland connection", + ))); + } + window.set_parent(Some(&parent.window)); + } + #[cfg(x11_platform)] + crate::platform_impl::Window::X(_) => { + return Err(os_error!(OsError::Misc("transient parent is not a Wayland window"))); + } + } + } + let mut window_state = WindowState::new( event_loop_window_target.connection.clone(), &event_loop_window_target.queue_handle,