Skip to content

[0.30] Wayland: report dropped files and offer the clipboard on one data device - #4729

Open
crmne wants to merge 2 commits into
rust-windowing:v0.30.xfrom
crmne:wayland-data-device-0.30
Open

crmne wants to merge 2 commits into
rust-windowing:v0.30.xfrom
crmne:wayland-data-device-0.30

Conversation

@crmne

@crmne crmne commented Oct 3, 2026 •

Copy link
Copy Markdown

For the 0.30 maintenance branch, where eframe/egui and many other applications still are. On master, file drops landed with #4571 and the clipboard is being added on the same data device in #4658, so this is 0.30 only.

Problem

winit 0.30 reports no file drops on Wayland (#1881). Adding them means binding a wl_data_device per seat, and that alone breaks paste in many apps on Hyprland: toolkits such as egui get their clipboard from smithay-clipboard, which binds a second data device on the same connection, and Hyprland (0.56.2) sends the selection and drags only to the first data device a client creates (dataDeviceForClient). Whichever device comes second loses either paste or drops. wlroots sends the selection to every device of a client, so sway is not affected.

Fix

Two commits:

  1. File drops. Winit binds one wl_data_device per seat and accepts drags offering text/uri-list with the copy action. The list is read without blocking as soon as the drag enters a window, so the window gets HoveredFile for each local file, HoveredFileCancelled when the drag leaves, and DroppedFile for each file on drop. Actions are set only on enter: setting them again on motion restarts the negotiation and can turn a quick drop into a leave. Only file URIs for this machine become paths; the parser has unit tests.
  2. Clipboard on the same device. New platform::wayland::Clipboard, obtained with ActiveEventLoopExtWayland::clipboard(), or with Clipboard::for_display() from the wl_display pointer of a display handle for toolkits that only get the handle. It has load_text() and store_text() and works on the seat that last gave the app input (keyboard enter, key and button serials are recorded for set_selection).
    • It can be used from any thread. Reading another client's selection waits on the pipe without dispatching the event loop, and gives up after two seconds of silence.
    • Our own selection carries a private marker MIME type and is returned directly, so pasting it never waits on the event loop thread that would have to send it.
    • The compositor's send requests are answered from a short-lived thread, so a slow reader doesn't block the event loop.

Text only; images and the primary selection are out of scope.

Testing

  • cargo +nightly fmt --check; cargo test and cargo clippy --all-targets with default features and with --no-default-features --features=wayland,wayland-dlopen; X11-only build; cargo doc; build with 1.70.0 (MSRV). Clippy reports only existing lints in xkb/compose.rs and x11/event_processor.rs, none in the changed files.

  • In an egui app (with the companion egui change below) on headless compositors:

    Compositor Paste in Copy out Paste own copy Folder drop File drop
    Hyprland 0.56.2 (nested in headless KWin) yes yes yes yes yes
    mutter 50.5 yes yes yes yes not run
    sway 1.12 not run not run not run yes not run

    With the file drops but smithay-clipboard still binding its own device, the same Hyprland setup reproduces the bug: smithay-clipboard sees an empty selection and paste fails. Paste keeps working after drops in the same session with this change.

CI on v0.30.x currently fails before compiling: cargo update -p syn --precise 2.0.114 is ambiguous now that syn 3 exists (see #4692).

Downstream report: crmne/spotifast#614. The egui-winit side, which uses this clipboard instead of starting smithay-clipboard when the display belongs to a winit event loop, is emilk/egui#8657.

  • Tested on all platforms changed
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

crmne added 2 commits October 14, 2026 22:56
Winit binds a wl_data_device for each seat and accepts drags that offer
text/uri-list with the copy action. The list is read without blocking as
soon as the drag enters a window, so the window receives HoveredFile for each
local file while the drag is over it, HoveredFileCancelled when it leaves, and
DroppedFile for each file once it is dropped.

The actions are set only on enter: setting them again on motion restarts the
negotiation and can turn a quick drop into a leave. Only file URIs naming this
machine become paths.
Hyprland (0.56.2) sends the selection and drags only to the first
wl_data_device a client binds for a seat (dataDeviceForClient in
src/protocols/core/DataDevice.cpp). Winit binds one for file drops, so a
toolkit clipboard such as smithay-clipboard, which binds a second device on the
same connection, never receives the selection and paste fails everywhere. A
client should keep one data device per seat, so winit now offers the clipboard
on its own device instead.

platform::wayland::Clipboard reads and writes text on the seat that last gave
the application input. It is found from the event loop with
ActiveEventLoopExtWayland::clipboard, or from a wl_display pointer with
Clipboard::for_display, for toolkits that only receive the display handle.
Keyboard enter, key and button events record the serial that setting the
selection needs. Reading another client's selection receives it through a pipe
without dispatching the event loop and gives up after two seconds of silence.
Our own selection carries a private marker type and is returned directly, so
pasting it never waits on the thread that would have to send it. The compositor
asks for our text through the data source, and a short-lived thread writes it.
@crmne
crmne force-pushed the wayland-data-device-0.30 branch from 17aa519 to 7a962fd Compare October 14, 2026 21:16
@crmne

crmne commented Oct 14, 2026

Copy link
Copy Markdown
Author

Fixed the typos failure: a test string contained caf (from café), which the typos check flags. The test now uses naïve instead. The remaining failures are the syn lockfile step and cargo-deny findings that fail on v0.30.x itself.

crmne added a commit to crmne/egui that referenced this pull request Oct 14, 2026
Remove before merging, once a winit 0.30 release has
winit::platform::wayland::Clipboard.
@adventurelands

Copy link
Copy Markdown

A test report from an app that needs this: FilmCraft, a video editor on eframe, on Hyprland 0.56.2 (aarch64).

On winit 0.30.13, a file dragged from a GTK source onto FilmCraft imports nothing: FilmCraft gets enter, motion and leave but never a drop, because Hyprland sends drags and the selection only to the first data device a client creates. With this PR (7a962fd) pinned in, a drop imported the file 2 of 2 times, and text copy, text paste and file paste through the system clipboard all still worked, 2 of 2. The two FilmCraft PRs that work around it without this (storytold/filmcraft#1115, which adds its own data device, and storytold/filmcraft#634, which moves to XWayland) both broke text copy and paste in the same test.

Thanks for doing this.

Orillian pushed a commit to Orillian/rawmakase that referenced this pull request Oct 19, 2026
The winit fork receives drag and drop on Wayland (rust-windowing/winit#4729),
so the window no longer turns drops off there and the setup view offers
dragging a folder on every desktop.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bmh129 added a commit to bmh129/gridcraft that referenced this pull request Oct 25, 2026
winit 0.30.13 reports dropped files only on X11, so on a Wayland session a
workbook dragged from Files showed a "no" cursor. Rather than running through
XWayland, pin winit to rust-windowing/winit#4729 (the 0.30 backport of
Wayland file drops, which also moves the clipboard onto winit's own data
device).

egui's clipboard would otherwise bind a second data device through
smithay-clipboard, and Hyprland serves the selection only to a client's first
one, so paste would break there. patches/egui-winit is the published
egui-winit 0.36.2 with emilk/egui#8657 ported (it was written against egui
main), so egui reads and writes text through winit's clipboard when the
display belongs to a winit event loop. Licence files from egui 0.36.2 are
included.

Both patches go away once winit and egui release these changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JxSbmEZZDKrHjsmEDM34SY
bmh129 added a commit to bmh129/cadcraft that referenced this pull request Oct 25, 2026
winit 0.30.13 reports dropped files only on X11, so on a Wayland session a
drawing dragged from Files showed a "no" cursor unless CADCRAFT_X11=1 ran
the app through XWayland. Pin winit to rust-windowing/winit#4729 (the 0.30
backport of Wayland file drops, which also moves the clipboard onto winit's
own data device).

egui's clipboard would otherwise bind a second data device through
smithay-clipboard, and Hyprland serves the selection only to a client's first
one, so paste would break there. patches/egui-winit is the published
egui-winit 0.36.2 with emilk/egui#8657 ported, so egui reads and writes text
through winit's clipboard when the display belongs to a winit event loop.
Licence files from egui 0.36.2 are included.

Both patches go away once winit and egui release these changes. Ported from
GridCraft (storytold/gridcraft#2222).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
benandez added a commit to UCSLabs/mailcraft that referenced this pull request Oct 27, 2026
* #523: files dropped on the window are attached on Wayland too

Notes the winit fork's second patch (rust-windowing/winit#4729) beside the pin; the rev is bumped once the fork is pushed.

Human-reviewed, AI-assisted, nobody's mailbox harmed.

* #523: winit from the fork with Wayland file drops

Human-reviewed, AI-assisted, nobody's mailbox harmed.
richerfu pushed a commit to richerfu/egui that referenced this pull request Nov 2, 2026
…board when available

Port of emilk#8657 (draft) to 0.36.2, the companion of W15 (rust-windowing/winit#4729): winit now binds a wl_data_device per seat for file drops, and a second device from smithay-clipboard loses the selection on compositors that serve only the first device per client (Hyprland). With winit's clipboard available, smithay-clipboard is not started. Only the clipboard.rs change is taken; the PR's temporary [patch] of egui's own winit is not.

On 0.37, `Clipboard::new` stays `unsafe`. While winit's clipboard is in use, the
PRIMARY selection goes through arboard: W15 offers only the regular selection.
richerfu pushed a commit to richerfu/egui that referenced this pull request Nov 2, 2026
…board when available

Port of emilk#8657 (draft) to 0.36.2, the companion of W15 (rust-windowing/winit#4729): winit now binds a wl_data_device per seat for file drops, and a second device from smithay-clipboard loses the selection on compositors that serve only the first device per client (Hyprland). With winit's clipboard available, smithay-clipboard is not started. Only the clipboard.rs change is taken; the PR's temporary [patch] of egui's own winit is not.
bmh129 added a commit to bmh129/gridcraft that referenced this pull request Nov 3, 2026
winit 0.30.13 reported dropped files only on X11. The egui 0.37 migration
(storytold#2543) pins storytold/winit, whose patch W15 reports file drops through
a per-seat Wayland data device (rust-windowing/winit#4729), so files
dragged from the file manager open on native Wayland too. The XWayland
default is no longer needed.

It also costs a startup crash: winit's X11 backend loads
libxkbcommon-x11, which the Linux packages don't depend on. Where it's
missing (a Fedora toolbox, minimal installs), GridCraft panics before the
window opens: "Library libxkbcommon-x11.so could not be loaded."

Checked on GNOME (Wayland, Fedora 44) with a build of main plus other
proposed changes, run with GRIDCRAFT_WAYLAND=1 (the path this revert
makes the default): an .xlsx and a .csv dragged from Files each open as a
workbook, and the app starts without libxkbcommon-x11 installed.

This reverts commit 6f0e43c.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Rvu8dWh26U2fsLQMSBQfH8
ludovic111 pushed a commit to TheApple05/horizon that referenced this pull request Nov 9, 2026
The game workspace pinned winit to an unreleased backport in a personal
fork (crmne/winit) for native Wayland file drops. Every player build would
then depend on a repository outside winit's own, which the project doesn't
take. The drop import itself works wherever winit already delivers
DroppedFile (Windows, macOS, X11, XWayland); native Wayland follows once a
winit 0.30 release carries rust-windowing/winit#4729.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FredApps pushed a commit to storytold/gridcraft that referenced this pull request Nov 18, 2026
* Linux: run on native Wayland again by default (revert #165)
  
  winit 0.30.13 reported dropped files only on X11. The egui 0.37 migration
  (#2543) pins storytold/winit, whose patch W15 reports file drops through
  a per-seat Wayland data device (rust-windowing/winit#4729), so files
  dragged from the file manager open on native Wayland too. The XWayland
  default is no longer needed.
  
  It also costs a startup crash: winit's X11 backend loads
  libxkbcommon-x11, which the Linux packages don't depend on. Where it's
  missing (a Fedora toolbox, minimal installs), GridCraft panics before the
  window opens: "Library libxkbcommon-x11.so could not be loaded."
  
  Checked on GNOME (Wayland, Fedora 44) with a build of main plus other
  proposed changes, run with GRIDCRAFT_WAYLAND=1 (the path this revert
  makes the default): an .xlsx and a .csv dragged from Files each open as a
  workbook, and the app starts without libxkbcommon-x11 installed.
  
  This reverts commit 6f0e43c.
  
  Claude-Session: https://claude.ai/code/session_01Rvu8dWh26U2fsLQMSBQfH8
FairyHmm added a commit to FairyHmm/winit that referenced this pull request Nov 18, 2026
Bind a wl_data_device per seat and accept text/uri-list drops, emitting
HoveredFile/DroppedFile. Add start_drag_files() to begin an outgoing drag
with an optional preview image, advertised as Copy.

Backport of the approach in emilk/egui#8805 and rust-windowing#4729
for the 0.30 line.
Drew-Chase added a commit to Drew-Chase/lodestone-minecraft-launcher that referenced this pull request Nov 29, 2026
winit 0.30 reports no file drops on Wayland, so files dragged in from a
file manager never reach the Files tab or the Import dialog.

Apply the source changes of rust-windowing/winit#4729 (commits a4d60d8
and 7a962fd on v0.30.x) to the v0.30.13 tree. A drag offering
text/uri-list is accepted with the copy action, and the window then gets
HoveredFile, HoveredFileCancelled and DroppedFile. The PR's second commit
adds platform::wayland::Clipboard, which the next commit uses. The PR's
Cargo.toml change, which adds percent-encoding to the wayland feature, is
made by hand.

The PR was still open on 2026-11-28. Drop this copy once a winit 0.30.x
release includes it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants