[MacOS] WindowEvent::Resized event doesn't return correct window size
Describe the bug
The WindowEvent::Resized(size) event doesn't report the correct window dimensions on MacOS.
Steps To Reproduce
Run the following sample code (tweaked from hello_world.rs):
fn main() -> wry::Result<()> {
use wry::{
application::{
event::{Event, StartCause, WindowEvent},
event_loop::{ControlFlow, EventLoop},
window::WindowBuilder,
},
webview::WebViewBuilder,
};
let event_loop = EventLoop::new();
let window = WindowBuilder::new()
.with_title("Hello World")
.build(&event_loop)?;
let webview = WebViewBuilder::new(window)?
.build()?;
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
match event {
Event::NewEvents(StartCause::Init) => println!("Wry has started!"),
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => *control_flow = ControlFlow::Exit,
Event::WindowEvent {
event: WindowEvent::Resized(size),
..
} => {
//let _ = webview.resize();
// @Bug: always reports PhysicalSize { width: 1600, height: 1200 }
println!("{:?}", size);
println!("{:?}", webview.window().inner_size());
println!("");
},
_ => {}
}
});
}
Expected behavior
size and webview.window().inner_size() both should return the correct window dimensions during and after resize.
Screenshots
https://user-images.githubusercontent.com/5448363/153300226-34b10913-3487-42d6-b5b7-d49b95ecb09a.mov
Platform and Versions (please complete the following information): OS: MacOS Version 10.14.6 (18G103) Rustc: rustc 1.46.0, rustc 1.60.0-nightly (0c292c966 2022-02-08)
Would you assign yourself to resolve this bug?
- [ ] Yes
- [x] No
Additional context
N/A
This is a known issue, and that's why we provide webview.inner_size() to get the correct value.
Nice to have a workaround, but as a known issue is there a known way to fix it? Willing to look into it and submit a PR..
thanks @progrium, here is the original issue https://github.com/tauri-apps/wry/issues/384 , now I am not a macOS developer but seems like we would need a way to set the private nsview field in tao for everything to magically work? but it might not work because in the future we might support multiple webviews in one window.
cc @wusyong