diff options
Diffstat (limited to 'winit')
| -rw-r--r-- | winit/src/clipboard.rs | 10 | ||||
| -rw-r--r-- | winit/src/conversion.rs | 4 | ||||
| -rw-r--r-- | winit/src/program.rs | 96 | ||||
| -rw-r--r-- | winit/src/program/window_manager.rs | 8 | 
4 files changed, 90 insertions, 28 deletions
| diff --git a/winit/src/clipboard.rs b/winit/src/clipboard.rs index 7ae646fc..d54a1fe0 100644 --- a/winit/src/clipboard.rs +++ b/winit/src/clipboard.rs @@ -2,7 +2,7 @@  use crate::core::clipboard::Kind;  use std::sync::Arc; -use winit::window::Window; +use winit::window::{Window, WindowId};  /// A buffer for short-term storage and transfer within and between  /// applications. @@ -83,6 +83,14 @@ impl Clipboard {              State::Unavailable => {}          }      } + +    /// Returns the identifier of the window used to create the [`Clipboard`], if any. +    pub fn window_id(&self) -> Option<WindowId> { +        match &self.state { +            State::Connected { window, .. } => Some(window.id()), +            State::Unavailable => None, +        } +    }  }  impl crate::core::Clipboard for Clipboard { diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index e88ff84d..585e2409 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -79,6 +79,10 @@ pub fn window_attributes(          attributes = attributes              .with_skip_taskbar(settings.platform_specific.skip_taskbar); + +        attributes = attributes.with_undecorated_shadow( +            settings.platform_specific.undecorated_shadow, +        );      }      #[cfg(target_os = "macos")] diff --git a/winit/src/program.rs b/winit/src/program.rs index efe8a978..52d8eb5f 100644 --- a/winit/src/program.rs +++ b/winit/src/program.rs @@ -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)] @@ -650,7 +644,7 @@ async fn run_instance<P, C>(      mut runtime: Runtime<P::Executor, Proxy<P::Message>, Action<P::Message>>,      mut proxy: Proxy<P::Message>,      mut debug: Debug, -    mut boot: oneshot::Receiver<Boot<C>>, +    boot: oneshot::Receiver<Boot<C>>,      mut event_receiver: mpsc::UnboundedReceiver<Event<Action<P::Message>>>,      mut control_sender: mpsc::UnboundedSender<Control>,      is_daemon: bool, @@ -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.try_recv().ok().flatten().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,10 +667,22 @@ 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(); -    while let Some(event) = event_receiver.next().await { +    loop { +        // Empty the queue if possible +        let event = if let Ok(event) = event_receiver.try_next() { +            event +        } else { +            event_receiver.next().await +        }; + +        let Some(event) = event else { +            break; +        }; +          match event {              Event::WindowCreated {                  id, @@ -723,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;              } @@ -968,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, @@ -1212,13 +1227,23 @@ fn run_action<P, C>(                  *is_window_opening = true;              }              window::Action::Close(id) => { -                let _ = 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); +                    } -                events.push(( -                    id, -                    core::Event::Window(core::window::Event::Closed), -                )); +                    events.push(( +                        id, +                        core::Event::Window(core::window::Event::Closed), +                    )); +                }              }              window::Action::GetOldest(channel) => {                  let id = @@ -1278,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() @@ -1293,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( @@ -1403,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) => { diff --git a/winit/src/program/window_manager.rs b/winit/src/program/window_manager.rs index fcbf79f6..3d22e155 100644 --- a/winit/src/program/window_manager.rs +++ b/winit/src/program/window_manager.rs @@ -74,12 +74,20 @@ where          self.entries.is_empty()      } +    pub fn first(&self) -> Option<&Window<P, C>> { +        self.entries.first_key_value().map(|(_id, window)| window) +    } +      pub fn iter_mut(          &mut self,      ) -> impl Iterator<Item = (Id, &mut Window<P, C>)> {          self.entries.iter_mut().map(|(k, v)| (*k, v))      } +    pub fn get(&self, id: Id) -> Option<&Window<P, C>> { +        self.entries.get(&id) +    } +      pub fn get_mut(&mut self, id: Id) -> Option<&mut Window<P, C>> {          self.entries.get_mut(&id)      } | 
