Skip to content

Commit

Permalink
fix(windows): ignore resize events when minimized (#978)
Browse files Browse the repository at this point in the history
* fix(windows): Ignore resize events when minimized

* Update ignore-resize-when-minimized-windows.md

---------

Co-authored-by: ahodesuka <ahodesuka@users.noreply.github.com>
  • Loading branch information
ahodesuka and ahodesuka committed Jun 26, 2023
1 parent 4ab2a45 commit 87b331a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changes/ignore-resize-when-minimized-windows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

On Windows, avoid resizing the webview when the window gets minimized to avoid unnecessary `resize` event on JS side.
20 changes: 11 additions & 9 deletions src/webview/webview2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,15 +743,17 @@ window.addEventListener('mousemove', (e) => window.chrome.webview.postMessage('_
) -> LRESULT {
match msg {
win32wm::WM_SIZE => {
let controller = dwrefdata as *mut ICoreWebView2Controller;
let mut client_rect = RECT::default();
win32wm::GetClientRect(hwnd, &mut client_rect);
let _ = (*controller).SetBounds(RECT {
left: 0,
top: 0,
right: client_rect.right - client_rect.left,
bottom: client_rect.bottom - client_rect.top,
});
if wparam.0 != win32wm::SIZE_MINIMIZED as usize {
let controller = dwrefdata as *mut ICoreWebView2Controller;
let mut client_rect = RECT::default();
win32wm::GetClientRect(hwnd, &mut client_rect);
let _ = (*controller).SetBounds(RECT {
left: 0,
top: 0,
right: client_rect.right - client_rect.left,
bottom: client_rect.bottom - client_rect.top,
});
}
}

win32wm::WM_SETFOCUS | win32wm::WM_ENTERSIZEMOVE => {
Expand Down

0 comments on commit 87b331a

Please sign in to comment.