Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/platform/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Window>) -> Self;

/// Build window with the given name.
///
/// The `general` name sets an application ID, which should match the `.desktop`
Expand All @@ -109,6 +118,12 @@ pub trait WindowAttributesExtWayland {
}

impl WindowAttributesExtWayland for WindowAttributes {
#[inline]
fn with_transient_parent(mut self, parent: Arc<Window>) -> Self {
self.platform_specific.wayland_parent = Some(parent);
self
}

#[inline]
fn with_name(mut self, general: impl Into<String>, instance: impl Into<String>) -> Self {
self.platform_specific.name =
Expand Down
4 changes: 4 additions & 0 deletions src/platform_impl/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ impl ApplicationName {
pub struct PlatformSpecificWindowAttributes {
pub name: Option<ApplicationName>,
pub activation_token: Option<ActivationToken>,
#[cfg(wayland_platform)]
pub wayland_parent: Option<Arc<crate::window::Window>>,
#[cfg(x11_platform)]
pub x11: X11WindowAttributes,
}
Expand All @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions src/platform_impl/linux/wayland/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down