summaryrefslogtreecommitdiffstats
path: root/winit/src/program.rs
diff options
context:
space:
mode:
Diffstat (limited to 'winit/src/program.rs')
-rw-r--r--winit/src/program.rs77
1 files changed, 53 insertions, 24 deletions
diff --git a/winit/src/program.rs b/winit/src/program.rs
index c5c3133d..eef7e6c6 100644
--- a/winit/src/program.rs
+++ b/winit/src/program.rs
@@ -219,7 +219,7 @@ where
}
runtime.track(subscription::into_recipes(
- program.subscription().map(Action::Output),
+ runtime.enter(|| program.subscription().map(Action::Output)),
));
let (boot_sender, boot_receiver) = oneshot::channel();
@@ -307,8 +307,6 @@ where
}
};
- let clipboard = Clipboard::connect(window.clone());
-
let finish_boot = async move {
let mut compositor =
C::new(graphics_settings, window.clone()).await?;
@@ -318,10 +316,7 @@ where
}
sender
- .send(Boot {
- compositor,
- clipboard,
- })
+ .send(Boot { compositor })
.ok()
.expect("Send boot event");
@@ -617,7 +612,6 @@ where
struct Boot<C> {
compositor: C,
- clipboard: Clipboard,
}
#[derive(Debug)]
@@ -662,10 +656,7 @@ async fn run_instance<P, C>(
use winit::event;
use winit::event_loop::ControlFlow;
- let Boot {
- mut compositor,
- mut clipboard,
- } = boot.await.expect("Receive boot");
+ let Boot { mut compositor } = boot.await.expect("Receive boot");
let mut window_manager = WindowManager::new();
let mut is_window_opening = !is_daemon;
@@ -676,6 +667,7 @@ async fn run_instance<P, C>(
let mut ui_caches = FxHashMap::default();
let mut user_interfaces = ManuallyDrop::new(FxHashMap::default());
+ let mut clipboard = Clipboard::unconnected();
debug.startup_finished();
@@ -734,6 +726,10 @@ async fn run_instance<P, C>(
}),
));
+ if clipboard.window_id().is_none() {
+ clipboard = Clipboard::connect(window.raw.clone());
+ }
+
let _ = on_open.send(id);
is_window_opening = false;
}
@@ -979,14 +975,22 @@ async fn run_instance<P, C>(
winit::event::WindowEvent::CloseRequested
) && window.exit_on_close_request
{
- let _ = window_manager.remove(id);
- let _ = user_interfaces.remove(&id);
- let _ = ui_caches.remove(&id);
-
- events.push((
- id,
- core::Event::Window(window::Event::Closed),
- ));
+ run_action(
+ Action::Window(runtime::window::Action::Close(
+ id,
+ )),
+ &program,
+ &mut compositor,
+ &mut events,
+ &mut messages,
+ &mut clipboard,
+ &mut control_sender,
+ &mut debug,
+ &mut user_interfaces,
+ &mut window_manager,
+ &mut ui_caches,
+ &mut is_window_opening,
+ );
} else {
window.state.update(
&window.raw,
@@ -1165,7 +1169,7 @@ fn update<P: Program, E: Executor>(
}
}
- let subscription = program.subscription();
+ let subscription = runtime.enter(|| program.subscription());
runtime.track(subscription::into_recipes(subscription.map(Action::Output)));
}
@@ -1223,10 +1227,18 @@ fn run_action<P, C>(
*is_window_opening = true;
}
window::Action::Close(id) => {
- let window = window_manager.remove(id);
let _ = ui_caches.remove(&id);
+ let _ = interfaces.remove(&id);
+
+ if let Some(window) = window_manager.remove(id) {
+ if clipboard.window_id() == Some(window.raw.id()) {
+ *clipboard = window_manager
+ .first()
+ .map(|window| window.raw.clone())
+ .map(Clipboard::connect)
+ .unwrap_or_else(Clipboard::unconnected);
+ }
- if window.is_some() {
events.push((
id,
core::Event::Window(core::window::Event::Closed),
@@ -1291,7 +1303,7 @@ fn run_action<P, C>(
}
}
window::Action::GetPosition(id, channel) => {
- if let Some(window) = window_manager.get_mut(id) {
+ if let Some(window) = window_manager.get(id) {
let position = window
.raw
.inner_position()
@@ -1306,6 +1318,13 @@ fn run_action<P, C>(
let _ = channel.send(position);
}
}
+ window::Action::GetScaleFactor(id, channel) => {
+ if let Some(window) = window_manager.get_mut(id) {
+ let scale_factor = window.raw.scale_factor();
+
+ let _ = channel.send(scale_factor as f32);
+ }
+ }
window::Action::Move(id, position) => {
if let Some(window) = window_manager.get_mut(id) {
window.raw.set_outer_position(
@@ -1416,6 +1435,16 @@ fn run_action<P, C>(
));
}
}
+ window::Action::EnableMousePassthrough(id) => {
+ if let Some(window) = window_manager.get_mut(id) {
+ let _ = window.raw.set_cursor_hittest(false);
+ }
+ }
+ window::Action::DisableMousePassthrough(id) => {
+ if let Some(window) = window_manager.get_mut(id) {
+ let _ = window.raw.set_cursor_hittest(true);
+ }
+ }
},
Action::System(action) => match action {
system::Action::QueryInformation(_channel) => {