astrand / xclip

Command line interface to the X11 clipboard
GNU General Public License v2.0
1.04k stars 75 forks source link

Does not work with wayland #62

Open ankostis opened 5 years ago

ankostis commented 5 years ago

Latest Debian uses wayland by default, and all programs depending on xclip broke!.

I understand that this is an X utility, but still, if it is trivial to make it work out-of-the-box[*], it would be great.

[*] https://www.geekyhub.in/post/use-xclip-in-gnome-wayland/

hackerb9 commented 4 years ago

What is the failure mode when xclip is used under Wayland? Maybe xclip could detect that the chosen selection (Primary) isn't available and fallback to Clipboard.

skierpage commented 3 years ago

What is the failure mode when xclip is used under Wayland? Maybe xclip could detect that the chosen selection (Primary) isn't available and fallback to Clipboard.

Run under kwin_wayland from the Fedora 34 KDE spin (which by default runs an XWayland server to support X11 programs), if a Wayland program has the primary selection and no X11 programs have a primary selection then xclip version 0.13 immediately crashes with segmentation fault.

I fiddled with gdb. It's crashing in doOut() in the "no fallback available, exit with failure" leg at line 748

    free(sel_buf);

It seems to go through the loop calling xcout() a few times until it gets XCLIB_XCOUT_BAD_TARGET) and then calls free, but

p sel_buf
$12 = (unsigned char *) 0x38000000380 <error: Cannot access memory at address 0x38000000380>

so crash. But this is with the optimized binary; I don't know how sel_buf gets set.

Hope this helps. I originally filed downstream bug https://bugzilla.redhat.com/show_bug.cgi?id=1961031 before finding this issue. Thanks for this utility!

I installed the wl-clipboard package for the equivalent commands wl-copy and wl-paste under Wayland; it's going to be hard to retrain my fingers 😉.

pabloab commented 2 years ago

Maybe some ideas could be borrowed from wl-clipboard.

hackerb9 commented 2 years ago

As much grief as Wayland has caused for me, strangely it has not broken xclip on my computer. I am using Xwayland on Debian GNU/Linux 11 (the current stable release) with gnome.

hackerb9 commented 2 years ago

Skierpage wrote:

I originally filed downstream bug https://bugzilla.redhat.com/show_bug.cgi?id=1961031 before finding this issue.

Did you try the patched version "xclip-0.13-14.git11cba61.fc34" suggested in that bug? Did it help?

skierpage commented 2 years ago

Did you try the patched version "xclip-0.13-14.git11cba61.fc34" suggested in that bug? Did it help?

I just tried xclip-0.13-15.git11cba61.fc35.x86_64. I couldn't get it to crash.

I started an X11 program, chromium-browser running under Xwayland, and made some selections; xclip shows the X11 clipboard contents. Unsurprisingly (?) if I set the selection in a Wayland app (I used Firefox with MOZ_ENABLE_WAYLAND=1), that isn't reflected in xclip -o.

After exiting my one X11 program (but kwin_wayland is still running), xclip -o outputs "xclip: Error: There is no owner for the CLIPBOARD/ PRIMARY selection". But I can run echo 'NEW PRIMARY SELECTION' > xclip -selection primary without error.

It seems xclip is probably working about as well as can be expected under kwin Wayland.

hackerb9 commented 2 years ago

I started an X11 program, chromium-browser running under Xwayland, and made some selections; xclip shows the X11 clipboard contents. Unsurprisingly (?) if I set the selection in a Wayland app (I used Firefox with MOZ_ENABLE_WAYLAND=1), that isn't reflected in xclip -o.

After exiting my one X11 program (but kwin_wayland is still running), xclip -o outputs "xclip: Error: There is no owner for the CLIPBOARD/ PRIMARY selection".

And it does work when you do xclip -selection clipboard -o, right?

If so, that would make me think that xclip, when no specific selection is requested, should now default to to using the clipboard instead of the primary selection. @astrand, what do you think? I know this breaks with past behavior, but it seems reasonable.

astrand commented 2 years ago

From one perspective, why should we change the behaviour and break compatibility for all X11 users, just because some other competing project wants to do things differently? xclip was written to support X11, not other systems. If other systems wants to provide backwards compatibility they can of course do that, but if this compatibility is bad or incomplete, should really xclip be changed? I think that would be wrong; at least as long as most xclip users are using X11 rather than Wayland.

Having that said: Perhaps we can consider change the default so that xclip first tries primary, and if that fails, then uses clipboard. What do you think of this?

hackerb9 commented 2 years ago

Sounds like a good idea for output.

Should xclip on input default to writing to both the Primary selection and the Clipboard?

shmerl commented 2 years ago

Apparently, Wayland won't sync clipboards unless one of the client windows is focused.

So for this to work, you need to run the terminal itself in XWayland.

So this works for KDE / konsole for example:

QT_QPA_PLATFORM=xcb konsole

^ Starts konsole in XWayland more.

In the opened terminal:

echo foo | xclip -selection clipboard
rocketraman commented 2 months ago

Just as another datapoint, copying from a Wayland program (such as Chrome configured with ozone platform=wayland) I get this when used from a Wayland shell:

$ xclip -o -t TARGETS
xclip: Error: There is no owner for the PRIMARY selection

$ xclip -selection clipboard -o -t TARGETS
xclip: Error: There is no owner for the CLIPBOARD selection

qdbus org.kde.KWin /KWin org.kde.KWin.showDebugConsole shows the "Clipboard" content is correct. The source is shown as wl_data_source@x of <process>.

It'd be nice if xclip handled this somehow, but of course I understand if it did not. wl-clipboard works well for this use case.

BPowell76 commented 1 month ago

Just as another datapoint, copying from a Wayland program (such as Chrome configured with ozone platform=wayland) I get this when used from a Wayland shell:

$ xclip -o -t TARGETS
xclip: Error: There is no owner for the PRIMARY selection

$ xclip -selection clipboard -o -t TARGETS
xclip: Error: There is no owner for the CLIPBOARD selection

qdbus org.kde.KWin /KWin org.kde.KWin.showDebugConsole shows the "Clipboard" content is correct. The source is shown as wl_data_source@x of <process>.

It'd be nice if xclip handled this somehow, but of course I understand if it did not. wl-clipboard works well for this use case.

Thank you for sharing. This resolved my issue with copying from neovim to other applications/windows using Wayland. It's part of the Ubuntu apt repo so installing was about as simple as it gets.