Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/fix-dpi-leak-hdc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
tauri-runtime-wry: patch:bug
---

Fix getting the DPI internally leaks `HDC` handles on Windows. This also improves the resizing speed on undecorated windows
12 changes: 7 additions & 5 deletions crates/tauri-runtime-wry/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ mod imp {

#[allow(non_snake_case)]
pub unsafe fn hwnd_dpi(hwnd: HWND) -> u32 {
let hdc = GetDC(Some(hwnd));
if hdc.is_invalid() {
return USER_DEFAULT_SCREEN_DPI;
}
if let Some(GetDpiForWindow) = *GET_DPI_FOR_WINDOW {
// We are on Windows 10 Anniversary Update (1607) or later.
match GetDpiForWindow(hwnd) {
Expand All @@ -95,9 +91,15 @@ mod imp {
} else {
// We are on Vista or later.
if IsProcessDPIAware().as_bool() {
let hdc = GetDC(Some(hwnd));
if hdc.is_invalid() {
return USER_DEFAULT_SCREEN_DPI;
}
// If the process is DPI aware, then scaling must be handled by the application using
// this DPI value.
GetDeviceCaps(Some(hdc), LOGPIXELSX) as u32
let dpi = GetDeviceCaps(Some(hdc), LOGPIXELSX) as u32;
ReleaseDC(Some(hwnd), hdc);
dpi
} else {
// If the process is DPI unaware, then scaling is performed by the OS; we thus return
// 96 (scale factor 1.0) to prevent the window from being re-scaled by both the
Expand Down
Loading