Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X11 shell does not support clipboards. #937

Closed
luleyleo opened this issue May 15, 2020 · 3 comments · Fixed by #1851
Closed

X11 shell does not support clipboards. #937

luleyleo opened this issue May 15, 2020 · 3 comments · Fixed by #1851
Labels
help wanted has no one working on it yet missing a feature is missing on a specific platform shell/x11 concerns the X11 backend

Comments

@luleyleo
Copy link
Collaborator

No description provided.

@luleyleo luleyleo added help wanted has no one working on it yet shell/x11 concerns the X11 backend missing a feature is missing on a specific platform labels May 15, 2020
@psychon
Copy link
Contributor

psychon commented Jun 19, 2020

The relevant standard here is ICCCM. I recently-ish had the joy of implementing support for this. Since this X11, of course you need to create windows. Read the sections of ICCCM about selections.

The general process (for getting the selection) is that you send a ConvertSelection request and some time later receive a SelectionNotify event. Large data transfers then additionally involve some dance with window properties. This is called INCR and described in ICCCM.

For setting a selection, you create a window and make it the selection owner with SetSelectionOwner. Then you have to react to SelectionRequest events. SelectionClear tells you when something else became the selection owner.

The relevant selections are CLIPBOARD. Perhaps you also want to handle the PRIMARY selection. This is the currently selected text. Most (?) programs support pasting this via the middle mouse button.

Edit: And of course ICCCM makes things more complicated. You are not supposed to just call SetSelectionOwner, but there is a procedure to follow.

@maan2003 maan2003 mentioned this issue May 1, 2021
@psychon
Copy link
Contributor

psychon commented May 22, 2021

I took another look at the API and... I really would prefer a callback-based clipboard API in druid. That would be easier to implement.

The GTK backend uses gtk_clipboard_wait_for_contents() which is documented as: https://developer.gnome.org/gtk3/stable/gtk3-Clipboards.html#gtk-clipboard-wait-for-contents

This function waits for the data to be received using the main loop, so events, timeouts, etc, may be dispatched during the wait.

Something similar would be needed for the x11 backend for a synchronous API. And no idea what then should happen when "the other end" does not reply to a clipboard event. Perhaps one could just "collect" all X11 events and stuff them into a list for later processing, waiting only for clipboard events.

On the other hand, a synchronous API is likely way nicer for the API user, so... yeah, I'm not really sure. At least I'll remove this from my list of "things to try to implement in druid-x11 during vacation".

@psychon
Copy link
Contributor

psychon commented May 31, 2021

#1805 handles the "get clipboard contents"-part. I also implemented setting clipboard contents: https://github.com/linebender/druid/compare/master...psychon:x11-put-clipboard?expand=1

I want to wait for #1805 to "go through" before tackling setting the clipboard contents. So far I only tested this with something like the following (I also tested this with a shorter string):

fn main() {
    tracing_subscriber::fmt().init();
    let app = druid_shell::Application::new().unwrap();
    let mut contents = String::from("1234567890");
    while contents.len() < 17 * 1024 * 1024 {
        let copy = contents.clone();
        contents = contents + &copy;
    }
    app.clipboard().put_string(contents);
    app.run(None);
}

(A first version of my code forgot to update the "current position" in incremental transfers. Providing an "infinite paste" made gvim die with:)

(gvim:61438): GLib-ERROR **: 14:18:05.607: ../../../glib/gmem.c:177: failed to allocate 18446744071562100412 bytes
Vim: Caught deadly signal TRAP
Vim: preserving files...
Vim: Finished.

psychon added a commit to psychon/druid that referenced this issue Jul 4, 2021
Fixes: linebender#937
Signed-off-by: Uli Schlachter <psychon@znc.in>
maan2003 pushed a commit that referenced this issue Jul 8, 2021
* x11: Turn Clipboard into a singleton

This commit renames the current Clipboard to ClipboardState and adds a
new Clipboard(Rc<RefCell<ClipboardState>>). This is in preparation for
setting the clipboard contents where we need to keep the clipboard
contents in ClipboardState.

* Preparations for setting the clipboard

Signed-off-by: Uli Schlachter <psychon@znc.in>

* x11: Implement putting things into the clipboard

Fixes: #937
Signed-off-by: Uli Schlachter <psychon@znc.in>

* Add CHANGELOG.md entry

Signed-off-by: Uli Schlachter <psychon@znc.in>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted has no one working on it yet missing a feature is missing on a specific platform shell/x11 concerns the X11 backend
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants