Skip to content

Commit bea3f51

Browse files
committed
fix: drag source fixes
1 parent 6f6c24b commit bea3f51

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

native/src/widget/dnd_source.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<'a, Message, Renderer> DndSource<'a, Message, Renderer> {
108108
on_finished: None,
109109
on_dropped: None,
110110
on_selection_action: None,
111-
drag_threshold: 5.0,
111+
drag_threshold: 25.0,
112112
handle_captured_events: true,
113113
}
114114
}
@@ -249,6 +249,22 @@ where
249249
}
250250

251251
let mut state = tree.state.downcast_mut::<State>();
252+
253+
if matches!(
254+
event,
255+
Event::PlatformSpecific(event::PlatformSpecific::Wayland(
256+
event::wayland::Event::Seat(
257+
event::wayland::SeatEvent::Leave,
258+
_
259+
)
260+
)) | Event::Mouse(mouse::Event::ButtonReleased(
261+
mouse::Button::Left
262+
)) | Event::Touch(touch::Event::FingerLifted { .. })
263+
| Event::Touch(touch::Event::FingerLost { .. })
264+
) {
265+
state.left_pressed_position = None;
266+
return event::Status::Captured;
267+
}
252268

253269
if state.is_dragging {
254270
if let Event::PlatformSpecific(event::PlatformSpecific::Wayland(
@@ -302,7 +318,10 @@ where
302318
}
303319
}
304320

305-
if !layout.bounds().contains(cursor_position) {
321+
if cursor_position.x > 0.0
322+
&& cursor_position.y > 0.0
323+
&& !layout.bounds().contains(cursor_position)
324+
{
306325
// XXX if the widget is not hovered but the mouse is pressed,
307326
// we are triggering on_drag
308327
if let (Some(on_drag), Some(_)) =
@@ -319,6 +338,9 @@ where
319338
if let (Some(on_drag), Some(pressed_pos)) =
320339
(self.on_drag.clone(), state.left_pressed_position.clone())
321340
{
341+
if cursor_position.x < 0.0 || cursor_position.y < 0.0 {
342+
return captured;
343+
}
322344
let distance = (cursor_position.x - pressed_pos.x).powi(2)
323345
+ (cursor_position.y - pressed_pos.y).powi(2);
324346
if distance > self.drag_threshold {

0 commit comments

Comments
 (0)