diff --git a/.changes/dpi-type-wrappers.md b/.changes/dpi-type-wrappers.md new file mode 100644 index 000000000000..93b0c1875f4e --- /dev/null +++ b/.changes/dpi-type-wrappers.md @@ -0,0 +1,5 @@ +--- +"tauri-runtime-wry": "minor:breaking" +--- + +Removed unused dpi wrapper types like `PhysicalPositionWrapper` diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index 8ba6a4f870f7..41bce8d15cee 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -63,11 +63,6 @@ use wry::WebViewBuilderExtWindows; use wry::{WebViewBuilderExtDarwin, WebViewExtDarwin}; use tao::{ - dpi::{ - LogicalPosition as TaoLogicalPosition, LogicalSize as TaoLogicalSize, - PhysicalPosition as TaoPhysicalPosition, PhysicalSize as TaoPhysicalSize, - Position as TaoPosition, Size as TaoSize, - }, event::{Event, StartCause, WindowEvent as TaoWindowEvent}, event_loop::{ ControlFlow, DeviceEventFilter as TaoDeviceEventFilter, EventLoop, EventLoopBuilder, @@ -507,17 +502,15 @@ impl WindowEventWrapper { #[allow(unused_variables)] window: &WindowWrapper, ) -> Self { let event = match event { - TaoWindowEvent::Resized(size) => WindowEvent::Resized(PhysicalSizeWrapper(*size).into()), - TaoWindowEvent::Moved(position) => { - WindowEvent::Moved(PhysicalPositionWrapper(*position).into()) - } + TaoWindowEvent::Resized(size) => WindowEvent::Resized(*size), + TaoWindowEvent::Moved(position) => WindowEvent::Moved(*position), TaoWindowEvent::Destroyed => WindowEvent::Destroyed, TaoWindowEvent::ScaleFactorChanged { scale_factor, new_inner_size, } => WindowEvent::ScaleFactorChanged { scale_factor: *scale_factor, - new_inner_size: PhysicalSizeWrapper(**new_inner_size).into(), + new_inner_size: **new_inner_size, }, TaoWindowEvent::Focused(focused) => { #[cfg(not(windows))] @@ -571,7 +564,7 @@ impl WindowEventWrapper { &window.webviews, window.has_children.load(Ordering::Relaxed), ); - Self(Some(WindowEvent::Resized(PhysicalSizeWrapper(size).into()))) + Self(Some(WindowEvent::Resized(size))) } else { Self(None) } @@ -605,102 +598,18 @@ impl From for Monitor { fn from(monitor: MonitorHandleWrapper) -> Monitor { Self { name: monitor.0.name(), - position: PhysicalPositionWrapper(monitor.0.position()).into(), - size: PhysicalSizeWrapper(monitor.0.size()).into(), + position: monitor.0.position(), + size: monitor.0.size(), work_area: monitor.0.work_area(), scale_factor: monitor.0.scale_factor(), } } } -pub struct PhysicalPositionWrapper(pub TaoPhysicalPosition); - -impl From> for PhysicalPosition { - fn from(position: PhysicalPositionWrapper) -> Self { - Self { - x: position.0.x, - y: position.0.y, - } - } -} - -impl From> for PhysicalPositionWrapper { - fn from(position: PhysicalPosition) -> Self { - Self(TaoPhysicalPosition { - x: position.x, - y: position.y, - }) - } -} - -struct LogicalPositionWrapper(TaoLogicalPosition); - -impl From> for LogicalPositionWrapper { - fn from(position: LogicalPosition) -> Self { - Self(TaoLogicalPosition { - x: position.x, - y: position.y, - }) - } -} - -pub struct PhysicalSizeWrapper(pub TaoPhysicalSize); - -impl From> for PhysicalSize { - fn from(size: PhysicalSizeWrapper) -> Self { - Self { - width: size.0.width, - height: size.0.height, - } - } -} - -impl From> for PhysicalSizeWrapper { - fn from(size: PhysicalSize) -> Self { - Self(TaoPhysicalSize { - width: size.width, - height: size.height, - }) - } -} - -struct LogicalSizeWrapper(TaoLogicalSize); - -impl From> for LogicalSizeWrapper { - fn from(size: LogicalSize) -> Self { - Self(TaoLogicalSize { - width: size.width, - height: size.height, - }) - } -} - -pub struct SizeWrapper(pub TaoSize); - -impl From for SizeWrapper { - fn from(size: Size) -> Self { - match size { - Size::Logical(s) => Self(TaoSize::Logical(LogicalSizeWrapper::from(s).0)), - Size::Physical(s) => Self(TaoSize::Physical(PhysicalSizeWrapper::from(s).0)), - } - } -} - -pub struct PositionWrapper(pub TaoPosition); - -impl From for PositionWrapper { - fn from(position: Position) -> Self { - match position { - Position::Logical(s) => Self(TaoPosition::Logical(LogicalPositionWrapper::from(s).0)), - Position::Physical(s) => Self(TaoPosition::Physical(PhysicalPositionWrapper::from(s).0)), - } - } -} - #[cfg(desktop)] fn find_monitor_for_position( monitors: impl Iterator, - window_position: TaoPosition, + window_position: Position, ) -> Option { monitors.into_iter().find(|m| { let monitor_pos = m.position(); @@ -986,8 +895,9 @@ impl WindowBuilder for WindowBuilderWrapper { if let Some(prevent_overflow) = &config.prevent_overflow { window = match prevent_overflow { PreventOverflowConfig::Enable(true) => window.prevent_overflow(), - PreventOverflowConfig::Margin(margin) => window - .prevent_overflow_with_margin(TaoPhysicalSize::new(margin.width, margin.height).into()), + PreventOverflowConfig::Margin(margin) => { + window.prevent_overflow_with_margin(PhysicalSize::new(margin.width, margin.height).into()) + } _ => window, }; } @@ -1001,28 +911,26 @@ impl WindowBuilder for WindowBuilderWrapper { } fn position(mut self, x: f64, y: f64) -> Self { - self.inner = self.inner.with_position(TaoLogicalPosition::new(x, y)); + self.inner = self.inner.with_position(LogicalPosition::new(x, y)); self } fn inner_size(mut self, width: f64, height: f64) -> Self { - self.inner = self - .inner - .with_inner_size(TaoLogicalSize::new(width, height)); + self.inner = self.inner.with_inner_size(LogicalSize::new(width, height)); self } fn min_inner_size(mut self, min_width: f64, min_height: f64) -> Self { self.inner = self .inner - .with_min_inner_size(TaoLogicalSize::new(min_width, min_height)); + .with_min_inner_size(LogicalSize::new(min_width, min_height)); self } fn max_inner_size(mut self, max_width: f64, max_height: f64) -> Self { self.inner = self .inner - .with_max_inner_size(TaoLogicalSize::new(max_width, max_height)); + .with_max_inner_size(LogicalSize::new(max_width, max_height)); self } @@ -2821,8 +2729,6 @@ impl RuntimeHandle for WryHandle { fn cursor_position(&self) -> Result> { event_loop_window_getter!(self, EventLoopWindowTargetMessage::CursorPosition)? - .map(PhysicalPositionWrapper) - .map(Into::into) .map_err(|_| Error::FailedToGetCursorPosition) } @@ -3149,8 +3055,6 @@ impl Runtime for Wry { .main_thread .window_target .cursor_position() - .map(PhysicalPositionWrapper) - .map(Into::into) .map_err(|_| Error::FailedToGetCursorPosition) } @@ -3392,7 +3296,6 @@ fn handle_user_message( .send( window .inner_position() - .map(|p| PhysicalPositionWrapper(p).into()) .map_err(|_| Error::FailedToSendMessage), ) .unwrap(), @@ -3400,16 +3303,13 @@ fn handle_user_message( .send( window .outer_position() - .map(|p| PhysicalPositionWrapper(p).into()) .map_err(|_| Error::FailedToSendMessage), ) .unwrap(), WindowMessage::InnerSize(tx) => tx - .send(PhysicalSizeWrapper(inner_size(&window, &webviews, has_children)).into()) - .unwrap(), - WindowMessage::OuterSize(tx) => tx - .send(PhysicalSizeWrapper(window.outer_size()).into()) + .send(inner_size(&window, &webviews, has_children)) .unwrap(), + WindowMessage::OuterSize(tx) => tx.send(window.outer_size()).unwrap(), WindowMessage::IsFullscreen(tx) => tx.send(window.fullscreen().is_some()).unwrap(), WindowMessage::IsMinimized(tx) => tx.send(window.is_minimized()).unwrap(), WindowMessage::IsMaximized(tx) => tx.send(window.is_maximized()).unwrap(), @@ -3531,13 +3431,13 @@ fn handle_user_message( } WindowMessage::SetContentProtected(protected) => window.set_content_protection(protected), WindowMessage::SetSize(size) => { - window.set_inner_size(SizeWrapper::from(size).0); + window.set_inner_size(size); } WindowMessage::SetMinSize(size) => { - window.set_min_inner_size(size.map(|s| SizeWrapper::from(s).0)); + window.set_min_inner_size(size); } WindowMessage::SetMaxSize(size) => { - window.set_max_inner_size(size.map(|s| SizeWrapper::from(s).0)); + window.set_max_inner_size(size); } WindowMessage::SetSizeConstraints(constraints) => { window.set_inner_size_constraints(tao::window::WindowSizeConstraints { @@ -3547,9 +3447,7 @@ fn handle_user_message( max_height: constraints.max_height, }); } - WindowMessage::SetPosition(position) => { - window.set_outer_position(PositionWrapper::from(position).0) - } + WindowMessage::SetPosition(position) => window.set_outer_position(position), WindowMessage::SetFullscreen(fullscreen) => { if fullscreen { window.set_fullscreen(Some(Fullscreen::Borderless(None))) @@ -3594,7 +3492,7 @@ fn handle_user_message( window.set_cursor_icon(CursorIconWrapper::from(icon).0); } WindowMessage::SetCursorPosition(position) => { - let _ = window.set_cursor_position(PositionWrapper::from(position).0); + let _ = window.set_cursor_position(position); } WindowMessage::SetIgnoreCursorEvents(ignore) => { let _ = window.set_ignore_cursor_events(ignore); @@ -4551,7 +4449,7 @@ fn create_window( .inner .window .inner_size - .unwrap_or_else(|| TaoPhysicalSize::new(800, 600).into()); + .unwrap_or_else(|| PhysicalSize::new(800, 600).into()); let mut inner_size = window_builder .inner .window @@ -5418,13 +5316,13 @@ fn inner_size( window: &Window, webviews: &[WebviewWrapper], has_children: bool, -) -> TaoPhysicalSize { +) -> PhysicalSize { if !has_children && !webviews.is_empty() { use wry::WebViewExtMacOS; let webview = webviews.first().unwrap(); let view = unsafe { Retained::cast_unchecked::(webview.webview()) }; let view_frame = view.frame(); - let logical: TaoLogicalSize = (view_frame.size.width, view_frame.size.height).into(); + let logical: LogicalSize = (view_frame.size.width, view_frame.size.height).into(); return logical.to_physical(window.scale_factor()); } @@ -5437,7 +5335,7 @@ fn inner_size( window: &Window, webviews: &[WebviewWrapper], has_children: bool, -) -> TaoPhysicalSize { +) -> PhysicalSize { window.inner_size() } diff --git a/crates/tauri-runtime-wry/src/window/mod.rs b/crates/tauri-runtime-wry/src/window/mod.rs index b18543e5d0f8..59af72f3192f 100644 --- a/crates/tauri-runtime-wry/src/window/mod.rs +++ b/crates/tauri-runtime-wry/src/window/mod.rs @@ -59,6 +59,7 @@ impl WindowExt for tao::window::Window { } } +#[cfg(desktop)] pub fn calculate_window_center_position( window_size: tao::dpi::PhysicalSize, target_monitor: tao::monitor::MonitorHandle,