On Windows, add drag_resize_window method support (#2966)

This commit is contained in:
Venceslas Duet
2023-07-21 20:01:56 +02:00
committed by Kirill Chibisov
parent 0efcfaf5a9
commit afebe2e7d1
4 changed files with 44 additions and 24 deletions

View File

@@ -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, implement `Window::focus_window()`.
- On Web, remove unnecessary `Window::is_dark_mode()`, which was replaced with `Window::theme()`. - 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 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 # 0.29.0-beta.0

View File

@@ -217,7 +217,7 @@ Legend:
|Gamepad/Joystick events |❌[#804] |❌ |❌ |❌ |❌ |❌ |❓ |**N/A** | |Gamepad/Joystick events |❌[#804] |❌ |❌ |❌ |❌ |❌ |❓ |**N/A** |
|Device movement events |❓ |❓ |❓ |❓ |❌ |❌ |❓ |**N/A** | |Device movement events |❓ |❓ |❓ |❓ |❌ |❌ |❓ |**N/A** |
|Drag window with cursor |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|**N/A** |**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 ### Pending API Reworks
Changes in the API that have been agreed upon but aren't implemented across all platforms. Changes in the API that have been agreed upon but aren't implemented across all platforms.

View File

@@ -46,7 +46,8 @@ use windows_sys::Win32::{
IsWindowVisible, LoadCursorW, PeekMessageW, PostMessageW, RegisterClassExW, SetCursor, IsWindowVisible, LoadCursorW, PeekMessageW, PostMessageW, RegisterClassExW, SetCursor,
SetCursorPos, SetForegroundWindow, SetWindowDisplayAffinity, SetWindowPlacement, SetCursorPos, SetForegroundWindow, SetWindowDisplayAffinity, SetWindowPlacement,
SetWindowPos, SetWindowTextW, CS_HREDRAW, CS_VREDRAW, CW_USEDEFAULT, FLASHWINFO, 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, NID_READY, PM_NOREMOVE, SM_DIGITIZER, SWP_ASYNCWINDOWPOS, SWP_NOACTIVATE, SWP_NOSIZE,
SWP_NOZORDER, WDA_EXCLUDEFROMCAPTURE, WDA_NONE, WM_NCLBUTTONDOWN, WNDCLASSEXW, SWP_NOZORDER, WDA_EXCLUDEFROMCAPTURE, WDA_NONE, WM_NCLBUTTONDOWN, WNDCLASSEXW,
}, },
@@ -410,36 +411,53 @@ impl Window {
Ok(()) 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] #[inline]
pub fn drag_window(&self) -> Result<(), ExternalError> { pub fn drag_window(&self) -> Result<(), ExternalError> {
unsafe { unsafe {
let points = { self.handle_os_dragging(HTCAPTION as WPARAM);
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,
);
} }
Ok(()) Ok(())
} }
#[inline] #[inline]
pub fn drag_resize_window(&self, _direction: ResizeDirection) -> Result<(), ExternalError> { pub fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), ExternalError> {
Err(ExternalError::NotSupported(NotSupportedError::new())) 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] #[inline]

View File

@@ -1299,7 +1299,8 @@ impl Window {
/// ///
/// ## Platform-specific /// ## 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] #[inline]
pub fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), ExternalError> { pub fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), ExternalError> {
self.window.drag_resize_window(direction) self.window.drag_resize_window(direction)