Skip to content

Commit 2c34623

Browse files
fix on windows
1 parent 45d9351 commit 2c34623

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

desktop/src/window/win/native_handle.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ unsafe fn ensure_helper_class() {
211211
unsafe extern "system" fn main_window_handle_message(hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> LRESULT {
212212
if msg == WM_NCCALCSIZE && wparam.0 != 0 {
213213
// When maximized, shrink to visible frame so content doesn't extend beyond it.
214-
if unsafe { IsZoomed(hwnd).as_bool() } {
214+
if unsafe { IsZoomed(hwnd).as_bool() } && !is_effectively_fullscreen(hwnd) {
215215
let params = unsafe { &mut *(lparam.0 as *mut NCCALCSIZE_PARAMS) };
216216

217217
let dpi = unsafe { GetDpiForWindow(hwnd) };
@@ -366,3 +366,36 @@ unsafe fn calculate_resize_direction(helper: HWND, lparam: LPARAM) -> Option<u32
366366
_ => None,
367367
}
368368
}
369+
370+
// Check if the window is effectively fullscreen, meaning it covers the entire monitor.
371+
// We need to use this heuristic because Windows doesn't provide a way to check for fullscreen state.
372+
fn is_effectively_fullscreen(hwnd: HWND) -> bool {
373+
if hwnd.is_invalid() {
374+
return false;
375+
}
376+
377+
let mut view_rect = RECT::default();
378+
if unsafe { GetWindowRect(hwnd, &mut view_rect) }.is_err() {
379+
return false;
380+
}
381+
382+
let hmon = unsafe { MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST) };
383+
if hmon.is_invalid() {
384+
return false;
385+
}
386+
387+
let mut monitor_info = MONITORINFO {
388+
cbSize: std::mem::size_of::<MONITORINFO>() as u32,
389+
..Default::default()
390+
};
391+
if !unsafe { GetMonitorInfoW(hmon, &mut monitor_info) }.as_bool() {
392+
return false;
393+
}
394+
395+
// Allow a tiny tolerance for DPI / rounding issues
396+
const EPS: i32 = 1;
397+
(view_rect.left - monitor_info.rcMonitor.left).abs() <= EPS
398+
&& (view_rect.top - monitor_info.rcMonitor.top).abs() <= EPS
399+
&& (view_rect.right - monitor_info.rcMonitor.right).abs() <= EPS
400+
&& (view_rect.bottom - monitor_info.rcMonitor.bottom).abs() <= EPS
401+
}

0 commit comments

Comments
 (0)