From 99f9e76c37b59a9db7f0fe2b7a80601a9c0b7af6 Mon Sep 17 00:00:00 2001 From: Kevin O'NEILL Date: Tue, 10 Nov 2026 21:24:36 +0100 Subject: [PATCH] wayland: set a transient parent before the initial configure Window::set_parent support through the cross-platform parent attribute is not implemented on Wayland, and setting xdg_toplevel.set_parent after the window has been created is too late: the first commit has already requested the initial configure, so a tiling compositor sizes the window as a tiled toplevel even if it later floats it once the parent arrives. Add WindowAttributesExtWayland::with_transient_parent(Arc). The parent is validated (it must be a Wayland window on the same connection) and applied with xdg_toplevel.set_parent right after the SCTK window is created and before its first commit, so the compositor can choose the size and placement of an auxiliary window from the start. The attribute keeps the parent alive until creation; the application owns both windows afterwards. Co-Authored-By: Claude Opus 5.5 --- src/platform/wayland.rs | 15 ++++++++++++++ src/platform_impl/linux/mod.rs | 4 ++++ src/platform_impl/linux/wayland/window/mod.rs | 20 +++++++++++++++++++ 3 files changed, 39 insertions(+) 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,