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
26 changes: 12 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
23 changes: 23 additions & 0 deletions runtime/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ pub enum Action {
/// Open a new window with some [`Settings`].
Open(Id, Settings, oneshot::Sender<Id>),

/// 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<Option<Id>>),

/// Close the window and exits the application.
Close(Id),

Expand Down Expand Up @@ -280,6 +284,25 @@ pub fn open(settings: Settings) -> (Id, Task<Id>) {
)
}

/// 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<Option<Id>>) {
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<T>(id: Id) -> Task<T> {
task::effect(crate::Action::Window(Action::Close(id)))
Expand Down
62 changes: 58 additions & 4 deletions winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub mod conversion;

mod error;
mod proxy;
mod transient;
mod window;

pub use clipboard::Clipboard;
Expand Down Expand Up @@ -304,6 +305,7 @@ where
scale_factor,
monitor,
on_open,
parent,
} => {
let exit_on_close_request =
settings.exit_on_close_request;
Expand All @@ -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;
Expand Down Expand Up @@ -462,14 +469,33 @@ where
}
}

#[derive(Debug)]
enum OpenResponse {
Normal(oneshot::Sender<window::Id>),
Transient(oneshot::Sender<Option<window::Id>>),
}

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<Message: 'static> {
WindowCreated {
id: window::Id,
window: Arc<winit::window::Window>,
exit_on_close_request: bool,
make_visible: bool,
on_open: oneshot::Sender<window::Id>,
on_open: OpenResponse,
},
EventLoopAwakened(winit::event::Event<Message>),
Exit,
Expand All @@ -485,7 +511,8 @@ enum Control {
settings: window::Settings,
title: String,
monitor: Option<winit::monitor::MonitorHandle>,
on_open: oneshot::Sender<window::Id>,
on_open: OpenResponse,
parent: Option<Arc<winit::window::Window>>,
scale_factor: f32,
},
SetAutomaticWindowTabbing(bool),
Expand Down Expand Up @@ -709,7 +736,7 @@ async fn run_instance<P>(
clipboard = Clipboard::connect(window.raw.clone());
}

let _ = on_open.send(id);
on_open.opened(id);
is_window_opening = false;
}
Event::EventLoopAwakened(event) => {
Expand Down Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions winit/src/transient.rs
Original file line number Diff line number Diff line change
@@ -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<Arc<Window>>,
) -> 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
}