From 66e2a957d9599537b1e77ec75cfe49c33e0659fa Mon Sep 17 00:00:00 2001 From: yenru0 Date: Fri, 16 Oct 2026 16:55:38 +0900 Subject: [PATCH] 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. --- crates/gpui_windows/src/display.rs | 2 +- crates/gpui_windows/src/platform.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/gpui_windows/src/display.rs b/crates/gpui_windows/src/display.rs index ee02309d8c..acb08d6724 100644 --- a/crates/gpui_windows/src/display.rs +++ b/crates/gpui_windows/src/display.rs @@ -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 { +pub(crate) fn get_scale_factor_for_monitor(monitor: HMONITOR) -> Result { let mut dpi_x = 0; let mut dpi_y = 0; unsafe { GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &mut dpi_x, &mut dpi_y) }?; diff --git a/crates/gpui_windows/src/platform.rs b/crates/gpui_windows/src/platform.rs index eab3b5e55c..1787c3ca42 100644 --- a/crates/gpui_windows/src/platform.rs +++ b/crates/gpui_windows/src/platform.rs @@ -636,6 +636,27 @@ impl Platform for WindowsPlatform { .map(|inner| inner.handle) } + fn global_cursor_state(&self) -> Option { + 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,