bugaevc / wl-clipboard

Command-line copy/paste utilities for Wayland
GNU General Public License v3.0
1.62k stars 59 forks source link

wl-copy doesn't close #128

Closed tyalie closed 2 years ago

tyalie commented 2 years ago

Essentially the problem is: wl-copy doesn't close after finishing it's job. It took me a while to identify it as a problem, but independent on whether it is forked or run in foreground, the program will hang after copying the input. Interestingly enough it will close after a new wl-copy instance was run (which in turn doesn't close until a replacement occurs, ...)

It becomes annoying when the terminal emulator one uses waits for all forked processes to close after the shell has been stopped - which in turn doesn't happen here or after copying something in neovim (which uses wl-copy) the wl-copy command will still run in the background even though neovim has been terminated.

Another observation is, that wl-copy will respond to a normal SIGTERM and terminate accordingly. So it isn't really frozen here.

Examples

$ echo "hi" | wl-copy
$ ps aux | grep "wl-copy"  # wl-copy is still listed
$ killall wl-copy  # wl-copy doesn't exist anymore

$ echo "hi" | wl-copy
$ ps aux | grep "wl-copy" 
$ echo "test" | wl-copy
$ ps aux | grep "wl-copy"  # there is still one wl-copy running, but it has a new id (old one replaced)

$ echo "hi" | wl-copy --foreground  # will never finish except with CTRL-C

$ mkfifo pipe
$ wl-copy < pipe  # wl-copy hangs until pipe has got data
# in another terminal
$ echo "Hi" > pipe
# wl-copy above will "close", but still run in background

System config

$ wl-copy --version
wl-clipboard 2.0.0
Copyright (C) 2019 Sergey Bugaev
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ uname -a
LSB Version:    core-11.1.0ubuntu3-noarch:printing-11.1.0ubuntu3-noarch:security-11.1.0ubuntu3-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 21.10
Release:    21.10
Codename:   impish

$ zsh --version  # I'm using zsh here
zsh 5.8 (x86_64-ubuntu-linux-gnu)
YaLTeR commented 2 years ago

This is the normal behavior. There's no "global clipboard" on Wayland or X11; applications provide clipboard contents on demand. This means that wl-copy must run in the background and serve the clipboard contents until something else replaces them.

tyalie commented 2 years ago

ah oke that makes sense. so I might need to find another way to do this