Skip to main content

Module external_dnd

Module external_dnd 

Source
Expand description

External (OS) drag-and-drop service.

Lets a window accept drops that originate outside the application — files dragged from the file manager, or text / URLs dragged from another app — and feed them into the same drag pipeline used for in-app drags (teksilo_core::WidgetTree::begin_external_drag et al.).

Three concerns are separated, mirroring crate::file_dialog:

§Why raw platform backends

winit’s DroppedFile / HoveredFile events carry no cursor position, support files only, and are unimplemented on Wayland. A drop-zone widget placed inside a layout needs the drop position to hit-test which zone received the drop, so the real backends sit below winit on the raw platform APIs (OLE IDropTarget on Windows, NSDraggingDestination on macOS, wl_data_device on Wayland, XDND on X11), all of which provide position and arbitrary data formats. NoopExternalDndBackend is left for targets with no drop-target implementation at all.

§Threading

The macOS and Windows drop targets deliver their callbacks on the UI thread; the Wayland and X11 backends run a dedicated per-window dispatch thread on their own protocol connection. Either way the payload is routed through teksilo_core::AppEventPoster::post_external (the same channel as file dialogs) so the borrow of the window’s tree happens in one well-defined place in the event loop rather than re-entrantly inside a platform callback — and so a backend thread never touches the tree at all.

Structs§

ExternalDndEventPayload
Boxed inside AppEvent::External when a backend reports a drag phase. teksilo-app’s app-event handler downcasts to this type and routes the ExternalDragEvent to the originating window’s WidgetTree.
ExternalDndHandle
Per-app external-drag service. Registered in app-state by TeksiloAppBuilder::install_external_dnd; teksilo-app calls Self::attach / Self::detach from its window lifecycle hooks. Cloneable; clones share the same backend and guard map.
MemoryDndGuard
Guard that removes the window’s attachment record on drop, so ExternalDndHandle::detach is observable in tests via MemoryExternalDndBackend::attached_windows.
MemoryExternalDndBackend
In-memory backend for headless tests. Records the (window_id, poster) of each attached window so a test can synthesize OS drag phases via Self::emit, which posts an ExternalDndEventPayload exactly as a real backend would. Cloneable — clones share the same recording, so a test can keep a clone after handing one to ExternalDndHandle::new.
NoopDndGuard
A guard that does nothing on drop. Used by NoopExternalDndBackend and by backends whose registration needs no explicit teardown.
NoopExternalDndBackend
Backend that registers nothing and never emits events. Used on X11 and any target without a raw drop-target implementation. External OS drops simply don’t fire; a DropZone widget stays usable via its keyboard “Browse…” fallback button.
OutboundOsDragRequest
Posted by a backend whose outbound (app → OS) drag is blocking (Windows OLE DoDragDrop runs its own modal message loop) so it can be run OUTSIDE the in-app event dispatch that started it. ExternalDndGuard::begin_drag stashes the payload, posts this, and returns true; teksilo-app’s AppEvent::External arm downcasts it and calls ExternalDndHandle::run_pending_outbound_drag on the next loop turn — a point where no window is borrowed out of the manager, mirroring how inbound drag events route through the poster rather than re-entrantly inside a platform callback. Non-blocking backends (macOS / Wayland) never post this.

Enums§

ExternalDragEvent
One phase of an external (OS) drag over a window. Positions are in the window’s logical coordinate space (top-left origin), already converted from the platform’s native coordinates.

Traits§

ExternalDndBackend
Swappable external-drag backend. One backend instance serves the whole app; Self::attach is called once per window.
ExternalDndGuard
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.

Functions§

default_backend
The default external-drag backend for the current target.