From f82ddbe15e78b801a3b1e76aa185d75558c2f764 Mon Sep 17 00:00:00 2001 From: Jason Tsai Date: Mon, 22 Jul 2024 12:53:50 +0800 Subject: [PATCH 1/2] fix(example): workaround to prevent winit crash when unfocused --- .changes/example-winit-unfocus-crash.md | 5 +++++ examples/winit.rs | 21 +++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 .changes/example-winit-unfocus-crash.md diff --git a/.changes/example-winit-unfocus-crash.md b/.changes/example-winit-unfocus-crash.md new file mode 100644 index 000000000..0734d086f --- /dev/null +++ b/.changes/example-winit-unfocus-crash.md @@ -0,0 +1,5 @@ +--- +"wry": patch +--- + +Use a workaround for winit example to prevent crash when unfocus the window. diff --git a/examples/winit.rs b/examples/winit.rs index b67676416..fe76f5859 100644 --- a/examples/winit.rs +++ b/examples/winit.rs @@ -2,12 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT +use dpi::{LogicalPosition, LogicalSize}; use winit::{ event::{Event, WindowEvent}, event_loop::{ControlFlow, EventLoop}, window::WindowBuilder, }; -use wry::WebViewBuilder; +use wry::{Rect, WebViewBuilder}; fn main() -> wry::Result<()> { #[cfg(any( @@ -39,9 +40,9 @@ fn main() -> wry::Result<()> { .build(&event_loop) .unwrap(); - #[allow(unused_mut)] - let mut builder = WebViewBuilder::new(&window); - let _webview = builder.with_url("https://tauri.app").build()?; + let webview = WebViewBuilder::new_as_child(&window) + .with_url("https://tauri.app") + .build()?; event_loop .run(move |event, evl| { @@ -59,6 +60,18 @@ fn main() -> wry::Result<()> { } match event { + Event::WindowEvent { + event: WindowEvent::Resized(size), + .. + } => { + let size = size.to_logical::(window.scale_factor()); + webview + .set_bounds(Rect { + position: LogicalPosition::new(0, 0).into(), + size: LogicalSize::new(size.width, size.height).into(), + }) + .unwrap(); + } #[cfg(any( target_os = "linux", target_os = "dragonfly", From a182fb66bf4d97039ea98f7cf35684a9a0e94b3a Mon Sep 17 00:00:00 2001 From: Jason Tsai Date: Mon, 22 Jul 2024 13:09:21 +0800 Subject: [PATCH 2/2] chore: remove changelog and unix resize event --- .changes/example-winit-unfocus-crash.md | 5 ----- examples/winit.rs | 20 -------------------- 2 files changed, 25 deletions(-) delete mode 100644 .changes/example-winit-unfocus-crash.md diff --git a/.changes/example-winit-unfocus-crash.md b/.changes/example-winit-unfocus-crash.md deleted file mode 100644 index 0734d086f..000000000 --- a/.changes/example-winit-unfocus-crash.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"wry": patch ---- - -Use a workaround for winit example to prevent crash when unfocus the window. diff --git a/examples/winit.rs b/examples/winit.rs index fe76f5859..9afd8104b 100644 --- a/examples/winit.rs +++ b/examples/winit.rs @@ -72,26 +72,6 @@ fn main() -> wry::Result<()> { }) .unwrap(); } - #[cfg(any( - target_os = "linux", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd", - ))] - Event::WindowEvent { - event: WindowEvent::Resized(size), - .. - } => { - use wry::dpi::{PhysicalPosition, PhysicalSize}; - - _webview - .set_bounds(wry::Rect { - position: PhysicalPosition::new(0, 0).into(), - size: PhysicalSize::new(size.width, size.height).into(), - }) - .unwrap(); - } Event::WindowEvent { event: WindowEvent::CloseRequested, ..