diff --git a/CHANGELOG.md b/CHANGELOG.md index 65bd9502..4aa0b6de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ And please only add new entries to the top of this list, right below the `# Unre - On Web, implement `Window::focus_window()`. - On Web, remove unnecessary `Window::is_dark_mode()`, which was replaced with `Window::theme()`. - On Web, add `WindowBuilderExtWebSys::with_append()` to append the canvas element to the web page on creation. +- On Windows, add `drag_resize_window` method support. # 0.29.0-beta.0 diff --git a/FEATURES.md b/FEATURES.md index 10db04dc..9e859d89 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -217,7 +217,7 @@ Legend: |Gamepad/Joystick events |❌[#804] |❌ |❌ |❌ |❌ |❌ |❓ |**N/A** | |Device movement events |❓ |❓ |❓ |❓ |❌ |❌ |❓ |**N/A** | |Drag window with cursor |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|**N/A** |**N/A** | -|Resize with cursor |❌ |❌ |✔️ |❌ |**N/A**|**N/A**|**N/A** |**N/A** | +|Resize with cursor |✔️ |❌ |✔️ |✔️ |**N/A**|**N/A**|**N/A** |**N/A** | ### Pending API Reworks Changes in the API that have been agreed upon but aren't implemented across all platforms. diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index fc4543e7..ff07b8eb 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -46,7 +46,8 @@ use windows_sys::Win32::{ IsWindowVisible, LoadCursorW, PeekMessageW, PostMessageW, RegisterClassExW, SetCursor, SetCursorPos, SetForegroundWindow, SetWindowDisplayAffinity, SetWindowPlacement, SetWindowPos, SetWindowTextW, CS_HREDRAW, CS_VREDRAW, CW_USEDEFAULT, FLASHWINFO, - FLASHW_ALL, FLASHW_STOP, FLASHW_TIMERNOFG, FLASHW_TRAY, GWLP_HINSTANCE, HTCAPTION, + FLASHW_ALL, FLASHW_STOP, FLASHW_TIMERNOFG, FLASHW_TRAY, GWLP_HINSTANCE, HTBOTTOM, + HTBOTTOMLEFT, HTBOTTOMRIGHT, HTCAPTION, HTLEFT, HTRIGHT, HTTOP, HTTOPLEFT, HTTOPRIGHT, NID_READY, PM_NOREMOVE, SM_DIGITIZER, SWP_ASYNCWINDOWPOS, SWP_NOACTIVATE, SWP_NOSIZE, SWP_NOZORDER, WDA_EXCLUDEFROMCAPTURE, WDA_NONE, WM_NCLBUTTONDOWN, WNDCLASSEXW, }, @@ -410,36 +411,53 @@ impl Window { Ok(()) } + unsafe fn handle_os_dragging(&self, wparam: WPARAM) { + let points = { + let mut pos = mem::zeroed(); + GetCursorPos(&mut pos); + pos + }; + let points = POINTS { + x: points.x as i16, + y: points.y as i16, + }; + ReleaseCapture(); + + self.window_state_lock().dragging = true; + + PostMessageW( + self.hwnd(), + WM_NCLBUTTONDOWN, + wparam, + &points as *const _ as LPARAM, + ); + } + #[inline] pub fn drag_window(&self) -> Result<(), ExternalError> { unsafe { - let points = { - let mut pos = mem::zeroed(); - GetCursorPos(&mut pos); - pos - }; - let points = POINTS { - x: points.x as i16, - y: points.y as i16, - }; - ReleaseCapture(); - - self.window_state_lock().dragging = true; - - PostMessageW( - self.hwnd(), - WM_NCLBUTTONDOWN, - HTCAPTION as WPARAM, - &points as *const _ as LPARAM, - ); + self.handle_os_dragging(HTCAPTION as WPARAM); } Ok(()) } #[inline] - pub fn drag_resize_window(&self, _direction: ResizeDirection) -> Result<(), ExternalError> { - Err(ExternalError::NotSupported(NotSupportedError::new())) + pub fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), ExternalError> { + unsafe { + self.handle_os_dragging(match direction { + ResizeDirection::East => HTRIGHT, + ResizeDirection::North => HTTOP, + ResizeDirection::NorthEast => HTTOPRIGHT, + ResizeDirection::NorthWest => HTTOPLEFT, + ResizeDirection::South => HTBOTTOM, + ResizeDirection::SouthEast => HTBOTTOMRIGHT, + ResizeDirection::SouthWest => HTBOTTOMLEFT, + ResizeDirection::West => HTLEFT, + } as WPARAM); + } + + Ok(()) } #[inline] diff --git a/src/window.rs b/src/window.rs index 0353b56e..40d43c58 100644 --- a/src/window.rs +++ b/src/window.rs @@ -1299,7 +1299,8 @@ impl Window { /// /// ## Platform-specific /// - /// Only X11 is supported at this time. + /// - **macOS:** Always returns an [`ExternalError::NotSupported`] + /// - **iOS / Android / Web / Orbital:** Always returns an [`ExternalError::NotSupported`]. #[inline] pub fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), ExternalError> { self.window.drag_resize_window(direction)