From 10df7b5eb904ef2930e9b1aadc421adff9b91188 Mon Sep 17 00:00:00 2001 From: Smit Barmase Date: Wed, 4 Jun 2025 06:53:03 +0530 Subject: [PATCH] gpui: Add API for read and write active drag cursor style (#32028) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prep for https://github.com/zed-industries/zed/pull/32040 Currently, there’s no way to modify the cursor style of the active drag state after dragging begins. However, there are scenarios where we might want to change the cursor style, such as pressing a modifier key while dragging. This PR introduces an API to update and read the current active drag state cursor. Release Notes: - N/A --- crates/gpui/src/app.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index dc9fa0ced34c14c60bedf38e533e603fc97c07d2..e6d5fb9e48eea9b14f440ea77dc5d0354ad1d9e6 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -1559,6 +1559,11 @@ impl App { self.active_drag.is_some() } + /// Gets the cursor style of the currently active drag operation. + pub fn active_drag_cursor_style(&self) -> Option { + self.active_drag.as_ref().and_then(|drag| drag.cursor_style) + } + /// Stops active drag and clears any related effects. pub fn stop_active_drag(&mut self, window: &mut Window) -> bool { if self.active_drag.is_some() { @@ -1570,6 +1575,21 @@ impl App { } } + /// Sets the cursor style for the currently active drag operation. + pub fn set_active_drag_cursor_style( + &mut self, + cursor_style: CursorStyle, + window: &mut Window, + ) -> bool { + if let Some(ref mut drag) = self.active_drag { + drag.cursor_style = Some(cursor_style); + window.refresh(); + true + } else { + false + } + } + /// Set the prompt renderer for GPUI. This will replace the default or platform specific /// prompts with this custom implementation. pub fn set_prompt_builder(