From c193e2a04c369b7699cd0d73049e84b6851b5c06 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Sat, 9 Nov 2024 03:14:14 +0200 Subject: [PATCH] fix(linux): fix `DragDropEvent::Drop` never fired on wayland (#1408) * fix(linux): fix `DragDrop` never fired on wayland closes tauri-apps/tauri#11282 * Update src/webkitgtk/drag_drop.rs --- .changes/drag-drop-wayland.md | 5 +++++ src/webkitgtk/drag_drop.rs | 41 +++++++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 .changes/drag-drop-wayland.md diff --git a/.changes/drag-drop-wayland.md b/.changes/drag-drop-wayland.md new file mode 100644 index 000000000..a9a4593f9 --- /dev/null +++ b/.changes/drag-drop-wayland.md @@ -0,0 +1,5 @@ +--- +"wry": "patch" +--- + +Fix `DragDropEvent::Drop` event never fired on Wayland (and sometimes on X11). diff --git a/src/webkitgtk/drag_drop.rs b/src/webkitgtk/drag_drop.rs index 4f81dae70..513371330 100644 --- a/src/webkitgtk/drag_drop.rs +++ b/src/webkitgtk/drag_drop.rs @@ -13,9 +13,16 @@ use webkit2gtk::WebView; use crate::DragDropEvent; +#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)] +enum DragControllerState { + Entered, + Leaving, + Left, +} + struct DragDropController { paths: UnsafeCell>>, - has_entered: Cell, + state: Cell, position: Cell<(i32, i32)>, handler: Box bool>, } @@ -25,7 +32,7 @@ impl DragDropController { Self { handler, paths: UnsafeCell::new(None), - has_entered: Cell::new(false), + state: Cell::new(DragControllerState::Left), position: Cell::new((0, 0)), } } @@ -43,15 +50,19 @@ impl DragDropController { } fn enter(&self) { - self.has_entered.set(true); + self.state.set(DragControllerState::Entered); } - fn has_entered(&self) -> bool { - self.has_entered.get() + fn leaving(&self) { + self.state.set(DragControllerState::Leaving); } fn leave(&self) { - self.has_entered.set(false); + self.state.set(DragControllerState::Left); + } + + fn state(&self) -> DragControllerState { + self.state.get() } fn call(&self, event: DragDropEvent) -> bool { @@ -81,7 +92,7 @@ pub(crate) fn connect_drag_event(webview: &WebView, handler: Box