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

/// Open a portal dialog with an exported Wayland parent handle and modal hint.
OpenDialog(Id, Settings, String, bool, Option<String>, oneshot::Sender<Option<Id>>),

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

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

/// Opens an out-of-process dialog. The Wayland parent handle excludes the
/// `wayland:` prefix. Unsupported compositors may display an unparented window;
/// unsupported adapters return `None` without opening a surface.
pub fn open_dialog(parent_handle: String, modal: bool, settings: Settings) -> (Id, Task<Option<Id>>) {
open_dialog_with_activation(parent_handle, modal, None, settings)
}

/// Opens a dialog using an incoming startup activation token, when supplied.
pub fn open_dialog_with_activation(parent_handle: String, modal: bool, activation_token: Option<String>, settings: Settings) -> (Id, Task<Option<Id>>) {
let id = Id::unique();
(id, task::oneshot(move |channel| {
crate::Action::Window(Action::OpenDialog(id, settings, parent_handle, modal, activation_token, channel))
}))
}

/// Closes the window with `id`.
pub fn close<T>(id: Id) -> Task<T> {
task::effect(crate::Action::Window(Action::Close(id)))
Expand Down
41 changes: 37 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,
foreign_parent,
} => {
let exit_on_close_request =
settings.exit_on_close_request;
Expand All @@ -325,6 +327,8 @@ where
)
.with_visible(false);

let window_attributes = transient::dialog_attributes(window_attributes, foreign_parent);

#[cfg(target_arch = "wasm32")]
let window_attributes = {
use winit::platform::web::WindowAttributesExtWebSys;
Expand Down Expand Up @@ -462,14 +466,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 +508,8 @@ enum Control {
settings: window::Settings,
title: String,
monitor: Option<winit::monitor::MonitorHandle>,
on_open: oneshot::Sender<window::Id>,
on_open: OpenResponse,
foreign_parent: Option<(String, bool, Option<String>)>,
scale_factor: f32,
},
SetAutomaticWindowTabbing(bool),
Expand Down Expand Up @@ -709,7 +733,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 +1414,21 @@ 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),
foreign_parent: None,
})
.expect("Send control action");

*is_window_opening = true;
}
window::Action::OpenDialog(id, settings, handle, modal, token, channel) => {
control_sender.start_send(Control::CreateWindow {
id, settings, title: program.title(id), scale_factor: program.scale_factor(id),
monitor: window_manager.last_monitor(), on_open: OpenResponse::Transient(channel),
foreign_parent: Some((handle, modal, token)),
}).expect("Send dialog window control action");
*is_window_opening = true;
}
window::Action::Close(id) => {
let _ = ui_caches.remove(&id);
let _ = interfaces.remove(&id);
Expand Down
17 changes: 17 additions & 0 deletions winit/src/transient.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! Native auxiliary-window attributes, applied before initial configuration.
use winit::window::WindowAttributes;

pub(crate) fn dialog_attributes(attributes: WindowAttributes, parent: Option<(String, bool, Option<String>)>) -> WindowAttributes {
#[cfg(all(target_os = "linux", feature = "wayland"))]
if let Some((handle, modal, token)) = parent {
use winit::platform::wayland::WindowAttributesExtWayland;
use winit::platform::startup_notify::WindowAttributesExtStartupNotify;
let attributes = attributes.with_foreign_parent(handle, modal);
return if let Some(token) = token {
attributes.with_activation_token(winit::window::ActivationToken::from_raw(token))
} else { attributes };
}
#[cfg(not(all(target_os = "linux", feature = "wayland")))]
let _ = parent;
attributes
}