Support the X11/Wayland PRIMARY selection - #8428
Conversation
|
Preview available at https://egui-pr-preview.github.io/pr/8428-featureprimary-selection 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.
f4f29b7 to
5531b8d
Compare
| /// other application on those platforms does. | ||
| /// | ||
| /// Integrations on platforms without a PRIMARY selection should ignore this. | ||
| CopyTextToPrimary(String), |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Selecting text in a
Labelor aTextEditnow fills the PRIMARY selection, and middle-clicking aTextEditpastes 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.