pub trait ExternalDndGuard {
// Provided methods
fn begin_drag(
&self,
_data: &OutboundDragData,
_image: Option<&DragImageData>,
) -> bool { ... }
fn set_scale_factor(&self, _scale: f64) { ... }
fn cancel_drag(&self) { ... }
fn run_pending_outbound_drag(&self) { ... }
}Expand description
RAII guard for one window’s OS drop-target registration. Dropping it
revokes the registration (e.g. RevokeDragDrop on Windows, unregistering
the dragging destination on macOS, destroying the wl_data_device
listener on Wayland). Backends return a boxed guard from
ExternalDndBackend::attach; ExternalDndHandle holds it for the
lifetime of the window.
Provided Methods§
Sourcefn begin_drag(
&self,
_data: &OutboundDragData,
_image: Option<&DragImageData>,
) -> bool
fn begin_drag( &self, _data: &OutboundDragData, _image: Option<&DragImageData>, ) -> bool
Start a native OS drag session (app → OS, “outbound”) for this window,
exporting data and optionally drawing image as the drag cursor.
Called when an in-app drag escalates past the window boundary carrying
an OS-exportable payload.
Returns true if a native session actually started. The default is a
no-op returning false — outbound is only implemented on macOS and
Wayland; Windows / X11 / the test sink decline, and the framework then
keeps the in-app drag alive (it can come back into the window).
When the OS drag ends, the backend MUST post an
ExternalDragEvent::DragEnded through the poster captured at
ExternalDndBackend::attach.
Sourcefn set_scale_factor(&self, _scale: f64)
fn set_scale_factor(&self, _scale: f64)
Tell the backend this window’s HiDPI scale factor.
ExternalDragEvent positions are window-logical, but X11 speaks
only physical pixels and — unlike Win32’s GetDpiForWindow or AppKit’s
point space — offers no per-window scale to divide by. So the app layer
pushes winit’s own answer down: once at attach, and again on every
ScaleFactorChanged (dragging the window to a monitor with a different
scale mid-drag would otherwise start reporting drops at the wrong
place).
Default no-op: every other backend gets the scale from the OS.
Sourcefn cancel_drag(&self)
fn cancel_drag(&self)
Cancel an in-flight outbound OS drag (the user pressed Escape).
Only meaningful for backends that drive the drag themselves rather than handing it to a modal OS loop. X11 does — it tracks the pointer on its own connection — so it has no OS-level Escape handling to inherit, and without this the drag could only end by releasing the button.
The backend MUST still post the terminal
ExternalDragEvent::DragEnded exactly as it would for any other
ending, so the source widget’s on_drag_ended fires once either way.
Sourcefn run_pending_outbound_drag(&self)
fn run_pending_outbound_drag(&self)
Run a previously-requested blocking outbound drag for this window,
synchronously. Called by ExternalDndHandle::run_pending_outbound_drag
from a teksilo-app event-loop turn AFTER Self::begin_drag returned
true and stashed the payload — so a blocking platform drag loop (Windows
OLE DoDragDrop) runs outside the dispatch that started it. When it
finishes, this MUST post ExternalDragEvent::DragEnded through the
captured poster. Default no-op: non-blocking backends (macOS / Wayland)
start the session directly in begin_drag and never stash.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".