Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(windows): Enable native resizing on undecorated windows with shadows #905

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
23 changes: 21 additions & 2 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -2121,9 +2122,27 @@ unsafe fn public_window_callback_inner<T: 'static>(
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
}
Expand Down
18 changes: 18 additions & 0 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PhysicalPosition<i32>, NotSupportedError> {
unsafe { util::get_window_rect(self.window.0) }
Expand Down
2 changes: 2 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ impl WindowBuilder {
) -> Result<Window, OsError> {
platform_impl::Window::new(&window_target.p, self.window, self.platform_specific).map(
|window| {
#[cfg(windows)]
window.request_nccalcsize();
window.request_redraw();
Window { window }
},
Expand Down
Loading