summaryrefslogtreecommitdiffstats
path: root/winit/src/application
diff options
context:
space:
mode:
Diffstat (limited to 'winit/src/application')
-rw-r--r--winit/src/application/profiler.rs101
-rw-r--r--winit/src/application/state.rs24
2 files changed, 13 insertions, 112 deletions
diff --git a/winit/src/application/profiler.rs b/winit/src/application/profiler.rs
deleted file mode 100644
index 7031507a..00000000
--- a/winit/src/application/profiler.rs
+++ /dev/null
@@ -1,101 +0,0 @@
-//! A simple profiler for Iced.
-use std::ffi::OsStr;
-use std::path::Path;
-use std::time::Duration;
-use tracing_subscriber::prelude::*;
-use tracing_subscriber::Registry;
-#[cfg(feature = "chrome-trace")]
-use {
- tracing_chrome::FlushGuard,
- tracing_subscriber::fmt::{format::DefaultFields, FormattedFields},
-};
-
-/// Profiler state. This will likely need to be updated or reworked when adding new tracing backends.
-#[allow(missing_debug_implementations)]
-pub struct Profiler {
- #[cfg(feature = "chrome-trace")]
- /// [`FlushGuard`] must not be dropped until the application scope is dropped for accurate tracing.
- _guard: FlushGuard,
-}
-
-impl Profiler {
- /// Initializes the [`Profiler`].
- pub fn init() -> Self {
- // Registry stores the spans & generates unique span IDs
- let subscriber = Registry::default();
-
- let default_path = Path::new(env!("CARGO_MANIFEST_DIR"));
- let curr_exe = std::env::current_exe()
- .unwrap_or_else(|_| default_path.to_path_buf());
- let out_dir = curr_exe.parent().unwrap_or(default_path).join("traces");
-
- #[cfg(feature = "chrome-trace")]
- let (chrome_layer, guard) = {
- let mut layer = tracing_chrome::ChromeLayerBuilder::new();
-
- // Optional configurable env var: CHROME_TRACE_FILE=/path/to/trace_file/file.json,
- // for uploading to chrome://tracing (old) or ui.perfetto.dev (new).
- if let Ok(path) = std::env::var("CHROME_TRACE_FILE") {
- layer = layer.file(path);
- } else if std::fs::create_dir_all(&out_dir).is_ok() {
- let time = std::time::SystemTime::now()
- .duration_since(std::time::UNIX_EPOCH)
- .unwrap_or(Duration::from_millis(0))
- .as_millis();
-
- let curr_exe_name = curr_exe
- .file_name()
- .unwrap_or_else(|| OsStr::new("trace"))
- .to_str()
- .unwrap_or("trace");
-
- let path =
- out_dir.join(format!("{curr_exe_name}_trace_{time}.json"));
-
- layer = layer.file(path);
- } else {
- layer = layer.file(env!("CARGO_MANIFEST_DIR"))
- }
-
- let (chrome_layer, guard) = layer
- .name_fn(Box::new(|event_or_span| match event_or_span {
- tracing_chrome::EventOrSpan::Event(event) => {
- event.metadata().name().into()
- }
- tracing_chrome::EventOrSpan::Span(span) => {
- if let Some(fields) = span
- .extensions()
- .get::<FormattedFields<DefaultFields>>()
- {
- format!(
- "{}: {}",
- span.metadata().name(),
- fields.fields.as_str()
- )
- } else {
- span.metadata().name().into()
- }
- }
- }))
- .build();
-
- (chrome_layer, guard)
- };
-
- let fmt_layer = tracing_subscriber::fmt::Layer::default();
- let subscriber = subscriber.with(fmt_layer);
-
- #[cfg(feature = "chrome-trace")]
- let subscriber = subscriber.with(chrome_layer);
-
- // create dispatcher which will forward span events to the subscriber
- // this can only be set once or will panic
- tracing::subscriber::set_global_default(subscriber)
- .expect("Tracer could not set the global default subscriber.");
-
- Profiler {
- #[cfg(feature = "chrome-trace")]
- _guard: guard,
- }
- }
-}
diff --git a/winit/src/application/state.rs b/winit/src/application/state.rs
index e655529a..8c9b20e0 100644
--- a/winit/src/application/state.rs
+++ b/winit/src/application/state.rs
@@ -22,7 +22,7 @@ where
viewport: Viewport,
viewport_version: usize,
cursor_position: Option<winit::dpi::PhysicalPosition<f64>>,
- modifiers: winit::event::ModifiersState,
+ modifiers: winit::keyboard::ModifiersState,
theme: <A::Renderer as core::Renderer>::Theme,
appearance: application::Appearance,
application: PhantomData<A>,
@@ -54,7 +54,7 @@ where
viewport,
viewport_version: 0,
cursor_position: None,
- modifiers: winit::event::ModifiersState::default(),
+ modifiers: winit::keyboard::ModifiersState::default(),
theme,
appearance,
application: PhantomData,
@@ -102,7 +102,7 @@ where
}
/// Returns the current keyboard modifiers of the [`State`].
- pub fn modifiers(&self) -> winit::event::ModifiersState {
+ pub fn modifiers(&self) -> winit::keyboard::ModifiersState {
self.modifiers
}
@@ -126,7 +126,7 @@ where
pub fn update(
&mut self,
window: &Window,
- event: &WindowEvent<'_>,
+ event: &WindowEvent,
_debug: &mut Debug,
) {
match event {
@@ -142,10 +142,9 @@ where
}
WindowEvent::ScaleFactorChanged {
scale_factor: new_scale_factor,
- new_inner_size,
+ ..
} => {
- let size =
- Size::new(new_inner_size.width, new_inner_size.height);
+ let size = self.viewport.physical_size();
self.viewport = Viewport::with_physical_size(
size,
@@ -164,13 +163,16 @@ where
self.cursor_position = None;
}
WindowEvent::ModifiersChanged(new_modifiers) => {
- self.modifiers = *new_modifiers;
+ self.modifiers = new_modifiers.state();
}
#[cfg(feature = "debug")]
WindowEvent::KeyboardInput {
- input:
- winit::event::KeyboardInput {
- virtual_keycode: Some(winit::event::VirtualKeyCode::F12),
+ event:
+ winit::event::KeyEvent {
+ logical_key:
+ winit::keyboard::Key::Named(
+ winit::keyboard::NamedKey::F12,
+ ),
state: winit::event::ElementState::Pressed,
..
},