gpui_windows: Report the global cursor state for drag tracking

Implement Platform::global_cursor_state with GetCursorPos scaled by the
DPI of the monitor under the cursor, and the left button state from
GetAsyncKeyState, so drags released outside every window reach the
tear-off handler on Windows too.
This commit is contained in:
yenru0 committed 2026-10-16 16:55:38 +09:00
1 parent b3cca826c8
commit 66e2a957d9
2 files changed
+22 -1

No files matched your search

+1 -1
View File
@@ -201,7 +201,7 @@ fn generate_uuid(device_name: &[u16]) -> Uuid {
Uuid::new_v5(&Uuid::NAMESPACE_DNS, &name)
}
fn get_scale_factor_for_monitor(monitor: HMONITOR) -> Result<f32> {
pub(crate) fn get_scale_factor_for_monitor(monitor: HMONITOR) -> Result<f32> {
let mut dpi_x = 0;
let mut dpi_y = 0;
unsafe { GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &mut dpi_x, &mut dpi_y) }?;
+21
View File
@@ -636,6 +636,27 @@ impl Platform for WindowsPlatform {
.map(|inner| inner.handle)
}
fn global_cursor_state(&self) -> Option<GlobalCursorState> {
let mut point: POINT = unsafe { std::mem::zeroed() };
unsafe { GetCursorPos(&mut point) }
.context("unable to get cursor position")
.log_err()?;
let scale_factor = unsafe {
let monitor = MonitorFromPoint(point, MONITOR_DEFAULTTONEAREST);
if monitor.is_invalid() {
1.0
} else {
get_scale_factor_for_monitor(monitor).log_err()?
}
};
let left_button_pressed =
unsafe { GetAsyncKeyState(VK_LBUTTON.0 as i32) } as u16 & 0x8000 != 0;
Some(GlobalCursorState {
position: logical_point(point.x as f32, point.y as f32, scale_factor),
left_button_pressed,
})
}
fn open_window(
&self,
handle: AnyWindowHandle,