Skip to content

Support the X11/Wayland PRIMARY selection - #8428

Open
hallyhaa wants to merge 5 commits into
emilk:mainfrom
hallyhaa:feature/primary-selection
Open

Support the X11/Wayland PRIMARY selection#8428
hallyhaa wants to merge 5 commits into
emilk:mainfrom
hallyhaa:feature/primary-selection

Conversation

@hallyhaa

Copy link
Copy Markdown
Contributor

Selecting text in a Label or a TextEdit now fills the PRIMARY selection, and middle-clicking a TextEdit pastes it. This is what all other X11 and Wayland applications do.

Testing: tests/egui_tests/tests/test_primary_selection.rs. Publishing from labels and text edits, no publishing of passwords, no re-claiming of an unchanged selection, nothing at all on non-PRIMARY platforms, pasting at the click position rather than at the cursor, and no paste from a click outside the widget.

@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown

Preview available at https://egui-pr-preview.github.io/pr/8428-featureprimary-selection
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

can be pasted into other applications with the middle mouse button

This relates to issue emilk#5852, but doesn't solve the paste-INTO-egui part.

Claiming PRIMARY makes this process its owner, so it is published only
when the selection has actually changed and no pointer button is held.
…dit` on X11/Wayland now inserts the PRIMARY selection at the click point.
@hallyhaa
hallyhaa force-pushed the feature/primary-selection branch from f4f29b7 to 5531b8d Compare August 18, 2026 07:21
Comment thread crates/egui/src/data/output.rs Outdated
/// other application on those platforms does.
///
/// Integrations on platforms without a PRIMARY selection should ignore this.
CopyTextToPrimary(String),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should generalize this to TextSelectionChanged, or even remove it and just have eframe ask egui "What is the current text selection?" and monitor it for change (we should have a egui_ctx.text_selection() if we don't already)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generalize this: yes, absolutely. But I don't think we should poll. We would then have to build a string every frame a selection exists (for label selections), instead of once when it settles. And "don't re-claim PRIMARY mid-drag" would have to be re-derived by every integration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some changes. Now use Options::report_text_selection (default to on on linux). The cost that the platform check was really guarding is still guarded (only assemble the selected text when someone is listening). Now awaiting your opinion.

…opy_text_to_primary` goes away with the old name. Widgets that

manage their own selection use `ctx.send_cmd` like they do for the other
commands.
The command no longer says anything about PRIMARY, so a platform check was the wrong knob. An option instead, defaulting to on where PRIMARY exists. Label selections span widgets and are assembled during the pass, so egui only builds the string when someone is listening.
@hallyhaa
hallyhaa requested a review from emilk August 18, 2026 13:44
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.

Add support for copying and pasting to the X11/Wayland PRIMARY clipboard

2 participants