Skip to content

egui-winit: use winit's Wayland clipboard instead of smithay-clipboard when available - #8657

Draft
crmne wants to merge 2 commits into
emilk:mainfrom
crmne:egui-winit-wayland-clipboard
Draft

crmne wants to merge 2 commits into
emilk:mainfrom
crmne:egui-winit-wayland-clipboard

Conversation

@crmne

@crmne crmne commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Depends on rust-windowing/winit#4729, which is not in a winit release yet, so this is a draft. The second commit points winit at that branch so CI can build; it must be dropped before merging (cargo-deny rejects the git source).

winit#4729 adds Wayland file drops to winit 0.30 (the winit side of #1563), which means winit binds a wl_data_device per seat. smithay-clipboard then binds a second device on the same connection, and Hyprland sends the selection only to a client's first data device (dataDeviceForClient), so paste fails in every text field. To avoid that, the winit PR also offers text copy and paste on its own device as winit::platform::wayland::Clipboard.

With this change, egui_winit::Clipboard::new asks winit for the clipboard of the event loop behind the Wayland display handle (Clipboard::for_display). If there is one, text goes through it and smithay-clipboard is never started. Otherwise nothing changes. arboard still handles images, and an empty or non-text Wayland clipboard falls through to arboard as the smithay path does.

Tested in an egui app on headless Hyprland 0.56.2 and mutter 50.5: paste in, copy out, pasting our own copy, and paste after a file drop all work. Without this change, the same Hyprland setup with winit#4729 fails to paste. cargo clippy (all features, debug and release), cargo test -p egui-winit, and the egui-winit/eframe feature checks from scripts/check.sh pass on 1.95.

  • I have followed the instructions in the PR template

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Preview available at https://egui-pr-preview.github.io/pr/8657-egui-winit-wayland-clipboard
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

View snapshot changes at kitdiff

crmne added 2 commits October 14, 2026 23:00
Once winit binds a data device per seat (for file drops), smithay-clipboard
binds a second one on the same connection. Hyprland sends the selection only to
a client's first data device, so smithay-clipboard never sees it and paste
fails in every text field.

When the display handle belongs to a winit event loop, read and write text
through winit::platform::wayland::Clipboard, which uses winit's own data
device, and don't start smithay-clipboard. Other displays keep
smithay-clipboard, and arboard still handles images.
Remove before merging, once a winit 0.30 release has
winit::platform::wayland::Clipboard.
@crmne
crmne force-pushed the egui-winit-wayland-clipboard branch from ee84f32 to 14135f0 Compare October 14, 2026 21:18
@crmne

crmne commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main. Clipboard::new is unsafe there now; the winit clipboard path sits at its top, unchanged. The TEMPORARY commit points at the current head of rust-windowing/winit#4729. cargo-deny rejects that git source as expected for this draft, and the commit goes once a winit 0.30 release has the clipboard.

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]>
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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant