Skip to content

Commit

Permalink
feat: add position to DragLeft
Browse files Browse the repository at this point in the history
Not yet implemented on macOS
  • Loading branch information
valadaptive committed Jan 10, 2025
1 parent 242c22f commit 43d8af6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/dnd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl ApplicationHandler for Application {
event: WindowEvent,
) {
match event {
WindowEvent::DragLeft
WindowEvent::DragLeft { .. }
| WindowEvent::DragEntered { .. }
| WindowEvent::DragMoved { .. }
| WindowEvent::DragDrop { .. } => {
Expand Down
2 changes: 1 addition & 1 deletion examples/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ impl ApplicationHandler for Application {
info!("Smart zoom");
},
WindowEvent::TouchpadPressure { .. }
| WindowEvent::DragLeft
| WindowEvent::DragLeft { .. }
| WindowEvent::KeyboardInput { .. }
| WindowEvent::PointerEntered { .. }
| WindowEvent::DragEntered { .. }
Expand Down
13 changes: 11 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,16 @@ pub enum WindowEvent {
},
/// The drag operation has been cancelled or left the window. On some platforms, this may occur
/// even if no other drag events have occurred.
DragLeft,
DragLeft {
/// (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).
///
/// ## Platform-specific
///
/// - **Windows:** Always emits [`None`].
position: Option<PhysicalPosition<f64>>,
},

/// The window gained or lost focus.
///
Expand Down Expand Up @@ -1236,7 +1245,7 @@ mod tests {
paths: vec!["x.txt".into()],
position: (0, 0).into(),
});
with_window_event(DragLeft);
with_window_event(DragLeft { position: Some((0, 0).into()) });
with_window_event(Ime(Enabled));
with_window_event(PointerMoved {
device_id: None,
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/apple/appkit/window_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ declare_class!(
#[method(draggingExited:)]
fn dragging_exited(&self, _sender: Option<&NSObject>) {
trace_scope!("draggingExited:");
self.queue_event(WindowEvent::DragLeft);
self.queue_event(WindowEvent::DragLeft { position: None } );
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/platform_impl/linux/x11/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,10 @@ impl EventProcessor {

if xev.message_type == atoms[XdndLeave] as c_ulong {
if self.dnd.has_entered {
let event = Event::WindowEvent { window_id, event: WindowEvent::DragLeft };
let event = Event::WindowEvent {
window_id,
event: WindowEvent::DragLeft { position: Some(self.dnd.position) },
};
callback(&self.target, event);
}
self.dnd.reset();
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/windows/drop_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,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: DragLeft,
event: DragLeft { position: None },
});
}

Expand Down

0 comments on commit 43d8af6

Please sign in to comment.