diff --git a/examples/dnd.rs b/examples/dnd.rs index 5a659937c62..8a79231d6ce 100644 --- a/examples/dnd.rs +++ b/examples/dnd.rs @@ -42,9 +42,9 @@ impl ApplicationHandler for Application { event: WindowEvent, ) { match event { - WindowEvent::DragLeave - | WindowEvent::DragEnter { .. } - | WindowEvent::DragOver { .. } + WindowEvent::DragLeft + | WindowEvent::DragEntered { .. } + | WindowEvent::DragMoved { .. } | WindowEvent::DragDrop { .. } => { println!("{:?}", event); }, diff --git a/examples/window.rs b/examples/window.rs index 54572721701..cab94268755 100644 --- a/examples/window.rs +++ b/examples/window.rs @@ -541,11 +541,11 @@ impl ApplicationHandler for Application { info!("Smart zoom"); }, WindowEvent::TouchpadPressure { .. } - | WindowEvent::DragLeave + | WindowEvent::DragLeft | WindowEvent::KeyboardInput { .. } | WindowEvent::PointerEntered { .. } - | WindowEvent::DragEnter { .. } - | WindowEvent::DragOver { .. } + | WindowEvent::DragEntered { .. } + | WindowEvent::DragMoved { .. } | WindowEvent::DragDrop { .. } | WindowEvent::Destroyed | WindowEvent::Moved(_) => (), diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 9c423fe0f34..0933953e6ae 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -167,8 +167,8 @@ changelog entry. - Reworked the file drag-and-drop API. The `WindowEvent::DroppedFile`, `WindowEvent::HoveredFile` and `WindowEvent::HoveredFileCancelled` - events have been removed, and replaced with `WindowEvent::DragEnter`, `WindowEvent::DragOver`, - `WindowEvent::DragDrop` and `WindowEvent::DragLeave`. + events have been removed, and replaced with `WindowEvent::DragEntered`, `WindowEvent::DragMoved`, + `WindowEvent::DragDrop` and `WindowEvent::DragLeft`. The old drag-and-drop events were emitted once per file. This occurred when files were *first* hovered over the window, dropped, or left the window. The new drag-and-drop events are emitted @@ -176,11 +176,11 @@ changelog entry. pointer position. The rough correspondence is: - - `WindowEvent::HoveredFile` -> `WindowEvent::DragEnter` + - `WindowEvent::HoveredFile` -> `WindowEvent::DragEntered` - `WindowEvent::DroppedFile` -> `WindowEvent::DragDrop` - - `WindowEvent::HoveredFileCancelled` -> `WindowEvent::DragLeave` + - `WindowEvent::HoveredFileCancelled` -> `WindowEvent::DragLeft` - The `WindowEvent::DragOver` event is entirely new, and is emitted whenever the pointer moves + The `WindowEvent::DragMoved` event is entirely new, and is emitted whenever the pointer moves whilst files are being dragged over the window. It doesn't contain any file paths, just the pointer position. diff --git a/src/event.rs b/src/event.rs index da238d959c0..f913407d605 100644 --- a/src/event.rs +++ b/src/event.rs @@ -176,30 +176,33 @@ pub enum WindowEvent { Destroyed, /// A drag operation has entered the window. - DragEnter { + DragEntered { /// List of paths that are being dragged onto the window. paths: Vec, - /// Position of the drag operation. May be negative on some platforms if something is - /// dragged over a window's decorations (title bar, frame, etc). + /// (x,y) coordinates in pixels relative to the top-left corner of the window. May be + /// negative on some platforms if something is dragged over a window's decorations (title + /// bar, frame, etc). position: PhysicalPosition, }, - /// A drag operation is moving over the window. - DragOver { - /// Position of the drag operation. May be negative on some platforms if something is - /// dragged over a window's decorations (title bar, frame, etc). + /// A drag operation has moved over the window. + DragMoved { + /// (x,y) coordinates in pixels relative to the top-left corner of the window. May be + /// negative on some platforms if something is dragged over a window's decorations (title + /// bar, frame, etc). position: PhysicalPosition, }, /// The drag operation has dropped file(s) on the window. DragDrop { /// List of paths that are being dragged onto the window. paths: Vec, - /// Position of the drag operation. May be negative on some platforms if something is - /// dragged over a window's decorations (title bar, frame, etc). + /// (x,y) coordinates in pixels relative to the top-left corner of the window. May be + /// negative on some platforms if something is dragged over a window's decorations (title + /// bar, frame, etc). position: PhysicalPosition, }, /// The drag operation has been cancelled or left the window. On some platforms, this may occur /// even if no other drag events have occurred. - DragLeave, + DragLeft, /// The window gained or lost focus. /// @@ -1224,16 +1227,16 @@ mod tests { with_window_event(Focused(true)); with_window_event(Moved((0, 0).into())); with_window_event(SurfaceResized((0, 0).into())); - with_window_event(DragEnter { + with_window_event(DragEntered { paths: vec!["x.txt".into()], position: (0, 0).into(), }); - with_window_event(DragOver { position: (0, 0).into() }); + with_window_event(DragMoved { position: (0, 0).into() }); with_window_event(DragDrop { paths: vec!["x.txt".into()], position: (0, 0).into(), }); - with_window_event(DragLeave); + with_window_event(DragLeft); with_window_event(Ime(Enabled)); with_window_event(PointerMoved { device_id: None, diff --git a/src/platform_impl/apple/appkit/window_delegate.rs b/src/platform_impl/apple/appkit/window_delegate.rs index 8edc24e6e63..7339911c300 100644 --- a/src/platform_impl/apple/appkit/window_delegate.rs +++ b/src/platform_impl/apple/appkit/window_delegate.rs @@ -393,7 +393,7 @@ declare_class!( let position = LogicalPosition::::from((dl.x, dl.y)).to_physical(self.scale_factor()); - self.queue_event(WindowEvent::DragEnter { paths, position }); + self.queue_event(WindowEvent::DragEntered { paths, position }); true } @@ -413,7 +413,7 @@ declare_class!( let dl = self.view().convertPoint_fromView(dl, None); let position = LogicalPosition::::from((dl.x, dl.y)).to_physical(self.scale_factor()); - self.queue_event(WindowEvent::DragOver { position }); + self.queue_event(WindowEvent::DragMoved { position }); true } @@ -459,7 +459,7 @@ declare_class!( #[method(draggingExited:)] fn dragging_exited(&self, _sender: Option<&NSObject>) { trace_scope!("draggingExited:"); - self.queue_event(WindowEvent::DragLeave); + self.queue_event(WindowEvent::DragLeft); } } diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index 6e4c1e26c0d..5de5b8e9235 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -561,7 +561,7 @@ impl EventProcessor { if xev.message_type == atoms[XdndLeave] as c_ulong { if self.dnd.has_entered { - let event = Event::WindowEvent { window_id, event: WindowEvent::DragLeave }; + let event = Event::WindowEvent { window_id, event: WindowEvent::DragLeft }; callback(&self.target, event); } self.dnd.reset(); @@ -593,14 +593,14 @@ impl EventProcessor { if self.dnd.has_entered { callback(&self.target, Event::WindowEvent { window_id, - event: WindowEvent::DragOver { position: self.dnd.position }, + event: WindowEvent::DragMoved { position: self.dnd.position }, }); } else { let paths = path_list.iter().map(Into::into).collect(); self.dnd.has_entered = true; callback(&self.target, Event::WindowEvent { window_id, - event: WindowEvent::DragEnter { paths, position: self.dnd.position }, + event: WindowEvent::DragEntered { paths, position: self.dnd.position }, }); } } diff --git a/src/platform_impl/windows/drop_handler.rs b/src/platform_impl/windows/drop_handler.rs index 515929c674a..1c772099f8b 100644 --- a/src/platform_impl/windows/drop_handler.rs +++ b/src/platform_impl/windows/drop_handler.rs @@ -27,7 +27,7 @@ pub struct FileDropHandlerData { send_event: Box, cursor_effect: u32, enter_is_valid: bool, /* If the currently hovered item is not valid there must not be any - * `DragLeave` emitted */ + * `DragLeft` emitted */ } pub struct FileDropHandler { @@ -82,7 +82,7 @@ impl FileDropHandler { pt: POINTL, pdwEffect: *mut u32, ) -> HRESULT { - use crate::event::WindowEvent::DragEnter; + use crate::event::WindowEvent::DragEntered; let drop_handler = unsafe { Self::from_interface(this) }; let mut pt = POINT { x: pt.x, y: pt.y }; unsafe { @@ -95,7 +95,7 @@ impl FileDropHandler { if drop_handler.enter_is_valid { drop_handler.send_event(Event::WindowEvent { window_id: WindowId::from_raw(drop_handler.window as usize), - event: DragEnter { paths, position }, + event: DragEntered { paths, position }, }); } drop_handler.cursor_effect = @@ -113,7 +113,7 @@ impl FileDropHandler { pt: POINTL, pdwEffect: *mut u32, ) -> HRESULT { - use crate::event::WindowEvent::DragOver; + use crate::event::WindowEvent::DragMoved; let drop_handler = unsafe { Self::from_interface(this) }; if drop_handler.enter_is_valid { let mut pt = POINT { x: pt.x, y: pt.y }; @@ -123,7 +123,7 @@ impl FileDropHandler { let position = PhysicalPosition::new(pt.x as f64, pt.y as f64); drop_handler.send_event(Event::WindowEvent { window_id: WindowId::from_raw(drop_handler.window as usize), - event: DragOver { position }, + event: DragMoved { position }, }); } unsafe { @@ -133,12 +133,12 @@ impl FileDropHandler { } pub unsafe extern "system" fn DragLeave(this: *mut IDropTarget) -> HRESULT { - use crate::event::WindowEvent::DragLeave; + use crate::event::WindowEvent::DragLeft; let drop_handler = unsafe { Self::from_interface(this) }; if drop_handler.enter_is_valid { drop_handler.send_event(Event::WindowEvent { window_id: WindowId::from_raw(drop_handler.window as usize), - event: DragLeave, + event: DragLeft, }); }