diff options
Diffstat (limited to 'winit')
| -rw-r--r-- | winit/Cargo.toml | 2 | ||||
| -rw-r--r-- | winit/src/application.rs | 47 | ||||
| -rw-r--r-- | winit/src/application/state.rs | 29 | 
3 files changed, 52 insertions, 26 deletions
| diff --git a/winit/Cargo.toml b/winit/Cargo.toml index b75b1929..de7c1c62 100644 --- a/winit/Cargo.toml +++ b/winit/Cargo.toml @@ -31,7 +31,7 @@ raw-window-handle = "0.5"  [dependencies.winit]  version = "0.28"  git = "https://github.com/iced-rs/winit.git" -rev = "ac1ddfe0bd870910b3aa64a18d386fdd55b30a1d" +rev = "c52db2045d0a2f1b8d9923870de1d4ab1994146e"  default-features = false  [dependencies.iced_runtime] diff --git a/winit/src/application.rs b/winit/src/application.rs index 4147be17..6e7b94ef 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -308,6 +308,8 @@ async fn run_instance<A, E, C>(      run_command(          &application, +        &mut compositor, +        &mut surface,          &mut cache,          &state,          &mut renderer, @@ -318,7 +320,6 @@ async fn run_instance<A, E, C>(          &mut proxy,          &mut debug,          &window, -        || compositor.fetch_information(),      );      runtime.track(application.subscription().into_recipes()); @@ -356,7 +357,7 @@ async fn run_instance<A, E, C>(                  let (interface_state, statuses) = user_interface.update(                      &events, -                    state.cursor_position(), +                    state.cursor(),                      &mut renderer,                      &mut clipboard,                      &mut messages, @@ -382,6 +383,8 @@ async fn run_instance<A, E, C>(                      // Update application                      update(                          &mut application, +                        &mut compositor, +                        &mut surface,                          &mut cache,                          &state,                          &mut renderer, @@ -392,7 +395,6 @@ async fn run_instance<A, E, C>(                          &mut debug,                          &mut messages,                          &window, -                        || compositor.fetch_information(),                      );                      // Update window @@ -422,7 +424,7 @@ async fn run_instance<A, E, C>(                  let (interface_state, _) = user_interface.update(                      &[redraw_event.clone()], -                    state.cursor_position(), +                    state.cursor(),                      &mut renderer,                      &mut clipboard,                      &mut messages, @@ -435,7 +437,7 @@ async fn run_instance<A, E, C>(                      &renderer::Style {                          text_color: state.text_color(),                      }, -                    state.cursor_position(), +                    state.cursor(),                  );                  debug.draw_finished(); @@ -508,7 +510,7 @@ async fn run_instance<A, E, C>(                          &renderer::Style {                              text_color: state.text_color(),                          }, -                        state.cursor_position(), +                        state.cursor(),                      );                      if new_mouse_interaction != mouse_interaction { @@ -645,8 +647,10 @@ where  /// Updates an [`Application`] by feeding it the provided messages, spawning any  /// resulting [`Command`], and tracking its [`Subscription`]. -pub fn update<A: Application, E: Executor>( +pub fn update<A: Application, C, E: Executor>(      application: &mut A, +    compositor: &mut C, +    surface: &mut C::Surface,      cache: &mut user_interface::Cache,      state: &State<A>,      renderer: &mut A::Renderer, @@ -657,8 +661,8 @@ pub fn update<A: Application, E: Executor>(      debug: &mut Debug,      messages: &mut Vec<A::Message>,      window: &winit::window::Window, -    graphics_info: impl FnOnce() -> compositor::Information + Copy,  ) where +    C: Compositor<Renderer = A::Renderer> + 'static,      <A::Renderer as core::Renderer>::Theme: StyleSheet,  {      for message in messages.drain(..) { @@ -676,6 +680,8 @@ pub fn update<A: Application, E: Executor>(          run_command(              application, +            compositor, +            surface,              cache,              state,              renderer, @@ -686,7 +692,6 @@ pub fn update<A: Application, E: Executor>(              proxy,              debug,              window, -            graphics_info,          );      } @@ -695,8 +700,10 @@ pub fn update<A: Application, E: Executor>(  }  /// Runs the actions of a [`Command`]. -pub fn run_command<A, E>( +pub fn run_command<A, C, E>(      application: &A, +    compositor: &mut C, +    surface: &mut C::Surface,      cache: &mut user_interface::Cache,      state: &State<A>,      renderer: &mut A::Renderer, @@ -707,10 +714,10 @@ pub fn run_command<A, E>(      proxy: &mut winit::event_loop::EventLoopProxy<A::Message>,      debug: &mut Debug,      window: &winit::window::Window, -    _graphics_info: impl FnOnce() -> compositor::Information + Copy,  ) where      A: Application,      E: Executor, +    C: Compositor<Renderer = A::Renderer> + 'static,      <A::Renderer as core::Renderer>::Theme: StyleSheet,  {      use crate::runtime::command; @@ -802,12 +809,28 @@ pub fn run_command<A, E>(                          .send_event(tag(window.id().into()))                          .expect("Send message to event loop");                  } +                window::Action::Screenshot(tag) => { +                    let bytes = compositor.screenshot( +                        renderer, +                        surface, +                        state.viewport(), +                        state.background_color(), +                        &debug.overlay(), +                    ); + +                    proxy +                        .send_event(tag(window::Screenshot::new( +                            bytes, +                            state.physical_size(), +                        ))) +                        .expect("Send message to event loop.") +                }              },              command::Action::System(action) => match action {                  system::Action::QueryInformation(_tag) => {                      #[cfg(feature = "system")]                      { -                        let graphics_info = _graphics_info(); +                        let graphics_info = compositor.fetch_information();                          let proxy = proxy.clone();                          let _ = std::thread::spawn(move || { diff --git a/winit/src/application/state.rs b/winit/src/application/state.rs index c37ccca6..967f43f2 100644 --- a/winit/src/application/state.rs +++ b/winit/src/application/state.rs @@ -1,7 +1,8 @@  use crate::application::{self, StyleSheet as _};  use crate::conversion;  use crate::core; -use crate::core::{Color, Point, Size}; +use crate::core::mouse; +use crate::core::{Color, Size};  use crate::graphics::Viewport;  use crate::runtime::Debug;  use crate::Application; @@ -20,7 +21,7 @@ where      scale_factor: f64,      viewport: Viewport,      viewport_version: usize, -    cursor_position: winit::dpi::PhysicalPosition<f64>, +    cursor_position: Option<winit::dpi::PhysicalPosition<f64>>,      modifiers: winit::event::ModifiersState,      theme: <A::Renderer as core::Renderer>::Theme,      appearance: application::Appearance, @@ -52,8 +53,7 @@ where              scale_factor,              viewport,              viewport_version: 0, -            // TODO: Encode cursor availability in the type-system -            cursor_position: winit::dpi::PhysicalPosition::new(-1.0, -1.0), +            cursor_position: None,              modifiers: winit::event::ModifiersState::default(),              theme,              appearance, @@ -89,11 +89,16 @@ where      }      /// Returns the current cursor position of the [`State`]. -    pub fn cursor_position(&self) -> Point { -        conversion::cursor_position( -            self.cursor_position, -            self.viewport.scale_factor(), -        ) +    pub fn cursor(&self) -> mouse::Cursor { +        self.cursor_position +            .map(|cursor_position| { +                conversion::cursor_position( +                    cursor_position, +                    self.viewport.scale_factor(), +                ) +            }) +            .map(mouse::Cursor::Available) +            .unwrap_or(mouse::Cursor::Unavailable)      }      /// Returns the current keyboard modifiers of the [`State`]. @@ -153,12 +158,10 @@ where              | WindowEvent::Touch(Touch {                  location: position, ..              }) => { -                self.cursor_position = *position; +                self.cursor_position = Some(*position);              }              WindowEvent::CursorLeft { .. } => { -                // TODO: Encode cursor availability in the type-system -                self.cursor_position = -                    winit::dpi::PhysicalPosition::new(-1.0, -1.0); +                self.cursor_position = None;              }              WindowEvent::ModifiersChanged(new_modifiers) => {                  self.modifiers = *new_modifiers; | 
