From 7e799503739ded5103ec824d9990c91631e2e929 Mon Sep 17 00:00:00 2001 From: Nuno Sa Date: Wed, 7 Jun 2023 21:13:11 +0200 Subject: [PATCH] scripts: helpers.sh: use primary clipboard on wayland with mouse Follow the same logic as in X and use the primary clipboard for Wayland sessions when mouse support is on. Note a new parameter (@yank_wayland_mouse), which is off by default, was introduced so that the old behavior is maintained. That means that users need to set the following in their tmux.conf: `set -g @yank_wayland_mouse 'true'` to enable the above behavior. Signed-off-by: Nuno Sa --- scripts/helpers.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/helpers.sh b/scripts/helpers.sh index 66beeec..896c2a8 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -40,6 +40,9 @@ custom_copy_command_option="@custom_copy_command" override_copy_command_default="" override_copy_command_option="@override_copy_command" +yank_wayland_mouse_default="false" +yank_wayland_mouse_option="@yank_wayland_mouse" + # helper functions get_tmux_option() { local option="$1" @@ -104,6 +107,10 @@ custom_copy_command() { override_copy_command() { get_tmux_option "$override_copy_command_option" "$override_copy_command_default" } + +yank_wayland_mouse() { + get_tmux_option "$yank_wayland_mouse_option" "$yank_wayland_mouse_default" +} # Ensures a message is displayed for 5 seconds in tmux prompt. # Does not override the 'display-time' tmux option. display_message() { @@ -149,7 +156,11 @@ clipboard_copy_command() { elif command_exists "clip.exe"; then # WSL clipboard command echo "cat | clip.exe" elif command_exists "wl-copy"; then # wl-clipboard: Wayland clipboard utilities - echo "wl-copy" + if [[ $mouse == "true" && $(yank_wayland_mouse) == "true" ]]; then + echo "wl-copy --$(yank_selection_mouse)" + else + echo "wl-copy" + fi elif command_exists "xsel"; then local xsel_selection if [[ $mouse == "true" ]]; then