diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index d7ab42f06..e88c4a4ab 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -23,7 +23,8 @@ use windows::{ core::{s, PCWSTR}, Win32::{ Foundation::{ - BOOL, HANDLE, HINSTANCE, HMODULE, HWND, LPARAM, LRESULT, POINT, RECT, WAIT_TIMEOUT, WPARAM, + BOOL, FALSE, HANDLE, HINSTANCE, HMODULE, HWND, LPARAM, LRESULT, POINT, RECT, WAIT_TIMEOUT, + WPARAM, }, Graphics::Gdi::*, System::{ @@ -2121,9 +2122,27 @@ unsafe fn public_window_callback_inner( params.rgrc[0] = rect; } } else if window_flags.contains(WindowFlags::MARKER_UNDECORATED_SHADOW) { + let mut rect = RECT::default(); + if AdjustWindowRectEx( + &mut rect, + WINDOW_STYLE((GetWindowLongPtrW(window, GWL_STYLE) & !(WS_CAPTION.0 as isize)) as u32), + FALSE, + WINDOW_EX_STYLE::default(), + ) + .is_ok() + { + rect.left *= -1; + rect.top *= -1; + } else { + // As a fallback value, this keeps the shadow border but disables the resizing. + rect.bottom = -1; + } + let params = &mut *(lparam.0 as *mut NCCALCSIZE_PARAMS); params.rgrc[0].top += 1; - params.rgrc[0].bottom += 1; + params.rgrc[0].left += rect.left; + params.rgrc[0].right -= rect.right; + params.rgrc[0].bottom -= rect.bottom; } result = ProcResult::Value(LRESULT(0)); // return 0 here to make the window borderless } diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index d78ee1b42..3069452ef 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -182,6 +182,24 @@ impl Window { } } + #[inline] + pub(crate) fn request_nccalcsize(&self) { + unsafe { + let mut rect = RECT::default(); + if GetWindowRect(self.window.0, &mut rect).is_ok() { + let _ = SetWindowPos( + self.window.0, + HWND::default(), + rect.left, + rect.top, + rect.right - rect.left, + rect.bottom - rect.top, + SWP_FRAMECHANGED, + ); + } + } + } + #[inline] pub fn outer_position(&self) -> Result, NotSupportedError> { unsafe { util::get_window_rect(self.window.0) } diff --git a/src/window.rs b/src/window.rs index 1a59e5c76..50ed643ff 100644 --- a/src/window.rs +++ b/src/window.rs @@ -556,6 +556,8 @@ impl WindowBuilder { ) -> Result { platform_impl::Window::new(&window_target.p, self.window, self.platform_specific).map( |window| { + #[cfg(windows)] + window.request_nccalcsize(); window.request_redraw(); Window { window } },