Skip to content

Commit

Permalink
fix window size is not correctly restored
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Jun 17, 2024
1 parent bd80c09 commit 7226dd7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions v2/src/wry/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,25 @@ impl WebViewRenderer {
Ok(WebViewRenderer { webview, window, zoom_level, always_on_top, menu })
}

#[cfg(not(target_os = "macos"))]
fn window_rect(&self) -> Result<(LogicalSize<f64>, LogicalPosition<f64>)> {
let scale = self.window.scale_factor();
let size = self.window.inner_size().to_logical(scale);
let pos = self.window.outer_position()?.to_logical(scale);
Ok((size, pos))
}

#[cfg(target_os = "macos")]
fn window_rect(&self) -> Result<(LogicalSize<f64>, LogicalPosition<f64>)> {
let scale = self.window.scale_factor();
// `self.window.inner_size()` does not work because `WebView` replaces `NSWindow` instance's
// `contentView` field of `self.window`.
let size = self.webview.bounds()?.size.to_logical(scale);
// `self.webview.bounds()` does not report a correct position so it needs to be obtained
// separately.
let pos = self.window.outer_position()?.to_logical(scale);
Ok((size, pos))
}
}

impl Renderer for WebViewRenderer {
Expand Down

0 comments on commit 7226dd7

Please sign in to comment.