You are not logged in.

#1 2024-01-15 19:14:09

Taroven
Member
Registered: 2013-11-06
Posts: 3

[Solved]wl-copy never exits when used via ssh (Sway clipboard sharing)

I run a two-computer setup. Both systems are running Sway and I would like to set up text-only clipboard sync between them.

So here's where I'm at: By storing a SWAYSOCK reference in /tmp I'm able to interact between the two computers with swaymsg. This has worked perfectly for dpms control using swaymsg over ssh for a while now. Storing WAYLAND_DISPLAY the same way, I'm able to interact with wl-copy and wl-paste over ssh. I'm checking the mimetypes for text/plain to only send text, and checking current clipboard contents before setting them to prevent infinite loops. The problem I'm running into comes with wl-copy over ssh.

The sending side is easy, just this:

#!/bin/bash
# run via wl-paste -w /path/to/clipboard-sync
mime=$(wl-paste --list-types)
valid="text/plain"

if [[ $mime =~ $valid ]]; then
	wl-paste | ssh 10.0.0.5 wl-copy-remote
fi

Contents of wl-copy-remote:

#!/bin/bash

display=$(< /tmp/wayland_display)
old=$(WAYLAND_DISPLAY=$display wl-paste)
new=$(cat -)

if [ "$old" == "$new" ]; then
	exit 1
else
	echo $new | WAYLAND_DISPLAY=$display wl-copy
fi

Locally on either system (or via ssh shell), wl-copy-remote does its thing and just works. When called via

wl-paste | ssh 10.0.0.5 wl-copy-remote

...it does set the clipboard contents properly but doesn't fork off and just hangs, causing future copies to fail.

Is there a way to do this gracefully? Like I could do it the opposite way and ssh into the opposite machine every few seconds to grab the output of wl-paste, but that seems like a horrific way of doing it.

Last edited by Taroven (2024-01-17 13:41:10)

Offline

#2 2024-01-17 13:40:52

Taroven
Member
Registered: 2013-11-06
Posts: 3

Re: [Solved]wl-copy never exits when used via ssh (Sway clipboard sharing)

Didn't find a fix for wl-copy hanging over ssh, but I've worked around the problem by sending the clipboard contents to /tmp on the opposite computer with scp and using inotify to watch the file for changes and trigger wl-copy locally.

Offline

#3 2024-05-26 12:02:47

amzd
Member
Registered: 2024-05-26
Posts: 1

Re: [Solved]wl-copy never exits when used via ssh (Sway clipboard sharing)

Sorry for reviving a very old thread but this is the first result on my search tool.

The issue is that stderr is not closed before forking. You can fix this by doing a `2>/dev/null` redirection.

echo "$new" | wl-copy 2>/dev/null

source: https://github.com/bugaevc/wl-clipboard/pull/154

Offline

Board footer

Powered by FluxBB