mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 13:51:30 +11:00
On Windows, add drag_resize_window
method support (#2966)
This commit is contained in:
parent
f7a84a5b50
commit
c62e64060b
|
@ -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
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue