Closed vain closed 6 days ago
Thanks for adding code to this issue, it helps with understanding your idea. This approach looks good to me, I would reccomend turning it into a pull request. Code wise, I would add some sort of error-handling if the child didn't exit with 0, even something such as a print to the console to understand why it didn't use "x" paster. However, this code should likely be reviewed in the pull request, than here.
Closing, this has been fixed in the meantime.
The code currently does this:
The intention here is probably to try to execute
wl-paste
and, if that doesn't work, fall back toxclip
.I don't think that's the correct way to do this.
popen()
will only returnNULL
iffork()
orpipe()
fails, but that doesn't tell you anything about theexec()
call, nor if the child exited cleanly. The latter is the crucial information. For example, if bothwl-paste
andxclip
are installed and you run bemenu on X11,wl-paste
will properlyexec()
but eventually exit with an exit code of1
because it can't talk to a Wayland compositor.What we would need to to is: Open the pipe, try to read from it, and only use the result if the child exited with
0
. If it didn't, try another paste program.I'd suggest doing something like this:
Note: I'm pretty tired and wrote this piece of code rather quickly without much testing. If you agree that this is the way to go, then I'd be happy to turn this into a proper pull request. 🙂