diff --git a/Cargo.lock b/Cargo.lock index 8b65d21309..6becfdb36e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1283,7 +1283,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -1349,9 +1349,8 @@ dependencies = [ [[package]] name = "dpi" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76" +version = "0.1.1" +source = "git+https://github.com/kevinard/winit?rev=99f9e76c37b59a9db7f0fe2b7a80601a9c0b7af6#99f9e76c37b59a9db7f0fe2b7a80601a9c0b7af6" [[package]] name = "editor" @@ -1437,7 +1436,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -2811,7 +2810,7 @@ checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46" dependencies = [ "hermit-abi", "libc", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -2869,7 +2868,7 @@ dependencies = [ "portable-atomic", "portable-atomic-util", "serde_core", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -3527,7 +3526,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -4959,7 +4958,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.11.0", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -5737,7 +5736,7 @@ dependencies = [ "getrandom 0.3.4", "once_cell", "rustix 1.1.2", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -6982,7 +6981,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -7476,9 +7475,8 @@ checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" [[package]] name = "winit" -version = "0.30.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c66d4b9ed69c4009f6321f762d6e61ad8a2389cd431b97cb1e146812e9e6c732" +version = "0.30.13" +source = "git+https://github.com/kevinard/winit?rev=99f9e76c37b59a9db7f0fe2b7a80601a9c0b7af6#99f9e76c37b59a9db7f0fe2b7a80601a9c0b7af6" dependencies = [ "ahash", "android-activity", diff --git a/Cargo.toml b/Cargo.toml index bfaf6f44e5..de32b44f57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -263,3 +263,6 @@ useless_conversion = "deny" [workspace.lints.rustdoc] broken_intra_doc_links = "forbid" + +[patch.crates-io] +winit = { git = "https://github.com/kevinard/winit", rev = "99f9e76c37b59a9db7f0fe2b7a80601a9c0b7af6" } diff --git a/runtime/src/window.rs b/runtime/src/window.rs index 2eb0509882..2b37fea469 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -19,6 +19,10 @@ pub enum Action { /// Open a new window with some [`Settings`]. Open(Id, Settings, oneshot::Sender), + /// Open an auxiliary window above an existing parent before mapping it. + /// Returns `None` when the parent is gone or the backend is unsupported. + OpenTransient(Id, Settings, Id, oneshot::Sender>), + /// Close the window and exits the application. Close(Id), @@ -280,6 +284,25 @@ pub fn open(settings: Settings) -> (Id, Task) { ) } +/// Opens a non-modal auxiliary window attached to an existing parent. +/// +/// The parent relationship is applied before the first rendered buffer is +/// attached. The compositor retains control of placement and focus policy. +/// Returns `None` if the parent has closed or native parenting is unsupported; +/// no unrelated ordinary window is shown in that case. +/// +/// Currently supported by the Winit backend on Wayland. Layer surfaces and +/// other platforms return `None`. +pub fn open_transient(parent: Id, settings: Settings) -> (Id, Task>) { + let id = Id::unique(); + ( + id, + task::oneshot(move |channel| { + crate::Action::Window(Action::OpenTransient(id, settings, parent, channel)) + }), + ) +} + /// Closes the window with `id`. pub fn close(id: Id) -> Task { task::effect(crate::Action::Window(Action::Close(id))) diff --git a/winit/src/lib.rs b/winit/src/lib.rs index 9f48aa8c9a..7cff3c980c 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -31,6 +31,7 @@ pub mod conversion; mod error; mod proxy; +mod transient; mod window; pub use clipboard::Clipboard; @@ -304,6 +305,7 @@ where scale_factor, monitor, on_open, + parent, } => { let exit_on_close_request = settings.exit_on_close_request; @@ -325,6 +327,11 @@ where ) .with_visible(false); + let window_attributes = transient::attributes( + window_attributes, + parent, + ); + #[cfg(target_arch = "wasm32")] let window_attributes = { use winit::platform::web::WindowAttributesExtWebSys; @@ -462,6 +469,25 @@ where } } +#[derive(Debug)] +enum OpenResponse { + Normal(oneshot::Sender), + Transient(oneshot::Sender>), +} + +impl OpenResponse { + fn opened(self, id: window::Id) { + match self { + Self::Normal(channel) => { + let _ = channel.send(id); + } + Self::Transient(channel) => { + let _ = channel.send(Some(id)); + } + } + } +} + #[derive(Debug)] enum Event { WindowCreated { @@ -469,7 +495,7 @@ enum Event { window: Arc, exit_on_close_request: bool, make_visible: bool, - on_open: oneshot::Sender, + on_open: OpenResponse, }, EventLoopAwakened(winit::event::Event), Exit, @@ -485,7 +511,8 @@ enum Control { settings: window::Settings, title: String, monitor: Option, - on_open: oneshot::Sender, + on_open: OpenResponse, + parent: Option>, scale_factor: f32, }, SetAutomaticWindowTabbing(bool), @@ -709,7 +736,7 @@ async fn run_instance

( clipboard = Clipboard::connect(window.raw.clone()); } - let _ = on_open.send(id); + on_open.opened(id); is_window_opening = false; } Event::EventLoopAwakened(event) => { @@ -1390,12 +1417,39 @@ fn run_action<'a, P, C>( title: program.title(id), scale_factor: program.scale_factor(id), monitor, - on_open: channel, + on_open: OpenResponse::Normal(channel), + parent: None, }) .expect("Send control action"); *is_window_opening = true; } + window::Action::OpenTransient(id, settings, parent, channel) => { + let Some(parent) = window_manager + .get_mut(parent) + .map(|window| window.raw.clone()) + else { + let _ = channel.send(None); + return; + }; + if !transient::supported(&parent) { + let _ = channel.send(None); + return; + } + let monitor = parent.current_monitor(); + control_sender + .start_send(Control::CreateWindow { + id, + settings, + title: program.title(id), + scale_factor: program.scale_factor(id), + monitor, + on_open: OpenResponse::Transient(channel), + parent: Some(parent), + }) + .expect("Send transient window control action"); + *is_window_opening = true; + } window::Action::Close(id) => { let _ = ui_caches.remove(&id); let _ = interfaces.remove(&id); diff --git a/winit/src/transient.rs b/winit/src/transient.rs new file mode 100644 index 0000000000..fd60857f88 --- /dev/null +++ b/winit/src/transient.rs @@ -0,0 +1,28 @@ +//! Native auxiliary-window attributes, applied before initial configuration. +use std::sync::Arc; +use winit::window::{Window, WindowAttributes}; + +#[cfg(all(target_os = "linux", feature = "wayland"))] +pub(crate) fn supported(parent: &Window) -> bool { + use winit::platform::wayland::WindowExtWayland; + parent.xdg_toplevel().is_some() +} + +#[cfg(not(all(target_os = "linux", feature = "wayland")))] +pub(crate) fn supported(_parent: &Window) -> bool { + false +} + +pub(crate) fn attributes( + attributes: WindowAttributes, + parent: Option>, +) -> WindowAttributes { + #[cfg(all(target_os = "linux", feature = "wayland"))] + if let Some(parent) = parent { + use winit::platform::wayland::WindowAttributesExtWayland; + return attributes.with_transient_parent(parent); + } + #[cfg(not(all(target_os = "linux", feature = "wayland")))] + let _ = parent; + attributes +}